Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite syntax error on insert default value during trigger after

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.

like image 266
Andreas Avatar asked Aug 06 '26 14:08

Andreas


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;
like image 116
laalto Avatar answered Aug 08 '26 03:08

laalto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!