FMDataBaseQueue 是线程安全的,可以在多线程中放心使用
FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithPath:dbPath]
[queue inDatabase:^(FMDatabase *adb) {
[adb executeUpdate:@"create table qfoo (foo text)"];
[adb executeUpdate:@"insert into qfoo values ('hello')"];
FMResultSet *rsl = [adb executeQuery:@"select * from qfoo where foo like 'h%'"]
}
//处理事务 大量数据库存取操作效率高 失败一次性回滚
[queue inTransaction:^(FMDatabase *adb, BOOL *rollback) {
NSLog(@"Starting update %ld", nby);
[adb executeUpdate:@"insert into qfoo values ('1')"];
[adb executeUpdate:@"insert into qfoo values ('2')"];
[adb executeUpdate:@"insert into qfoo values ('3')"];
NSLog(@"Ending update %ld", nby);
}];
*当数据库文件存储到 Docments 需设置不上传icloud