我正在尝试更新我的数据库以获得另一个名为Visible的列。我希望整个列都填充错误的值。当我运行代码时,它会进入更新功能并发出以下错误:
android.database.sqlite.SQLiteException: no such column: true: UPDATE Themes2 SET Visibility = true;
private static final String TABLE_THEMES_V2 = "Themes2";
public static final String KEY_VISIBLE = "Visibility";
if (oldVersion < 8) {
db.execSQL("ALTER TABLE " + TABLE_THEMES_V2 + " ADD COLUMN " + KEY_VISIBLE + " text");
db.execSQL("UPDATE " + TABLE_THEMES_V2 + " SET " + KEY_VISIBLE + " = true;");
db.setTransactionSuccessful();
}
有谁知道什么是错的?很久以前我用同样的功能在列中输入“1”...
答案 0 :(得分:1)
您的KEY_VISIBLE列具有Text数据类型,因此您应该使用以下语法对其进行更新,
db.execSQL("UPDATE " + TABLE_THEMES_V2 + " SET " + KEY_VISIBLE + " = 'true';");
您在字符串值中缺少'
单个反转标记。
您可以尝试的另一种方法是将KEY_VISIBLE列设置为整数类型
db.execSQL("ALTER TABLE " + TABLE_THEMES_V2 + " ADD COLUMN " + KEY_VISIBLE + " INTEGER");
db.execSQL("UPDATE " + TABLE_THEMES_V2 + " SET " + KEY_VISIBLE + " = 1;"); // for True
db.execSQL("UPDATE " + TABLE_THEMES_V2 + " SET " + KEY_VISIBLE + " = 0;"); // for False