0

我正在为我的数据库使用休闲模式来存储消息传递线程。

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;

但是,它不起作用。即使新插入的行的时间戳较大,表的内容也保持不变,此触发器根据新添加的行更新地址。

我将秒数存储在整数中。有什么想法我错了吗?

4

1 回答 1

0

我不知道你的问题的确切解决方案。但是由于您的问题是关于查询的,并且如果您在 SQLite 中执行这些操作,请在 SQliteBrowser 或 SQLite 管理器中测试您的 SQL 语句。在那里,您可以了解数据库对您的语句的反应。

于 2013-09-14T06:42:09.633 回答