I've got small problem with RAISE function in my trigger. This is my SQLite code:
CREATE TRIGGER CheckingDate
BEFORE INSERT ON MyTable
FOR EACH ROW
WHEN NEW.Start_date > NEW.End_date
BEGIN
RAISE(ABORT, 'End_date must be in the future');
END;
Start_date
and end_date
are SMALLDATETIME
and Start_date
is the result of datetime('now')
.
I run it in my python 2.7 program with all other sql script by sqlite3.complete_statement()
and it gives Syntax Error near RAISE
. Can someone tell me why? I tried ABORT
, ROLLBACK
, instead of ABORT
or SELECT CASE
or WHEN THEN
in my trigger but it still gives error;
RAISE()
is a SQL function, you'll need to use it as part of a statement; TRIGGER
s only allow for UPDATE
, INSERT
, DELETE
or SELECT
statements; use it in a SELECT
:
CREATE TRIGGER CheckingDate
BEFORE INSERT ON MyTable
FOR EACH ROW
WHEN NEW.Start_date > NEW.End_date
BEGIN
SELECT RAISE(ABORT, 'End_date must be in the future');
END;
This triggers the error correctly:
sqlite> insert into mytable values ('2030-1-1 20:20:20', datetime('now'));
Error: End_date must be in the future