【问题标题】:Insert NULL with swift + FMDB使用 swift + FMDB 插入 NULL
【发布时间】:2015-05-13 04:57:06
【问题描述】:

如何使用 swift 将 NULL 插入列中

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

【问题讨论】:

    标签: sqlite swift null fmdb


    【解决方案1】:

    来自 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() ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-23
      • 2016-01-23
      • 2012-04-23
      • 2018-04-06
      相关资源
      最近更新 更多