sqlite(fmdb)选择x不起作用的位置



我正在使用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);

NULL无法与 =操作员进行比较;它与值不等,甚至本身。

要与NULL进行比较,您必须使用IS NULL操作员:

stmt = @"select * from test where shipToCode is null";

尝试以下内容,并检查是否有任何更改:

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);

最新更新