I am trying to delete some rows from table based on some conditions in particular based on dates.
I have tables containing date in string type and other fielde, here is my table structure
private static final String DATABASE_CREATE_HISTORY = "CREATE TABLE " + TABLE_HISTORY + "(" + COLUMN_ID + " INTEGER PRIMARY KEY," + COLUMN_NAME + " TEXT," + COLUMN_LOC + " TEXT," + COLUMN_TYPE + " TEXT," + COLUMN_DATE + " TEXT" + ")";
Now I want to delete all the rows based on date and COLUMN_LOC
Here is what I am doing
int numDeleted = database.delete(DataBaseHelper.TABLE_HISTORY, "date" + " < '" + writeFormat.format(d) + "'" + " AND " + DataBaseHelper.COLUMN_LOC + " = " +location, null);
In above query Date is this format Sat Mar 21 00:00:00 GMT+01:00 2015 and COLUMN_LOC is string containing for example "Home", "Airport" etc
But application crashes on this delete action with error
android.database.sqlite.SQLiteException: no such column: Home (code 1): , while compiling: DELETE FROM history WHERE date < 'Sat Mar 21 00:00:00 GMT+01:00 2015' AND loc = Home
I do not undertands why as it contains Home fiels in row and without COLUMN_LOC paramter it works fine.
Aucun commentaire:
Enregistrer un commentaire