2012-10-30 31 views
2

,試圖查詢一個表,如發表聲明,SQLITE(FMDB)選擇其中x是空不是我使用FMDB iOS上的工作

select * from test where foo isNull 

在SQLite的C API,這最終結合使用此API爲空,

int sqlite3_bind_null(sqlite3_stmt*, int); 

這是行不通的。通過fmdb調用的select似乎正確地將該列綁定到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); 

回答

3

NULL不能與=運營商相比,它不等於任何價值,甚至本身。

要與NULL比較,你必須使用IS NULL操作:

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

我發現這對我自己的。描述得很好。 – David

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