Is there a way to open the same db in both readonly mode and write mode #980
-
I have some usecase that need open db in two modes.
Eg:
But it seems the dbReadonly still able to insert/update/delete data. So is there a way to do that ? Thx! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
By default, openDatabase and openReadOnlyDatabase uses the flag 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 dbReadOnly = await openDatabase(path, readOnly: true, singleInstance: false); |
Beta Was this translation helpful? Give feedback.
-
Parsing SQL could be very complex. For simplicity, I would assume that any statement not starting with |
Beta Was this translation helpful? Give feedback.
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):