使用 swift + FMDB 插入 NULL
Insert NULL with swift + FMDB
如何将 NULL 插入到具有 swift
的列中
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() ]
如何将 NULL 插入到具有 swift
的列中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() ]