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];
}];
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];
}];
相关文章推荐
- 代理设计模式
- text-overflow:ellipsis
- 关于职业生涯规划的会议记录
- 职场新人,你进入职场应该规划的事
- 字符串的正则表达式
- linux——创建用户及所属组总结
- YII1升级到YII2的注意事项
- LeetCodeOJ.Longest Substring Without Repeating Characters
- 最长递增子序列
- 数学问题和狼追兔问题
- eclipse下修改tomcat的URIEncoding为UTF-8
- 计算1/1-1/2+1/3-1/4......+1/99-1/100的值
- 详细透彻的分析DM9000网卡驱动程序(1)
- 分享txt转换pdf格式具体转换方法
- sh脚本语法_基础
- 在一个Activity 里面去关闭另一个Activity或者多个Acitivity
- 各种RAID的理解
- 20个非常有用的Java程序片段
- Java 理论与实践: 变还是不变?
- 惠普公司将拆成两家公司