SQLite中的条件查询 [英] Conditional query in SQLite

查看:158
本文介绍了SQLite中的条件查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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 from tosync where tbname = "%s" and tbid = %d 
end
else
begin
  insert into tosync(tbname, tbid, act) values("%s", %d, %d);
end

分别是

 [TbName, tbid, act, act, TbName, tbid, TbName, tbid, act]

请注意,本主题与UPSERT和sqlite中可用的类似问题无关.

Please note, that this topic is not about UPSERT and similar issues available in sqlite.

推荐答案

您不能在SQLite中以这种方式进行条件查询.

You can't do conditional queries in this way in SQLite.

但是,您可以执行INSERT ...不存在的操作...

You can however do INSERT ... WHERE NOT EXISTS ...

查看更多信息... http://www.sqlite.org/lang_insert. html

Check this out for more information... http://www.sqlite.org/lang_insert.html

这篇关于SQLite中的条件查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆