美文网首页
iOS数据库存储框架FMDB的使用

iOS数据库存储框架FMDB的使用

作者: Bryan5137 | 来源:发表于2016-05-05 13:42 被阅读45次

    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];

    }];

    相关文章

      网友评论

          本文标题:iOS数据库存储框架FMDB的使用

          本文链接:https://www.haomeiwen.com/subject/kjedrttx.html