我遇到了一个奇怪的问题,即我公司内部应用程序的用户没有运行 sqlite 查询。它崩溃并出现以下错误:
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
并且intCol4
是为我要安装的新版本添加到此表的新列。但是,如果我删除intCol3
它有一个错误,intCol4
如果我也删除它,那么它的primaryKey有问题..
最初我认为这与他是唯一一个在他的手机上安装了 android 9 的用户有关,但是当在不同的 android 9 设备上尝试它时它工作正常。这似乎是他第二次将他的谷歌帐户链接到它打破此查询的设备。
我尝试全新安装该应用程序并清除所有应用程序数据以及缓存到他手机的所有内容,但它仍然会引发此异常。
我还尝试添加代码以尝试在每次他尝试登录时创建“缺失”列,但这并没有什么不同。
有没有人遇到过类似的事情或能够指出我在哪里看的正确方向?这是我的onCreate
和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)"
);
}