Skip to content
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

[iOS] attempt to write a readonly database #1124

Open
DjordjeMancic97 opened this issue Aug 16, 2024 · 3 comments
Open

[iOS] attempt to write a readonly database #1124

DjordjeMancic97 opened this issue Aug 16, 2024 · 3 comments

Comments

@DjordjeMancic97
Copy link

DjordjeMancic97 commented Aug 16, 2024

Hello,

I am experiencing weird issue on iOS when trying to create new database after deleting the previous.

Here is the flow:

Database creation

  db = await openDatabase(
      path,
      version: databaseVersion,
      onConfigure: (db) async => await db.execute('PRAGMA foreign_keys = ON'),
      onCreate: (Database db, int version) async {
        await loadDatabaseSchema(db);
      },
    );

After this we have a working database then we close and delete it:

      await db.close();
      final directory = await getApplicationDocumentsDirectory();
      final path = join(directory.path, databaseName);
      await deleteDatabase(path);

All good, db file is gone

However, after this we again run the openDatabase like in first step, database file is created and all tables are there.
However at every attempt of writing some data the error message will appear:

DatabaseException(Error Domain=FMDatabase Code=8 "attempt to write a readonly database" UserInfo={NSLocalizedDescription=attempt to write a readonly database})

This happens only on iOS. Using latest version of sqflite and Flutter 3.22.2

@alextekartik
Copy link
Contributor

Thanks for the report. Indeed that's bad. Can you confirm that the database is not used anywhere else in the mean time?

Can you make a quick test by adding a small delay (let's one second) before opening again to see if the same issue happens?

I won't be able to investigate much more in the next 2 weeks, sorry.

@DjordjeMancic97
Copy link
Author

Hello,

Yeah database is not used anywhere else, also delay is not solution especially because the actions of deleting the database and creating it again are pretty separated and happen at different places so there is just no way these 2 actions are performed within 1 second.

@alextekartik
Copy link
Contributor

Ok, also can you make sure the database folder exists before creating the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants