Open database error not firing
See original GitHub issueHi,
Platform: Android RN Version: 0.44.3 This Plugin Version: 3.3.1
I’m experiencing an issue where the error callback on an unsuccessful openDatabase
attempt isn’t firing.
The scenario I have is that I am updating in React-Native. I need to check for a legacy database on the app’s first open after update and migrate data from the old database to the new database.
The old database may or may not exist on the user’s device. For example, if they are newly installing the app they won’t have it.
I would like to attempt to open said legacy database and if it fails to find it, skip the data migration process.
When I test this in the scenario of the database not existing on my device I can see an error being caught in the SQLite native plugin code but the error callback never gets fired on the JS side.
Here is the native side error:
E/unknown:SQLitePlugin: unexpected error, stopping db thread
java.io.FileNotFoundException: www/mylegacydatabase.sqlite
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at org.pgsqlite.SQLitePlugin.openDatabase(SQLitePlugin.java:383)
at org.pgsqlite.SQLitePlugin.access$000(SQLitePlugin.java:49)
at org.pgsqlite.SQLitePlugin$DBRunner.run(SQLitePlugin.java:923)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Has anyone experienced this? Is there a work-around/fix?
This may also be affecting the success callback as well - unconfirmed as of yet
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:10 (5 by maintainers)
Have to try this myself…
update It seems like if you try and open a DB that isn’t there (resulting in the above exception) you don’t get the response to your specified error callback on the JS side.
In addition, if you try and run some SQL over the closed instance (for example, to try and test if the db is there as you don’t know either way) there is quite rightly an exception thrown BUT again, no callback is fired…so you’re kind of stuck.
I have found a way to get some kind of callback to the JS in this scenario. I’ve edited
SQLitePlugin.java
as follows:I’m still testing but this seems to fire my desired error callback on the
openDatabase
execution if the database in question doesn’t exist.Any further help/advice would be appreciated still.