I am attempting to write to a database of quotes I have created. If the user selects the "favorite" button, it will add a 1 (or true) value into the favorite column on the SQLITE database. For some reason I cannot write to the database and when I execute this code:
@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])
}
I expect the result to write to the database and place a 1 in the favorite column but sadly this is not the case. I get this error:
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: SQLite error 8 with statement
UPDATE quotes SET favorite = 1 WHERE quote = ?
arguments ["Abstinence is the great strengthener and clearer of reason."]: attempt to write a readonly database
I have tried to chmod 755
the database and that did not work either. Am I missing something?