Sqlite: db doesn't get created if deleted?


#1

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.


#2

@nikki do you know the answer to this?


#3

@ccheever @nikki following up on this.


#4

How are you manually deleting the database?


#5

step 2 above:

connect to device via adb shell and manually delete the database

so i simply rm the physical database file.


#6

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


#7

@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.


#8

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?


#9

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


#10

thanks @nikki

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