更新语法错误

时间:2015-08-10 11:02:20

标签: sqlite triggers

我怎么试着修改我的触发器语法,这个错误一直在起来,“ROWID”或“PERSONID”附近的错误。我只是想弄清楚出了什么问题。

/* PERSON */

CREATE TABLE PERSON(
    PERSONID INTEGER NOT NULL,
    USERNAME VARCHAR(128) NOT NULL,
    MODERATOR BOOLEAN NOT NULL DEFAULT FALSE,
    SCORE INTEGER NOT NULL DEFAULT 0,
    CREATEDATE DATETIME NOT NULL DEFAULT (DATETIME('now')),
    MODIFYDATE DATETIME,

    PRIMARY KEY (PERSONID)
);

CREATE TRIGGER trg_personupdate AFTER UPDATE ON PERSON
    FOR EACH ROW
    BEGIN
        UPDATE PERSON
            SET MODIFYDATE = DATETIME('NOW')
            WHERE ROWID = new.ROWID;
    END;

sqlite输出:

 13:51:28  [/* - 0 row(s), 0.026 secs]  Command processed. No rows were affected
 13:51:28  [CREATE - 0 row(s), 0.040 secs]  Command processed. No rows were affected
 13:51:28  [CREATE - 0 row(s), 0.000 secs]  [Error Code: 1]  [SQLITE_ERROR] SQL error or missing database (near "ROWID": syntax error)
 13:51:28  [END - 0 row(s), 0.000 secs]  [Error Code: 1]  [SQLITE_ERROR] SQL error or missing database (cannot commit - no transaction is active)
... 4 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.066/0.000 sec  [0 successful, 2 warnings, 2 errors]

我认为“WHERE PERSONID = NEW.PERSONID” - 也应该有效,但是错误只是更改为“PERSONID”附近的错误

1 个答案:

答案 0 :(得分:0)

使用sqlite而不是sqlite3初始化数据库。所以某些功能运行良好,而触发器没有。

使用 sqlite3 创建新数据库解决了这个问题。