Friday, 13 September 2013

Helper class is not returning image name which is stored in SQLite databse

Helper class is not returning image name which is stored in SQLite databse

I am trying to retrieve image paths from SQLite database and display
corresponding images on the ImageView. The problem is, helper class is not
returning the image name, so that, I am unable to display the image in the
ImageView. Please see the following code for helper.class
public static final String GETSD = "select DISTINCT FileName from Photos
where
last_disp_TimeStamp in (select MIN(last_disp_TimeStamp) from Photos where
DisplayCount in (select MIN(DisplayCount) from Photos));";
public static final String UPDATE_DISP = "update Photos set DisplayCount =
Displaycount+1 where last_disp_TimeStamp in (select MIN(last_disp_TimeStamp)
from Photos where DisplayCount in (select MIN(DisplayCount) from Photos));";
public static final String UPDATE_TIMESTAMP = "update Photos set
last_disp_TimeStamp = CURRENT_TIMESTAMP where FileName in (select
FileName from
Photos where last_disp_TimeStamp in (select MIN(last_disp_TimeStamp) from
Photos
where DisplayCount in (select MIN(DisplayCount) from Photos)));";
public String getSDPath() {
// TODO Auto-generated method stub
Cursor c;
SQLiteDatabase myDB ;
String commonpath = "/storage/sdcard/DCIM/Camera/SAMPLE IMAGES/";
String result="";
String h = "";
try {
myDB=this.openDataBase();
c=myDB.rawQuery(GETSD,null);
myDB.execSQL(UPDATE_DISP);
myDB.execSQL(UPDATE_TIMESTAMP);
if (c != null ) {
if (c.moveToFirst()) {
do {
// put your code to get data from cursor
int img = c.getColumnIndex("FileName");
result = c.getString(img);
h=commonpath+result;
}while (c.moveToNext());
}
}
if(c != null)
{
myDB.close();
c.close();
}
}catch(SQLException sqle){
throw sqle;
}
return h;
}
The queries are working fine, when I test them on SQLite browser I don't
have any problem with queries. I have checked the database file in
/data/data/com.example.myappname/databases/ folder. I have the required
photos in /storage/sdcard/DCIM/Camera/SAMPLE IMAGES/.
The path this function is returning is, /storage/sdcard/DCIM/Camera/SAMPLE
IMAGES/. But the expected string from this function is, something like
/storage/sdcard/DCIM/Camera/SAMPLE IMAGES/xxx.png
The string "xxx.png" is stored in database and with the query GET_SD, I am
retrieving the name of the image.
I have checked many questions and tutorials on this, but didn't get
solution for this.Please suggest me some solution. Thanks in advance.

No comments:

Post a Comment