2

我在 iOS 上使用 FMDB,尝试使用如下语句查询表,

select * from test where foo isNull

在 sqlite C API 中,这最终使用此 API 绑定到 null,

int sqlite3_bind_null(sqlite3_stmt*, int);

这是行不通的。通过 fmdb 调用的选择似乎将列正确绑定到 null 没有找到匹配的记录。

如果在 sqlite3 命令行会话中执行以下命令,它可以工作,但不能通过 FMDB 的 sqlite C API。

select * from test where foo isNull;

这是重现问题的 fmdb 代码。看起来 fmdb 正在执行调用 sqlite3_bind_null 的正确步骤。

        NSString *stmt = @"select * from test where shipToCode=:foo";
        NSDictionary *dict = @{@"foo" : [NSNull null]};
        FMResultSet *rs = [db executeQuery:stmt withParameterDictionary:dict];
        int count = 0;
        while ([rs next]) {
            count++;
        }
        NSLog(@"Count %d", count);
4

2 回答 2

3

NULL无法与=运营商进行比较;它不等于任何值,甚至它本身。

要与 进行比较NULL,您必须使用IS NULL运算符:

stmt = @"select * from test where shipToCode is null";
于 2012-10-30T08:17:34.870 回答
0

请尝试以下操作并检查是否有任何更改:

NSString *query = @"SELECT * FROM test WHERE shipToCode is NULL";

FMResultSet *rs = [db executeQuery:query];
int count = 0;

while ([rs next]) {
    count++;
}

NSLog(@"Count %d", count);
于 2012-10-30T06:07:09.163 回答