Android SQLite3:alter table在OnUpdate中不起作用

时间:2014-01-08 15:33:40

标签: android sqlite

我正在使用alter table entry add column logdate date的{​​{1}}电话在sqlite中进行SQLiteOpenHelper。 更改后,我可以看到我的表中有通过alter脚本创建的列(通过onUpdate)。

虽然我在选择要列出的列时会出现这个奇怪的错误sqlite3 /data/data/mypackage/databases/mydb.db(内部使用java.lang.IllegalArgumentException: column 'logdate' does not existCursorLoader

SimpleCursorAdapter实施如下:

SQLiteOpenHelper

我在SQLite3 alter table脚本上进行了后台搜索,here它表示如果使用public static void onCreate(SQLiteDatabase database) { Log.i("DB", "Creating table: " + TABLE_NAME); database.execSQL(CREATE_TABLE_SQL); } public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) { Log.i("DB", "updating database from v" + oldVersion + " to v" + newVersion); for (int upgradeTo = oldVersion + 1; upgradeTo <= newVersion; upgradeTo++) { Log.d("DB", "incremental database update from v" + (upgradeTo - 1) + " to v" + upgradeTo); switch (newVersion) { case 1: onCreate(database); break; case 2: alterTable(database, "add column " + COLUMN_DATE + " date default 0;"); break; } } } private static void alterTable(SQLiteDatabase database, String alterAdditions) { String sql = "alter table " + TABLE_NAME + " " + alterAdditions; Log.v("DB", "alter script: " + sql); database.execSQL(sql); } ,数据库将无法读取。这是我看到的错误还是我的代码有问题?

编辑#1:

Logcat(稍加修改)

ADD COLUMN

1 个答案:

答案 0 :(得分:0)

从终端

删除旧版本的数据库
adb shell
cd /data/data/com.example.applicationname/databases
rm *