我正在使用fullowing模式为我的数据库存储消息传递线程。
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;
然而,它不起作用。即使新插入的行在时间戳中较大,表的内容也保持不变,此触发器根据新添加的行更新地址。
我在Integer中存储秒数。 我错的任何想法?
答案 0 :(得分:0)
我不知道你问题的确切解决方案。但由于您的问题与查询有关,并且如果您在SQLite中执行这些操作,请在SQliteBrowser或SQLite管理器中测试您的SQL语句。在那里,您可以了解数据库如何对您的陈述作出反应。