I have a view in which I am inserting data in a background thread to sqlite database coming from server. Now when user taps and navigate to another view in which I have to read the contents from this database, but I am not able to fetch the contents as the database is already open in background thread of last view and it gives error “database is locked”.
NOTE: both the operations are in different Tables i.e I am writing in different table and reading from other table.
Does sqlite support multi threading, If yes then how can I remove the lock from database?
SQLite supports multithreading. You can share your connection handle/object between threads, they’ll sync their access nicely.
EDIT: pass the
sqlite3object (the one thatsqlite3_open()returns as the second parameter) to the thread instead of reopening the database in the thread. Something like this:Inside the thread, recover the SQLite3 object like this: