我正在为我的数据库使用休闲模式来存储消息传递线程。
CREATE TABLE threads(
_id INTEGER PRIMARY KEY AUTOINCREMENT,
date_sent_or_received INTEGER,
read INTEGER,
count INTEGER,
body TEXT,
address TEXT,
error_code INTEGER);
每当我将值插入 SMS 表时,我都会激活休闲触发器。
CREATE TRIGGER update_thread_id AFTER INSERT ON sms
WHEN
0 <> (select count() from threads
where length(address)>=length(new.address)
and substr(address, length(address)-length(new.address)+1) like new.address)
BEGIN
UPDATE threads SET
address = new. address
where substr(address, length(address)-length(new.address)+1) like new.address;
UPDATE threads SET
date_sent_or_received=new.date_sent_or_received,
read = new.read,
body = new.body
where date_sent_or_received<=new.date_sent_or_received
and address like new.address;
UPDATE sms SET
thread_id= (select _id from threads
where address like new.address)
where _id = new._id;
UPDATE threads SET
count = (select count() from sms
where thread_id=(select _id from threads
where address like new.address))
where address like new.address;
END;
我遇到问题陈述,我试图仅在线程内容比新线程旧时更改线程内容。它是这样的。
UPDATE threads SET
date_sent_or_received=new.date_sent_or_received,
read = new.read,
body = new.body
where date_sent_or_received<=new.date_sent_or_received
and address like new.address;
但是,它不起作用。即使新插入的行的时间戳较大,表的内容也保持不变,此触发器根据新添加的行更新地址。
我将秒数存储在整数中。有什么想法我错了吗?