Conditional Query In Sqlite
Way to do in sqlite what is typical in most DB? if exists(select 1 from tosync where tbname = '%s' and tbid = %d and (act = 1 and %d = 3 or act = 3 and %d = 1) begin delete f
Solution 1:
You can't do conditional queries in this way in SQLite.
You can however do INSERT ... WHERE NOT EXISTS ...
Check this out for more information... http://www.sqlite.org/lang_insert.html
Solution 2:
After a while solutuion was found for this particular situation.
I have to run both insert and delete queries in a row with same condition:
insert or replace into tosync (tbname,tbid,act)
select"%s" ,%d ,%d
where notexists(select1 from tosync
where tbname="%s"and tbid=%d and (act=1and %d=3or act=3and %d=1));
delete from tosync
where tbname="%s"and tbid=%d andexists(select1 from
tosync where tbname="%s"and tbid=%d and (act=1and %d=3or act=3and %d=1));
Post a Comment for "Conditional Query In Sqlite"