ios FMDB 怎么查询本地数据库
我自己下载了一个笑话数据库,怎么用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];
}
}
上边是我的代码,求大神帮帮我,谢谢了