gpt4 book ai didi

swift - 添加复杂查询后,项目的构建和运行时间过长

转载 作者:行者123 更新时间:2023-11-30 12:19:47 25 4
gpt4 key购买 nike

我已经在我的一个 swift 项目中集成了 SQLite.swift 框架,一切都工作正常,直到我添加了以下查询。添加以下查询项目后,构建时间太长。我等了30分钟,但项目仍然没有得到满足。

do
{
let stmt = try DB!.prepare ("SELECT e." + ENDPOINT_ID + " as _id, lk." + HUB_ID + ", e." + X_ENDPOINT_ID + ", e." + ENDPOINT_DESC + ", e." + ENDPOINT_TYPE_ID +", et." + ENDPOINT_STATUS_MIN + ", et." + ENDPOINT_STATUS_MAX + ", e." + ENDPOINT_STATUS + " FROM " + TABLE_ENDPOINT + " as e INNER JOIN " + TABLE_ENDPOINT_TYPE + " as et " +
" ON e." + ENDPOINT_TYPE_ID + " = et." + ENDPOINT_TYPE_ID +
" INNER JOIN " + TABLE_LINKING + " as lk " +
" ON e." + ENDPOINT_ID + " = lk." + ENDPOINT_ID +
" INNER JOIN " + TABLE_NODE + " as n " +
" ON lk." + NODE_ID + " = n." + NODE_ID +
" INNER JOIN " + TABLE_NODE_TYPE + " as nt " +
" ON n." + NODE_TYPE_ID + " = nt." + NODE_TYPE_ID +
" WHERE lk." + SECTION_ID + "=" + section_Id +
" AND nt." + NODE_CATEGORY + " = "S" " +
" ORDER BY e." + ENDPOINT_ID + " ASC")

let arr = Array(try stmt.run)

print("\(arr)")
return arr
} catch {
print("failed: \(error)")
return []
}

如果我注释上面的代码并尝试运行该项目,则运行该项目几乎不需要一分钟,但添加此代码后,需要花费大量时间。我已经等了将近 30 分钟,但该项目仍然没有编译,也没有抛出任何错误。预先感谢您的帮助

最佳答案

Swift 编译器在处理大字符串文字时遇到困难。另请参阅this question以获得进一步的提示。

我建议拆分 sql 并以小步骤构建字符串变量:

var sql = "SELECT e." + ENDPOINT_ID
sql = sql + HUB_ID + ", e."
sql = sql + X_ENDPOINT_ID + ", e."
...
let stmt = try DB!.prepare(sql)

关于swift - 添加复杂查询后,项目的构建和运行时间过长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44940913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com