如何使用 swift 将 NULL 插入到列中
let myNullableValue: Double? = nil
fmdb.executeUpdate(
"INSERT INTO myTable(myNullableColumn) SELECT :myNullableValue"
, withParameterDictionary: [ "myNullableValue": myNullableValue ])
最佳答案
来自 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() ]
关于sqlite - 使用 swift + FMDB 插入 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30206010/