无法在sqlite3触发器中使用SET

时间:2018-10-22 13:39:49

标签: python sqlite

我正在尝试启动数据库(使用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'])

0 个答案:

没有答案