SQLite使用默认值添加列

时间:2014-02-08 19:38:31

标签: android android-sqlite

我在Android SQLite数据库中工作。我将它从版本1升级到版本2。 onUpgrade方法按预期调用。

我的代码:

sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD COLUMN " + Contracts.DateActivities.C_GROUP + " INTEGER DEFAULT 0;");

我一直收到同样的错误:

Caused by: android.database.sqlite.SQLiteException: near "group": syntax error (code 1): , while compiling: ALTER TABLE DateActivities ADD group INTEGER DEFAULT 0

我做错了什么?

我尝试过的其他变体:

sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD COLUMN " + Contracts.DateActivities.C_GROUP + " INTEGER DEFAULT 0;");
sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD COLUMN " + Contracts.DateActivities.C_GROUP + " int DEFAULT 0;");
sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD " + Contracts.DateActivities.C_GROUP + " INTEGER DEFAULT 0;");

1 个答案:

答案 0 :(得分:4)

我怀疑 Contracts.DateActivities.C_GROUP 是“GROUP”(或“群组”或“群组”或...大小写无关紧要),这是一个保留关键字表示SQLite ...并且不能用于列名