Skip to content

Is there a way to open the same db in both readonly mode and write mode #980

Answered by alextekartik
quangson91 asked this question in Q&A
Discussion options

You must be logged in to vote

By default, openDatabase and openReadOnlyDatabase uses the flag singleInstance: true which means "The first to open wins" and any other call to openDatabase will get the same instance (i.e. in your case not read-only). One solution is to set this flag to false. This is not something many people used as it means that you might encounter lock issue (which means sometimes retrying an operation) when the 2 instances access the database at the same time.

What you can try (so unfortunately here you cannot use openReadOnlyDatabase as it does not have this options):

// Open in write mode
var dbWritable = await openDatabase(path, readOnly: false, singleInstance: false);
// Open in read mode
var db…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@quangson91
Comment options

Answer selected by quangson91
Comment options

You must be logged in to vote
1 reply
@quangson91
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants