微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sqlite3的故事

主要还是在数据库内容同步的时候遇到的问题,服务器端也不标识变化发生,那客户端用sqilite3,本来就是要实现目的,udpate不成功,我就用insert。

自然想到去拿那个影响的record数目。


但看来大家多推荐replace,这个replace是不是要知道原来sql的primarykey的值啊,可我偷懒,没设置,全用了一个自增长的id,这下。。。


因为数据库建表时没有指定primary key,所以replace语句不正常.


option 1 would look like: //基本来说,目前的数据结构,表,应该可以做到用replace or insert。。。。。

Nsstring * update =[Nsstring stringWithFormat:@"INSERT OR REPLACE INTO LIST (COUNT,NAME,DATE,IDNUM) VALUES (?,?,?)"]; 

option 2 would look like: //至于效率问题,我们需要找个同学测试下。。。。

"SELECT * FROM LIST WHERE IDNUM = '%i'",accessID integerValue]]; sqlite3_stmt stmt; int rc  sqlite3_prepare_v2(db[ UTF8String],0)"> -1& nil);ifrc == sqlITE_OK){   sqlite3_step sqlITE_ROW     "UPDATE LIST SET COUNT = ?,NAME = ?,DATE = ?,IDNUM = ? WHERE IDNUM = '%i'"   }else    }
先上下面的方案吧:)

为了减少网络流量,请问我可以只拿房间GUID和状态两个字段么,呵呵。。。。



The MIN/MAX optimization===============

Queries of the following forms will be optimized to run in logarithmic time assuming appropriate indices exist:

  SELECT MIN(x) FROM table;
  SELECT MAX(x) FROM table;

In order for these optimizations to occur,they must appear in exactly the form shown above - changing only the name of the table and column. It is not permissible to add a WHERE clause or do any arithmetic on the result. The result set must contain a single column. The column in the MIN or MAX function must be an indexed column.

所以我们的错误就在

select max(dd) as x,min(dd) as y fromddwhere state=4//本来测试没有看where,后来用了where发现不对了。这。。。。!

原文地址:https://www.jb51.cc/sqlite/201991.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐