无法在SQLite3中创建TRIGGER

时间:2012-08-28 15:02:40

标签: sql sqlite triggers syntax-error

我在sqlite3中创建此触发器second_loop时遇到问题: 它是更多代码的一部分,但正是这一部分给出了错误。 当我在数据库上执行代码时,我得到以下结果:靠近“CREATE”:语法错误

我确信触发器内的部件运行良好,因为我已单独测试它,但是必须有其它类型的问题。

请注意,我在同一个SQL中有另一个触发器,它工作得很好!

请指教,谢谢

CREATE TRIGGER second_loop AFTER UPDATE OF stack_count ON global WHEN NEW.stack_count<>0

BEGIN
 CREATE TEMP TABLE last_row(id INTEGER PRIMARY KEY, unvisited INTEGER DEFAULT 1, predecessor INTEGER DEFAULT 0, discovery INTEGER DEFAULT 0, finish INTEGER DEFAULT 0);

 INSERT INTO last_row
        SELECT *
        FROM nodes
        WHERE id = (SELECT node_id
                   FROM stack
                   ORDER BY oid DESC LIMIT 1);

 UPDATE last_row SET unvisited =0, predecessor = (SELECT parent_id FROM global), discovery = (SELECT time FROM global);

 UPDATE global SET current_id = (SELECT node_id FROM stack WHERE ROWID = (SELECT MAX(ROWID) FROM stack));
 UPDATE global SET time = time + 1;

 DELETE FROM stack WHERE ROWID = (SELECT MAX(ROWID));

 INSERT INTO stack(node_id)
   SELECT DISTINCT edges.target_id
   FROM nodes, edges, global
   WHERE edges.source_id=global.current_id AND nodes.unvisited=1;

  -- update stack count to go to second_loop trigger
  UPDATE global SET stack_count = stack_count + 1;
 END;

1 个答案:

答案 0 :(得分:3)

根据CREATE TRIGGER statement,SQLite3的syntax diagram不支持嵌入式CREATE TEMP TABLE子语句。