SQLite syntax error on insert default value during trigger after

Viewed 708

The problem: SQLite yields "near DEFAULT: syntax error" when running this through sqlite3_exec. The insertion works fine outside the trigger, and other statements works inside the trigger, but somehow the DEFAULT VALUES won´t work inside the trigger. Why is this happening?

SQLite code:

CREATE TABLE Symbol (
  Label VARCHAR(127) PRIMARY KEY
);
CREATE TABLE Process (
  Name INTEGER PRIMARY KEY
);
CREATE TABLE Named_Process_Definition (
  Label VARCHAR(127),
  Name INTEGER,
  FOREIGN KEY (Label) REFERENCES Symbol (Label),
  FOREIGN KEY (Name) REFERENCES Process_Definition (Name)
);
CREATE TRIGGER pre_new_named_process BEFORE INSERT ON Named_Process_Definition
  BEGIN
    INSERT INTO Symbol (Label) VALUES (NEW.Label);
  END;
CREATE TRIGGER post_new_named_process AFTER INSERT ON Named_Process_Definition
  BEGIN
    INSERT INTO Process DEFAULT VALUES;
    UPDATE Named_Process_Definition SET Name=last_insert_rowid()  WHERE rowid=NEW.rowid;
  END;

The triggers are meant to simplify inserting Named_Process_Definitions by automatically generating internal "unnamed" resources such as Process.

1 Answers

sqlite docs state:

The "INSERT INTO table DEFAULT VALUES" form of the INSERT statement is not supported.

You can work around this by inserting a null, e.g.:

CREATE TRIGGER post_new_named_process AFTER INSERT ON Named_Process_Definition
  BEGIN
    INSERT INTO Process(rowid) VALUES(NULL);
  END;
Related