FMDB

来源:互联网 发布:淘宝天天特价报名条件 编辑:程序博客网 时间:2024/05/16 17:49

[self.dbQueueinDatabase:^(FMDatabase *db) {

        [dbopen];

       BOOL stored = NO;

        

        //如果表不存在,建表

       NSString *sqlstr = [NSStringstringWithFormat:@"create table if not exists favoriteList (title,description,indexID,created,thumbnail,source,thumbnail_top)"];

        [dbexecuteUpdate:sqlstr];

        

       //查询存在与否

        NSString * string = [NSStringstringWithFormat:@"select * from favoriteList where indexID = ?"];

       FMResultSet * rs = [db executeQuery:string,news._id];

        

        //如果存在。。。。

       while ([rs next]) {

            stored =YES;

           break;

        }

        

       if (!stored) {

            NSString * sql = [NSStringstringWithFormat:@"insert into favoriteList (title,description,indexID,created,thumbnail,source,thumbnail_top) values (?,?,?,?,?,?,?)"];

           

           int i = [db executeUpdate:sql,news.title,news.descriptions,news._id,news.created,news.thumbnail,news.source,news.thumbnail_top];

            

           if (i) {


                UIAlertView * alertView = [[UIAlertViewalloc]initWithTitle:nilmessage:@"收藏成功"delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];

                [alertViewshow];

                

            }

        }

        [dbclose];

    }];


0 0
原创粉丝点击