sqlite3的故事
来源:互联网 发布:淘宝的网络广告方式 编辑:程序博客网 时间:2024/05/29 13:41
主要还是在数据库内容同步的时候遇到的问题,服务器端也不标识变化发生,那客户端用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: //至于效率问题,我们需要找个同学测试下。。。。
NSString * update = [NSString stringWithFormat:@"SELECT * FROM LIST WHERE IDNUM = '%i'", [accessID integerValue]];sqlite3_stmt *stmt;int rc = sqlite3_prepare_v2(db, [update UTF8String], -1, &stmt, nil);if (rc == SQLITE_OK) { if (sqlite3_step(stmt) == SQLITE_ROW) { update = [NSString stringWithFormat:@"UPDATE LIST SET COUNT = ?, NAME = ?, DATE = ?, IDNUM = ? WHERE IDNUM = '%i'", [accessID integerValue]]; } else{ update = [NSString stringWithFormat:@"INSERT OR REPLACE INTO LIST (COUNT, NAME, DATE, IDNUM) VALUES (?, ?, ?, ?)"]; }}
先上下面的方案吧:)为了减少网络流量,请问我可以只拿房间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 from dd where state=4//本来测试没有看where,后来用了where发现不对了。这。。。。!
- sqlite3的故事
- sqlite3的sqlite3.connect(":memory:")
- sqlite3.3.6的移植
- sqlite3的基本使用
- SQLite3的数据类型
- SQLite3的C编程
- SQLite3的使用
- Sqlite3的应用
- SQLite3支持的数据类型
- Sqlite3支持的数据类型
- SQLite3的操作命令
- sqlite3支持的数据类型
- sqlite3的简单使用
- sqlite3的时间类型
- sqlite3的使用教学
- Sqlite3的学习笔记
- sqlite3 的使用
- SQLite3的操作命令
- 用C++制作一个简单的文字游戏,纯属C++入门,有兴趣的可以看看
- iPhone图标去高光
- 动态链接库(DLL)简单了解
- 游戏引擎 之 寻路&路径平滑处理
- ubuntu 12.04 编译android 时问题总结
- sqlite3的故事
- zen-cart文件加载流程图(修改补充)
- myeclipse项目编码方式彻底设置
- MFC中MessageBox输出变量值
- SqlDateTime 溢出
- 关于iPhone和iPad的图标的思考
- VMware虚拟机的上网问题
- DBUS基础知识
- 在Linux下使用Openal来播放声音类