0

I use path obtained from Bundle.main.path can not insert update sqlite database with db.execute function No display error, I do not understand why, please help me below is my code

var config = Configuration()
config.readonly = false
config.foreignKeysEnabled = false
enter code here
let path1:String = Bundle.main.path(forResource: "data", ofType: "sqlite",inDirectory: "Data")!
db = try DatabaseQueue(path: path1,configuration:  config)
--------------
try db.execute("update detail set favorite = \(newDetail.favorite!) where id = \(newDetail.id!)")

1 Answer 1

1

You can not write into a file within the app bundle, you have to copy the sqlite file to e.g. the documents directory and use that copy to save your data.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for supporting me, i'm a newbie, can you create an example for me?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.