UNIX timestamp comparison
I am using fallowing schema for my database to store messaging threads.
CREATE TABLE threads(_id INTEGER PRIMARY KEY AUTOINCREMENT,
date_sent_or_received INTEGER, read INTEGER, count INTEGER, body TEXT,
address TEXT, error_code INTEGER);
I have the fallowing trigger that gets activated whenever I insert values
into a SMS table.
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;
I am encountering problem statement where I am trying to change content of
thread only when it is older than the newer one. It goes like this.
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;
However, it doesn't works. Content of the table remains same even when
newly inserted row is larger in timestamp, this trigger updates the
address according to newly added row.
I am storing seconds in Integer. Any ideas where I am wrong ?
No comments:
Post a Comment