-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqliteException(5): while executing statement, database is locked, database is locked (code 5) #2781
Comments
By default, sqlite3 uses a locking scheme that will not allow concurrent reads and writes. If one connection is read-only, enabling write-ahead logging with |
I'm getting a similar issue using an isolate trying to connect to the same database, @simolus3 could you give an example of how you would write this out in the customStatement()? Is there some way a read can wait for the other task to end? This is my code below.
Trying to figure out how i can do this concurrent in an isolate without locking erros |
To add, i think i'm getting the locked when my app first starts which is trying to connect at the same time most likely |
If you want to share the database isolate between the clients, you can open the drift isolate first, you can then send it as a parameter to the other isolate you're spawning. Or does one of the locked exception come from C++? |
i think my issue was not opening the first database before the isolate went to town, I staggered the initialization and seems to be working now! |
Before we get started, I always appreciate a good library. I used wal mode but database lock error was not solved,,,, beforeOpen: (details) async {
await customStatement('PRAGMA foreign_keys = ON');
await customStatement('PRAGMA journal_mode = wal');
}, Update 1I found why this error occured. most of error occured in onUpgrade. and onUpgrade called before beforeOpen. So PRAGMA journal_mode = wal doesn't called on beforeOpen. Can I use wal mode in beforeOpen? Update 2Also, after enabling WAL mode, I got the below error along with it. Do you have any idea about this issue and if so, could you share it?
|
You could try doing this in the
I haven't seen this one before, but I wonder if it might be happening because the switch between journal modes temporarily needs to lock the whole database? In addition, you could try setting the busy timeou pragma in |
Thank you so much simolus3 We solved the problem |
Hi simolus3, first of all thank you for good library!
Bug Explain
I'm currently opening drift's sqlite file in IOS WidgetKit with the code below.
My guess is that this open db is causing the SqliteException(5). But the weird thing is that I opened sqlite in read mode. As I understand it, sqlite3 can be accessed by multiple processes concurrently. Is that not available in Drift? Or is there something I'm misunderstanding?
Logs
Environment
flutter doctor
Drift Version
Reproduce Step
Reproducing in a new project. Give me a moment. The reproduction steps I'm thinking of are as follows
End
If you need additional information, please ask! Thanks for reading this long post.
The text was updated successfully, but these errors were encountered: