NSString* sqlPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)[0]stringByAppendingPathComponent:@"bank.sqlite"];
FMDatabaseQueue* queue = [FMDatabaseQueuedatabaseQueueWithPath:sqlPath];
[queue inDatabase:^(FMDatabase*db) {
[db beginTransaction];
BOOL flag =[db executeUpdate:@"create table if not exists t_bank (id integer primary key auto increment,name string)"];
if(flag) {
NSLog(@"success");
}else
{
NSLog(@"faiure");
[db rollback];
}
BOOL flag1 = [db executeUpdate:@"insert into t_bank (name) values(?);",@"haha"];
if(flag1) {
NSLog(@"success1");
}else
{
NSLog(@"faiure");
[db rollback];
}
FMResultSet* result = [db executeQuery:@"select* from t_bank"];
while([result next]) {
NSString* name = [result stringForColumn:@"name"];
int pid = [result intForColumn:@"id"];
NSLog(@"%d---%@",pid,name);
}
[db commit];
}];
网友评论