2016-11-26 40 views
0

觸發器在表如下的句法:錯誤限定SQLite中

CREATE TABLE "active_mtrs" 
(
    "mtr_ID" INTEGER PRIMARY KEY NOT NULL, 
    "status" INTEGER, 
    "NIrSTime" DATETIME, 
    "NIrETime" DATETIME 
) 

我所限定的觸發器爲:

CREATE TRIGGER "main"."replace1" 
AFTER INSERT ON "active_mtrs" FOR EACH ROW 
BEGIN 
    DECLARE @NIrSTime DATETIME; 
    DECLARE @NIrETime DATETIME; 
    DECLARE @mtr_ID INTEGER DEFAULT 0; 

    SELECT @mtr_ID = mtr_ID FROM INSERTED; 

    SELECT @NIrSTime = NIrSTime,@NIrETime = NIrETime 
    FROM subscriber 
    WHERE mtr_ID = @mtr_ID; 

    UPDATE active_mtrs 
    SET NIrSTime = @NIrSTime, 
     NIrETime = @NIrETime 
    WHERE mtr_ID = @mtr_ID; 
END 

其中subscriber是在此數據庫中另一個表。

但我得到一個錯誤:

[ near "DECLARE": syntax error ]
Exception Name: NS_ERROR_FAILURE
Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)

什麼是我的問題嗎?

回答

0

你的問題是你正試圖在SQLite中使用不同的SQL方言。

您不能使用DECLARE;你必須直接查看數值:

CREATE TRIGGER main.replace1 
AFTER INSERT ON active_mtrs 
FOR EACH ROW 
BEGIN 
    UPDATE active_mtrs 
    SET (NIrSTime, NIrETime) = 
      (SELECT NIrSTime, NIrETime 
      FROM subscriber 
      WHERE mtr_ID = NEW.mtr_ID) 
    WHERE mtr_ID = NEW.mtr_ID; 
END; 
+0

謝謝,這是正確的 –