我正在尝试启动数据库(使用sqlite3进行测试),但是似乎无法在触发器内执行SET
。我收到以下错误:OperationalError: near "SET": syntax error
。
触发器内部的插入有效,所以我很好奇我在做什么错了吗?
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute("""CREATE TABLE Programs (
id INTEGER PRIMARY KEY,
name VARCHAR(64) NOT NULL,
time_added INTEGER
);""")
c.execute("""CREATE TRIGGER program_time_added AFTER INSERT ON Programs
FOR EACH ROW
BEGIN
SET new.time_added = UNIX_TIMESTAMP(NOW());
END;""")
c.execute('INSERT INTO Programs (name) VALUES (?)', ['name'])