ios FMDB 怎么查询本地数据库

qq_27364703 2015-07-20 03:31:10
我自己下载了一个笑话数据库,怎么用fmdb把里边的内容取出来,,,,,,,,
NSArray *doucumentDirectory=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *file=[doucumentDirectory objectAtIndex:0];
NSString *dafile=[file stringByAppendingPathComponent:@"data.db"];
NSLog(@"%@",dafile);
if ([[NSFileManager defaultManager]fileExistsAtPath:dafile])
{
NSLog(@"数据库已存在");
}

_db=[FMDatabase databaseWithPath:dafile];

if (!_db)
{
NSLog(@"数据库创建不成功");
}
else
{
if([_db open])
{
NSLog(@"数据库创建成功并打开");
NSString *sqlCreateTable = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS joke (id INTEGER PRIMARY KEY AUTOINCREMENT, content TEXT)"];
BOOL res = [_db executeUpdate:sqlCreateTable];
NSLog(@"%d",res);
if (!res) {
NSLog(@"error when creating db table");
} else {
NSLog(@"success to creating db table");
}
NSString *sql = [NSString stringWithFormat:@"select * from joke"];
FMResultSet *result = [_db executeQuery:sql];
NSMutableArray *array=[[NSMutableArray alloc]initWithCapacity:0];
while ([result next])
{
NSString * uid=[result stringForColumn:@"content"];


[array addObject:uid];

}
NSLog(@"%@",array);


[_db close];



}
}
上边是我的代码,求大神帮帮我,谢谢了
...全文
728 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_27364703 2015-07-20
  • 打赏
  • 举报
回复
大神都去哪了??????
qq_27364703 2015-07-20
  • 打赏
  • 举报
回复
求大神啊,求大神
qq_27364703 2015-07-20
  • 打赏
  • 举报
回复

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧