gpt4 book ai didi

ios - 从 IOS 应用程序同时多次查询数据库导致崩溃

转载 作者:行者123 更新时间:2023-11-29 05:25:33 26 4
gpt4 key购买 nike

我正在使用 MySqlDriver 直接从我的 iOS 应用程序访问关系数据库。但如果我同时使用多个查询,则会导致驱动程序崩溃。驱动程序位于以下库中: https://github.com/mcorega/MySqlSwiftNative

我使用的代码是:

class ViewController: UIViewController {

let con = MySQL.Connection()
override func viewDidLoad() {
super.viewDidLoad()
let db_name = "database"

do{
try con.open("localhost", user: "root", passwd: "1234")
try con.use(db_name)
}
catch (let e) {
print(e)
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


@IBAction func onClickButton(sender: UIButton!){
DispatchQueue.global(qos: .background).async {
print("gone")
let select_stmt = try? self.con.prepare("query")
let stRes = try? select_stmt!.query([])
if let rr = try? stRes!.readAllRows() {
print(rr)
if rr!.count > 0{
// completion(true, (rr.first!))
}else{
// completion(true, [[String: Any]]())
}
}
}
}

}

最佳答案

我已经更新了您的代码。请检查并告诉我它是否适合您。

@IBAction func onClickButton(sender: UIButton!){
DispatchQueue.main.async {
print("Success")
let select_stmt = try? self.con.prepare("query")
let stRes = try? select_stmt!.query([])
if let rr = try? stRes!.readAllRows() {
print(rr)
if rr!.count > 0{
// completion(true, (rr.first!))
}else{
// completion(true, [[String: Any]]())
}
}
}
}

关于ios - 从 IOS 应用程序同时多次查询数据库导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58218619/

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