Reputation: 1045
I got this code launching a query on my database:
public List<Photo> getPhotos(Calendar from, Calendar to) {
// Check if the Connection to the DB is open
raiseConnectionExceptionIfNotConnected();
ArrayList<Photo> photos = new ArrayList<Photo>();
// Query the database
Cursor cur = db.rawQuery(
"SELECT " + Day_TABLE + "." + DAY_PHOTO +
" FROM " + Day_TABLE +
" WHERE " + Day_TABLE + "." + DAY_DATE + " BETWEEN =? AND =? " +
" AND " + Day_TABLE + "." + DAY_PHOTO + " IS NOT NULL " +
" ORDER BY " + Day_TABLE + "." + DAY_DATE + " DESC",
new String[] {date_format.format(from.getTime()),
date_format.format(to.getTime()) }
);
if (cur.moveToFirst()) {
do {
photos.add(new Photo(cur.getString(0)));
}
while (cur.moveToNext());
}
cur.close();
return photos;
}
But every time my activity calls it, I get this error:
06-30 17:09:46.488: E/AndroidRuntime(273): FATAL EXCEPTION: main 06-30 17:09:46.488: E/AndroidRuntime(273): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.github.groupENIGMA.journalEgocentrique/com.github.groupENIGMA.journalEgocentrique.GalleryActivity}: android.database.sqlite.SQLiteException: near "=": syntax error: , while compiling: SELECT day.photo FROM day WHERE ( day.date BETWEEN =? AND =? ) ( AND day.photo IS NOT NULL ) ORDER BY day.date DESC
I'm not getting what the issue could be. The query seems ok to me...
Upvotes: 2
Views: 95