I'm having an odd issue of a user of my companies internal app not running an sqlite query. It crashes with the following error:
android.database.sqlite.SQLiteException: no such column: intCol3 (code 1 SQLITE_ERROR): , while compiling: SELECT primaryKey, intCol1, textCol1, intCol2, textCol2, textCol3, intCol3 FROM table WHERE intCol4='1' LIMIT 100
intCol3
and intCol4
are new columns added to this table for the new version I'm trying to install. However, if I remove intCol3
it has an error with intCol4
and if I remove that as well, it has an issue with the primaryKey..
Initially I thought this was related to him being the only user who has android 9 on his phone but when trying it on a different android 9 device it works fine. It seems to be the second he links his google account to the device it breaks this query.
I've tried freshly installing the app and clearing all app data and anything cached to his phone and it still throws this exception.
I've also tried adding to the code to try creating the "Missing" columns each time he tries to log in but it doesn't make a difference.
Has anyone came across anything similar or be able to point me in the correct direction as to where to look?
This is my onCreate
and onUpgrade
@Override
public void onCreate(SQLiteDatabase db) {
try {
createTables();
} catch (Exception e) {
Log.d("Error:","Failied to build tables:" + e);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.v("*! dbHelper upgrade", "Update contacts");
db.execSQL("DROP TABLE IF EXISTS contacts");
onCreate(db);
}
public void createTables() {
SQLiteDatabase db = this.getWritableDatabase();
Log.v("*! dbHelper create", "Create contacts");
db.execSQL(
"create table contacts " +
"(cnId integer primary key, cnName text, cnDate date)"
);
db.execSQL(
"create table parts " +
"(primaryKey integer primary key, intCol1 integer, textCol1 text, intCol2 integer, textCol2 text, textCol3 text, intCol3 integer, intCol4 integer)"
);
}