2

我在 sqlite3 中创建此触发器 second_loop 时遇到问题:它是更多代码的一部分,但正是这部分给出了错误。当我在数据库上执行代码时,我得到以下信息:near "CREATE": syntax error

我确信触发器内部的部分工作得很好,因为我已经单独测试过了,但是这肯定有其他类型的问题。

请注意,我在同一个 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;
4

1 回答 1

3

根据语法图, SQLite3 的CREATE TRIGGER语句不支持嵌入式子语句。CREATE TEMP TABLE

于 2012-08-28T15:54:35.860 回答