Sqlite: db doesn't get created if deleted?

steps:

  1. create a database using SQLite.openDatabase()
  2. connect to device via adb shell and manually delete the database
  3. reload the app
  4. database file is not recreated (even though SQLite.openDatabase code is executed again)
  5. queries do not fail with error. Just returns 0 result.

Is it openDatabase loads it into memory? How do we force it to physically check if database file is present?
On the same note, what is the recommended way to delete a local sqlite db?

If I press the restart button in XDE and the project rebuilds, it seems to recreate the db.
On the android device, If I navigate to settings->app-> expo and click Force Stop, it seems to recreate the database file.

@nikki do you know the answer to this?

@ccheever @nikki following up on this.

How are you manually deleting the database?

step 2 above:

connect to device via adb shell and manually delete the database

so i simply rm the physical database file.

@nikki Following up on this. Am interested to know your thoughts.

@nikki how can I upgrade the database when the database design is changed ( changing on the version of the db ) , there is no delete method in SQLite class, and the version parameter will be ignored in the open method according to your documentation
“name (string) — Name of the database file to open.
The version, description and size arguments are ignored, but are accepted by the function for compatibility with the WebSQL specification”
Any suggestion please.

So, currently there isn’t a specific method to delete or upgrade SQLite databases. Created an issue to track this here: https://github.com/expo/expo/issues/639

We can scope this feature for the SDK for at least version 22. @msanduka do you think you could do a workaround by creating new tables within the database?

1 Like

This should be fixed by https://github.com/expo/expo/commit/12aeb4aa6b871c4763dd228ee5de4def043e2a8c which will most likely be released in SDK 24. Again, tracking on GitHub issue here: https://github.com/expo/expo/issues/639

1 Like

thanks @nikki

was reading the changelog for sdk v24 today and saw this change made it in.