2015-05-13 75 views
2

如何插入NULL与迅速插入NULL与SWIFT + FMDB

let myNullableValue: Double? = nil 
fmdb.executeUpdate(
    "INSERT INTO myTable(myNullableColumn) SELECT :myNullableValue" 
    , withParameterDictionary: [ "myNullableValue": myNullableValue ]) 

回答

3

从FMDB源代码列在 https://github.com/ccgus/fmdb/blob/master/src/fmdb/FMDatabase.m

- (void)bindObject:(id)obj toColumn:(int)idx inStatement:(sqlite3_stmt*)pStmt { 

    if ((!obj) || ((NSNull *)obj == [NSNull null])) { 
     sqlite3_bind_null(pStmt, idx); 
    } 
    // ... 

可以得出结论,一个NSNull值插入作为SQLite NULL, 即参数字典应该是

[ "myNullableValue": NSNull() ]