问题
I find the issue when my device is under 4.4.4 , i can't get it why the issue will happen like this. I try to find some solution Why does SQLite say that instr doesnt exist? , so i guess there was no INSTR
before when android device version is under 4.4.4
In my case i use the sql like this: //Sort date : Latest to Old date
public List<Contact> sortingDate() {
List<Contact> contactList = new ArrayList<>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_CONTACTS + " ORDER BY\n" +
" SUBSTR(Date, 1, 4) DESC,\n" +
" CASE WHEN INSTR(SUBSTR(Date, 6), '/') = 2\n" +
" THEN '0' || SUBSTR(Date, 6, 1)\n" +
" ELSE SUBSTR(Date, 6, 2) END DESC,\n" +
" CASE WHEN LENGTH(SUBSTR(SUBSTR(Date, 6), INSTR(SUBSTR(Date, 6), '/') + 1)) = 1\n" +
" THEN '0' || SUBSTR(SUBSTR(Date, 6), INSTR(SUBSTR(Date, 6), '/') + 1)\n" +
" ELSE SUBSTR(SUBSTR(Date, 6), INSTR(SUBSTR(Date, 6), '/') + 1) END DESC; ", null);
//looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Contact contact = new Contact();
contact.setID(Integer.parseInt(cursor.getString(0)));
contact.setDate(cursor.getString(1));
contact.setBeforeMorning(cursor.getString(2));
contact.setAfterMorning(cursor.getString(3));
contact.setBeforeNoon(cursor.getString(4));
contact.setAfterNoon(cursor.getString(5));
contact.setBeforeNight(cursor.getString(6));
contact.setAfterNight(cursor.getString(7));
System.out.println("The result is :" + cursor.getString(1));
//Adding contact to list
contactList.add(contact);
} while (cursor.moveToNext());
}
return contactList;
}
I use the sql because i want to ORDERBY
my date is yyyy/mm/dd
if my date is like 2017/2/5
Now i get the issue , i don't know how to change my code if i can't use INSTR
anymore.
I looking for some answer say can use LIKE '%Date%'
, obviously its not suitable for my case.
Any help would be appreciated. Thanks in advance.
来源:https://stackoverflow.com/questions/47790323/sqliteexception-no-such-function-instr-code-1-under-android-4-44