sqlite - 使用 swift + FMDB 插入 NULL

标签 sqlite swift null fmdb

如何使用 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/

相关文章:

objective-c - 从 Swift 访问 Objective-C 变量/函数

xcode - 如何像在 Visual Studio 中那样使用 Xcode 在 Swift 中折叠注释 block ?

sql-server - 将值赋给 Null 在十进制类型上抛出错误

ios - 如何在 Swift 中对对象进行 Nil

java - 从一个表中选择仅通过两个一对多表连接到另一个表中的一个值的值

ios - 来自 URL 的 PDF 在 WKWebView 中无法正确显示?

sqlite - Ionic2:使用SQLite,Ionic服务

null - 如果在 sas 中过滤后输出为空,如何显示消息

iphone - 如何将 sqlite3_column_blob 与 NSData 一起使用

sqlite - 将值设置为未知工资