SQLite在创建触发的条件下有条件
我正在使用sqlite创建一个触发器,我想比较旧值是否与新值不同,因此我可以执行insert
这是我创建的触发器,但似乎MySQL语法没有在sqlite中工作。 等效是什么?
CREATE TRIGGER document_handler AFTER UPDATE ON document
FOR EACH ROW
BEGIN
IF NEW.type <> OLD.type THEN
INSERT INTO DocumentUpdates (id_document, attribute_changed, lastvalue, newvalue, modification_date)
VALUES (id, "type", OLD.type, NEW.type, NOW());
END IF;
IF NEW.title <> OLD.title THEN
INSERT INTO DocumentUpdates (id_document, attribute_changed, lastvalue, newvalue, modification_date)
VALUES (id, "title", OLD.title, NEW.title, NOW());
END IF;
IF NEW.path <> OLD.path THEN
INSERT INTO DocumentUpdates (id_document, attribute_changed, lastvalue, newvalue, modification_date)
VALUES (id, "path", OLD.path, NEW.path, NOW());
END IF;
END;
I'm creating a trigger using SQLite and I want to compare if the OLD value is different than the NEW value so I can execute an INSERT
This is the trigger I created but seems like the MySQL syntax does not work in SQLite.
What would be the equivalent?
CREATE TRIGGER document_handler AFTER UPDATE ON document
FOR EACH ROW
BEGIN
IF NEW.type <> OLD.type THEN
INSERT INTO DocumentUpdates (id_document, attribute_changed, lastvalue, newvalue, modification_date)
VALUES (id, "type", OLD.type, NEW.type, NOW());
END IF;
IF NEW.title <> OLD.title THEN
INSERT INTO DocumentUpdates (id_document, attribute_changed, lastvalue, newvalue, modification_date)
VALUES (id, "title", OLD.title, NEW.title, NOW());
END IF;
IF NEW.path <> OLD.path THEN
INSERT INTO DocumentUpdates (id_document, attribute_changed, lastvalue, newvalue, modification_date)
VALUES (id, "path", OLD.path, NEW.path, NOW());
END IF;
END;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在sqlite中,没有
如果
条件语句。在这种情况下,您可以使用简单
where
条款:我更改了所有
&lt;&gt;
使用不是
,它也可以比较null
值。另外,
now()
在sqlite中的等效词是current_timestamp
。请参阅简化的 demo
。
In SQLite there is no
IF
conditional statement.In this case you can use simple
WHERE
clauses:I changed all
<>
withIS NOT
which can compare alsoNULL
values.Also, the equivalent of
NOW()
in SQLite isCURRENT_TIMESTAMP
.See a simplified demo.