I have written the below query which is working fine on Api 29 and 30 but app is crashing on Api 28 only with the following log System.out: crash_report=Exception is: android.database.sqlite.SQLiteException: no such column: true (code 1 SQLITE_ERROR): , while compiling: update doctor set is_rogspFiled = true where doctor_contactid = 784829 Here is my query. What do I need to change?
query = " update " + TABLE_DOCTOR + " set " + Queryclass.DOCTOR_ROGSP_STATUS + " = " + isFiled + " where " + Queryclass.DOCTOR_CONTACTID + " = " + gspid ;
cursor = sd.getData(query);
if (cursor.moveToNext()) {
isFiled = true;
ContentValues contentValues = new ContentValues();
contentValues.put(Queryclass.DOCTOR_ROGSP_STATUS, isFiled);
sd.update(Queryclass.TABLE_DOCTOR, contentValues, query);
}
cursor.close();
sd.close();
The version of SQLite used in API 28 is 3.22.0 (check this thread), but the constants true
and false
were introduced as aliases of 1
and 0
respectively in SQLite in version 3.23.0.
In your statement you must change isFiled
which returns true
or false
to an integer 1
or 0
:
query = "update " + TABLE_DOCTOR + " set " +
Queryclass.DOCTOR_ROGSP_STATUS + " = " + (isFiled ? 1 : 0) +
" where " + Queryclass.DOCTOR_CONTACTID + " = " + gspid;
But, concatenating parameters to SQL statement is always a bad idea.
You should use the method update()
where you use ?
placeholders to pass the parameters.