tekartik / sembast_sqflite

sembast on top of sqflite
BSD 2-Clause "Simplified" License
13 stars 1 forks source link

openDatabase fails on macOS #7

Closed tiloc closed 3 years ago

tiloc commented 3 years ago

I am using the following code to open a database:

final dir = await getApplicationDocumentsDirectory();

      if (dir != null) {
        // make sure it exists
        await dir.create(recursive: true);
        // build the database path
        final dbPath = join(dir.path, 'synchres.db');
        // open the database
        final db = await getDatabaseFactorySqflite(sqflite.databaseFactory)
            .openDatabase(dbPath);

Works great on Android. However, when I try this on MacOS I am getting the following exception:

Error Domain=FMDatabase Code=26 \"file is not a database\" UserInfo={NSLocalizedDescription=file is not a database}

And the following Debug output:

2021-02-18 20:56:18.412 flutter_healthcare[27350:337697] Unknown error calling sqlite3_step (26: file is not a database) rs
2021-02-18 20:56:18.418 flutter_healthcare[27350:337697] Unknown error calling sqlite3_step (26: file is not a database) eu
2021-02-18 20:56:18.418 flutter_healthcare[27350:337697] DB Query: BEGIN EXCLUSIVE
2021-02-18 20:56:18.418 flutter_healthcare[27350:337697] Unknown error finalizing or resetting statement (26: file is not a database)
2021-02-18 20:56:18.418 flutter_healthcare[27350:337697] DB Query: BEGIN EXCLUSIVE

The dbPath has value /Users/tilo/Library/Containers/com.example.flutterHealthcare/Data/Documents/synchres.db.

Is there any recommendation specific to macOS how to calculate a proper path? Or do I have to manually create an empty DB file?

I am on the following versions: sembast_sqflite: ^2.0.0 sqflite: ^2.0.0 sembast: ^3.0.0-nullsafety

tiloc commented 3 years ago

Aarrghhh, I had migrated from regular sembast to sembast_sqflite. The sqflite was trying to open the old JSON file...