FMDB、Swift 3、executeUpdate - 编译器构建失败

Posted

技术标签:

【中文标题】FMDB、Swift 3、executeUpdate - 编译器构建失败【英文标题】:FMDB, Swift 3, executeUpdate - compiler build failed 【发布时间】:2016-10-16 11:40:46 【问题描述】:

我在 Swift 3 中使用 FMDB。 在 Swift 2 上一切正常,但在进行 Swift 升级后,我得到: “由于信号导致命令失败:杀死:9”

在调查了它的原因后,我发现在 ArgumentsArray 中使用大约 24 个参数执行“executeUpdate”会导致编译器非常慢并最终返回编译错误。

将数组中的参数数量减少到20个时,编译器构建仍然很慢但成功完成。

欢迎任何想法/帮助...!

这是我的代码: (构建成功,但取消注释下面的 4 行将导致编译构建失败。任何其他 4 行当然会产生相同的结果)

func insertLocalization(_ localization: Localization) -> Bool 
        print ("Insert Localization: \(localization.localization_object_id!)#\(localization.spot_object_id!)#\(localization.language_code!)")
        sharedInstance.database!.open()
        let isInserted = sharedInstance.database!.executeUpdate(
            "INSERT INTO localizations (" +
                "localization_object_id, " +
                "spot_object_id, " +
                "language_code, " +
                "current_location_enabled, " +
                "spot_title, " +
                "spot_desc, " +
                "local_assistant_phone, " +
                "orientation_360_enabled, " +
                "direction_n_title, " +
                "direction_n_desc, " +
                "direction_ne_title, " +
                "direction_ne_desc, " +
                "direction_e_title, " +
                "direction_e_desc," +
                "direction_se_title, " +
                "direction_se_desc, " +
                "direction_s_title, " +
                "direction_s_desc, " +
                "direction_sw_title, " +
                "direction_sw_desc, " +
                "direction_w_title, " +
                "direction_w_desc, " +
                "direction_nw_title, " +
                "direction_nw_desc) " +
            "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
            withArgumentsIn: [
                // localization.localization_object_id!,
                // localization.spot_object_id!,
                // localization.language_code!,
                // localization.current_location_enabled!,
                localization.spot_title!,
                localization.spot_desc!,
                localization.local_assistant_phone!,
                localization.orientation_360_enabled!,
                localization.direction_n_title!,
                localization.direction_n_desc!,
                localization.direction_ne_title!,
                localization.direction_ne_desc!,
                localization.direction_e_title!,
                localization.direction_e_desc!,
                localization.direction_se_title!,
                localization.direction_se_desc!,
                localization.direction_s_title!,
                localization.direction_s_desc!,
                localization.direction_sw_title!,
                localization.direction_sw_desc!,
                localization.direction_w_title!,
                localization.direction_w_desc!,
                localization.direction_nw_title!,
                localization.direction_nw_desc!
            ])
        sharedInstance.database!.close()
        return isInserted
    

谢谢!

【问题讨论】:

【参考方案1】:

此代码在 Xcode 8.0 (8A218a) 中编译对我来说没有任何问题。但是,如果这对您不起作用,我建议您拆分队列,例如

let values =  [localization.localization_object_id!, ..., localization.direction_nw_desc!]

let isInserted = sharedInstance.database!.executeUpdate(
    "INSERT INTO localizations (...) " +
    "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
    withArgumentsIn: values)

【讨论】:

不幸的是,这没有帮助:(我目前的临时解决方案是首先将其分为 2 个操作:插入 不幸的是没有帮助:(我目前的临时解决方案是将INSERT操作分为2个操作:首先,插入前8列,然后用最后16列更新插入的记录。实用虽然但我认为不是那么优雅的解决方案。

以上是关于FMDB、Swift 3、executeUpdate - 编译器构建失败的主要内容,如果未能解决你的问题,请参考以下文章

无法使用 swift 3 在 FMDB 中执行更新

FMDB 不显示任何东西 - 迅速

使用 Swift 的 FMDatabaseQueue (FMDB)

使用 swift + FMDB 插入 NULL

如何在 Swift 中使用“FMDB/SQLCipher”进行加密和解密?

使用 Swift + FMDB 打开和关闭数据库