ios sqlite框架FMDB 的简单应用
2016-01-05 18:10
239 查看
// 导入FMDB头文件 import “FMDB.h” // 创建属性数据库对象队列属性 @property (nonatomic,strong) FMDatabaseQueue *queue; + (void)initialie { // 1.获取沙盒中数据库的文件名 NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@”car.sqlite”]; // 创建数据库对象队列 _queue = [FMDatabaseQueuedatabaseQueueWithPath:path]; // 创建表 [_queueinDatabase:^(FMDatabase *db) { BOOL result = [dbexecuteUpdate:@"create table if not exists t_car (id primary key autoincerment not null, name text not null)"]; if (result) { NSLog(@"创建表成功!"); } else { NSLog(@"创建表失败!"); } }]; } // 增加数据 - (void)add { [_queueinDatabase:^(FMDatabase *db) { [db executeUpdate:@”insert into t_car (name) values (?)”,@”宝马”]; }]; } // 删除数据 - (void)del { [_queueinDatabase:^(FMDatabase *db) { [db executeUpdate:@”delete table t_car where name = ?”,@”宝马”]; }]; } // 修改数据 - (void)update { [_queueinDatabase:^(FMDatabase *db) { [db executeUpdate:@”update t_car set name = ? where name = ?”,@”奔驰”,@”宝马”]; }]; } // 查询数据 - (void)query { [_queueinDatabase:^(FMDatabase *db) { // 获得结果集 FMResultSet rs = [dbexecuteQuery:@”select from t_car where name = ?”,@”宝马”]; // 遍历结果集 while (rs.next) { NSString *carName = [rsstringForColumn:@"name"]; int cid = [rsintForColumn:@"id"]; NSLog(@"id:%d,name:%@", cid, carName); } }]; }
相关文章推荐
- Redis主从复制和主从切换
- Oracle表 序列 约束 视图 索引的操作
- mysql 中查看指定表的字段名 (可根据字段变量生成c#后台代码)
- MySQL高并发下的解决方案
- iOS持久化之sqlite(待总结)
- redis 安装
- SQL表连接查询(inner join、full join、left join、right join)
- oracle 递归查询的例子
- redis哨兵(sentinel)原理
- Python的MongoDB模块PyMongo操作方法集锦
- 使用mysqlbinlog server远程备份binlog的脚本
- mysqldump备份过程中都干了些什么
- 邮件系统服务器搭建记录(二)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- Redis 集群的合纵与连横
- MySql的事务操作与演示样例
- node.js sql 注入攻击防御方法 (sql Injection)
- 关于SqlServer修改数据库常用信息的方法
- 基于C#的MongoDB数据库开发应用(1)--MongoDB数据库的基础知识和使用
- MySqlConnection.get_IsPasswordExpired()异常未将对象引用设置到对象实例
- oracle查询指定月份数据