标签:nsarray 优点 string mda nsstring sts 存在 str round
● FMResultSet
? 使用FMDatabase执行查询后的结果集
● FMDatabaseQueue
? 用于在多线程中执行多个查询或更新,它是线程安全的
NSLog(@"数据库打开失败!"); }
● 文件路径有三种情况
● 具体文件路径
? 如果不存在会自动创建
● 空字符串@""
? 会在临时目录创建一个空的数据库
? 当FMDatabase连接关闭时,数据库文件也被删除
● nil
? 会创建一个内存中临时数据库,当FMDatabase连接关闭时,数据库会被销毁
● -(FMResultSet*)executeQuery:(NSString*)sql,...
● -(FMResultSet*)executeQueryWithFormat:(NSString*)format,...
● -(FMResultSet*)executeQuery:(NSString*)sql withArgumentsInArray:(NSArray *)arguments
● 示例
// 查询数据
FMResultSet *rs = [db executeQuery:@"SELECT * FROM t_student"];
// 遍历结果集
while ([rs next]) {
NSString *name = [rs stringForColumn:@"name"];
int age = [rs intForColumn:@"age"];
double score = [rs doubleForColumn:@"score"];
}
● 为了保证线程安全,FMDB提供方便快捷的FMDatabaseQueue类 ● FMDatabaseQueue的创建
FMDatabaseQueue *queue = [FMDatabaseQueue
databaseQueueWithPath:path];
[db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Jack"];
[db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Rose"];
[db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Jim"];
FMResultSet *rs = [db executeQuery:@"select * from t_student"];
while ([rs next]) {
// ...
} }];
[db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Jack"];
[db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Rose"];
[db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Jim"];
FMResultSet *rs = [db executeQuery:@"select * from t_student"];
while ([rs next]) {
// ...
} }];
标签:nsarray 优点 string mda nsstring sts 存在 str round
原文地址:http://www.cnblogs.com/liuwj/p/6696810.html