删除调用历史记录文章调用数据库中的一个数据

时间:2013-06-08 02:46:56

标签: ios fmdb

数据库是只读的。

代码:

//获取数据库
    FMDatabase * db = [dataManager openDataBase];
    //判断数据库是否能打开
    if ([db open]) {
        //获取通话记录中所有的address
        FMResultSet * rs = [db executeQuery:@"SELECT address FROM privacy_call"];
        NSString * markaddress = nil;
        while ([rs next]) {
            NSString * address = [rs stringForColumn:@"address"];
            if ([self isEqualContactNumber:address withPrivacyNumber:number] && ![markaddress isEqualToString:address]) {
                markaddress = address;
                //删除数据
                BOOL resultSet = [db executeUpdate:@"DELETE FROM privacy_call WHERE address = ?",address];
                success = resultSet;
            }
        }
        [rs close];
    }
    else {
        NSLog(@"数据库打开错误");
        return NO;
    }

1 个答案:

答案 0 :(得分:0)

很难理解问题是什么,

但如果我猜测,这条线需要像这样更新:

//assuming executeUpdate returns a BOOL
BOOL success = [db executeUpdate:[NSString stringWithFormat:@"DELETE FROM privacy_call WHERE address = %@",address]];