您的位置:首页 > 其它

FMDB

2015-10-08 14:04 316 查看
[self.dbQueue
inDatabase:^(FMDatabase *db) {
[db
open];

BOOL stored = NO;

//如果表不存在,建表

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

//查询存在与否

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

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

//如果存在。。。。

while ([rs next]) {
stored =
YES;

break;
}

if (!stored) {

NSString * sql = [NSString
stringWithFormat:@"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 = [[UIAlertView
alloc]initWithTitle:nil
message:@"收藏成功"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil,
nil];
[alertView
show];

}
}
[db
close];
}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: