我正在尝试写入我创建的报价数据库。如果用户选择“收藏”按钮,它将在 SQLITE 数据库的收藏列中添加一个 1(或真)值。由于某种原因,我无法写入数据库,当我执行此代码时:
@IBAction func addFavorite(_ sender: Any) {
var configuration = Configuration()
configuration.readonly = false
let dbPath = Bundle.main.path(forResource: "data", ofType: "db")!
let dbQueue = try! DatabaseQueue(path: dbPath, configuration: configuration)
try! dbQueue.inDatabase { db in
try db.execute("""
UPDATE quotes SET favorite = 1 WHERE quote = ?;
""",
arguments: [quoteLabel.text])
}
我希望结果写入数据库并将 1 放在最喜欢的列中,但遗憾的是事实并非如此。我收到此错误:
线程 1:致命错误:“尝试!” 表达式意外引发错误:SQLite error 8 with statement
UPDATE quotes SET favorite = 1 WHERE quote = ?
arguments ["Abstinence is the greatstrengthener and clearer of reason."]: 尝试编写只读数据库
我试过chmod 755
数据库,但也没有用。我错过了什么吗?