我在尝试升级数据库时遇到此错误。我正在使用SQLiteAssetHelper。
11-30 03:32:55.868:W / System.err(383):引起: android.database.sqlite.SQLiteException:near" author_id":语法 错误(代码1):,编译时:CREATE TRIGGER [update_increase_size]
这是触发器的脚本:
CREATE TRIGGER [update_increase_size]
AFTER INSERT
ON [quote]
FOR EACH ROW
BEGIN
UPDATE author SET size = size+1 WHERE author_id = new.author_id;
UPDATE genre SET size = size+1 WHERE genre_id = new.genre_id;
END;
有人能看到我的错误吗?
答案 0 :(得分:0)
我终于找到了解决问题的方法。似乎SQLiteAssetHelper在使用触发器更新脚本时遇到问题,因为触发器可以有超过1个分号。所以我所做的是在onUpgrade方法中使用execSQL手动调用脚本,如下所示:
private static final String TRIGGER_INCREASE_SIZE = "CREATE TRIGGER IF NOT EXISTS [update_increase_size] "
+ "AFTER INSERT "
+ "ON [quote] "
+ "FOR EACH ROW "
+ "BEGIN "
+ "UPDATE [author] SET size = size+1 WHERE [author_id] = new.[author_id]; "
+ "UPDATE [genre] SET size = size+1 WHERE [genre_id] = new.[genre_id]; "
+ "END;";
@Override
public void onUpgrade(SQLiteDatabase db, int oldVer, int newVer) {
// TODO Auto-generated method stub
db.execSQL(TRIGGER_INCREASE_SIZE);
super.onUpgrade(db, oldVer, newVer);
}
希望这清楚地表明将来偶然遇到类似问题的人。