FMDB 操作数据库

操作数据库,之前,统一操作:
if (![db open]) {
        [db release];
        return;
}
之后统一操作:
[db close];




1、创建表:
[db executeUpdate:[NSString stringWithFormat:@"CREATE TABLE %@ (title text,id text UNIQUE,image text,user text,article text,time text,rt text,text text,weight text,desc text,type text,comments text,reposts text)",tablename]];


2、插入数据:
BOOL isSuccess = [db executeUpdate:[NSString stringWithFormat:@"insert into %@ (title,id,image,user,article,time,rt,text,weight,desc,type,comments,reposts) values(?,?,?,?,?,?,?,?,?,?,?,?,?)",tablename],
                              status.title,
                              status.id_ ,
                              imagedict,
                              userdict,
                              articledict,
                              status.time,
                              rtdict,
                              status.text,
                              status.weight,
                              status.desc,
                              status.type,
                              status.comments,
                              status.reposts
                              ];


3、查找数据:
FMResultSet *rs = [db executeQuery:[NSString stringWithFormat:@"select * from %@ where id = ?",tablename],[statusIdArray objectAtIndex:i]];
while ([rs next]) {
           NSMutableDictionary* statusdict = [[NSMutableDictionary alloc] init];
            if ([rs stringForColumn:@"title"])
                [statusdict setObject:[rs stringForColumn:@"title"] forKey:@"title"];
           。。。。。。
}


4、删除指定表的数据:
NSString *delegeTable = [NSString stringWithFormat:@"delete from %@",[NSString stringWithFormat:@"section_statuses_%@", sectionId]];
[db executeUpdate:delegeTable];


5、删除所有表的数据:
[db executeUpdate:[NSString stringWithFormat:@"delete * from %@",tablename]];


6、查询当前表中的数据条数
[db intForQuery:[NSString stringWithFormat:@"select count(id) from %@",tablename]];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值