FMDatabase是个不错的开源ObjectiveC的sqlite wrapper。Github下载地址如下:https://github.com/ccgus/fmdb
GitHub页面上有详细的使用方法。这里介绍下几种主要的操作:
创建数据库
FMDatabase *db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
打开数据库
if (![db open]) {
[db release];
return;
}
查询
FMResultSet *rs = [db executeQuery:@"SELECT age, name, isMale FROM myTable"];
while ([rs next]) {
//retrieve values for each record
NSInteger age = [rs intForColumn:@"age"];
NSString *name = [rs stringForColumn:@"name"];
BOOL isMale = [rs boolForColumn:@"isMail"];
//longForColumn:, longLongIntForColumn:,boolForColumn:
//doubleForColumn:,stringForColumn:,dateForColumn:
//,dataForColumn:,dataNoCopyForColumn:
//,UTF8StringForColumnIndex:,objectForColumn:}
关闭
[db close];
事务
[db beginTransaction];
[db commit];