FMDB操作数据库
来源:互联网 发布:淘宝怎么套现信用卡 编辑:程序博客网 时间:2024/06/06 23:18
#define KDataBasePath @“...”FMDatabase *db = [FMDatabase databaseWithPath:KDataBasePath];```1、打开数据库[db open]2、creat insert 用同一方法:将SQL语句转化为NSString [db executeUpdate:SQLCommandString];3、select 查询用query 返回值:FMResultSet类型 是个集合FMResultSet *result = [db executeQuery:SQLCommandString];if ([result next]) { NSLog(@"select success"); //拿出查询的字段数据 [result stringForColumn:@"name"];}4、关闭数据库[db close];
例子:
打开数据库#define KDataBasePath @“...”FMDatabase *db = [FMDatabase databaseWithPath:KDataBasePath]; if (![db open]) { NSLog(@"could not open db"); return; }else { NSLog(@"open db"); }```
创建数据表 -(void)creatTableWithTableName{ NSString *creatString = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS 'user' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, 'name' TEXT, 'password' TEXT)"]; BOOL result = [db executeUpdate:creatString]; if (result) { NSLog(@"tabel success"); }else { NSLog(@"tabel fail"); }}
查询数据表是否存在-(void)queryTable:(NSString *)tableName{ if ([db executeQuery:@"select count(*) as 'count' from sqlite_master where type = 'table' and name = %@",tableName]) { NSLog(@"tabel 已存在"); }else { NSLog(@"tabel 不存在"); }}
插入一条数据-(BOOL)insertDataWithId:(NSInteger)user_id Name:(NSString *)name Password:(NSString *)password{ //有问题------ BOOL result = [db executeUpdate:@"insert into user (name,password) values (?,?)",name,password]; if (result) { NSLog(@"insert success"); }else { NSLog(@"insert fail"); } return result;}
select选择数据-(BOOL)selectTableWithUserName:(NSString *)name Password:(NSString *)password{ BOOL resultSelect = NO; NSString *selectString = [NSString stringWithFormat:@"select *from 'user' where name = '%@' and password = '%@'",name,password]; FMResultSet *result = [db executeQuery:selectString]; if ([result next]) { resultSelect = YES; NSLog(@"select success"); NSLog(@"%@",[result stringForColumn:@"name"]); }else{ NSLog(@"select fail"); } return resultSelect;}
关闭数据库-(void)closeDataBase{ if (![db close]) { NSLog(@"数据库关闭异常,请检查"); return; }else { NSLog(@"关闭成功"); }}
0 0
- 数据库操作(使用FMDB)
- 数据库操作(使用FMDB)
- 数据库操作(使用FMDB)
- FMDB 数据库简单操作
- 数据库操作(使用FMDB)
- 数据库操作 FMDB
- 数据库操作(使用FMDB)
- 数据库操作(使用FMDB)
- 数据库操作FMDB
- FMDB操作数据库
- 数据库操作(使用FMDB)
- 数据库操作(使用FMDB)
- 数据库操作(使用FMDB)
- 数据库操作(使用FMDB)
- 217,FMDB数据库操作
- 使用FMDB操作数据库
- 数据库操作(使用FMDB)
- FMDB 操作数据库
- 虚拟机启动Ubuntu失败 module devicepoweron power on failed
- 25款简约时尚的页面登陆设计欣赏
- 安装IBM Data Studio Web控制台
- CrossApp 1.1.6新鲜出炉
- 微软良心之作——Visual Studio Code 开源免费跨平台代码编辑器
- FMDB操作数据库
- 形状类族中的纯虚函数
- Asp.net MVC4 + signalR 聊天室实现
- 判断机器大小端
- Opencv的配置
- ggsci命令提示符中看不到的OGG进程
- xcorr 自相关 c++实现
- Java远程执行Linux命令
- 同时安装VS2010 + Qt4.8.6 + Qt Add-in 和VS2008 + Qt4.8.6 + Qt Add-in