question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Open database error not firing

See original GitHub issue

Hi,

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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
andporcommented, Nov 21, 2017

Have to try this myself…

1reaction
scgoughcommented, Nov 20, 2017

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:

private class DBRunner implements Runnable {
        final String dbname;
        final int openFlags;
        private String assetFilename;
        private boolean androidLockWorkaround;
        final BlockingQueue<DBQuery> q;
        final CallbackContext openCbc;
        
        ...
        public void run() {
            try {
                this.mydb = openDatabase(dbname, this.assetFilename, this.openFlags, this.openCbc);
            } catch (Exception e) {
                FLog.e(TAG, "unexpected error, stopping db thread", e);

                this.openCbc.error("database access exception"); //<- NEW CALLBACK PUSH HERE

                dbrmap.remove(dbname);
                return;
            }
        ...

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix Microsoft Access Database Error 3049- Cannot Open ...
Method 1 ? Run Access Compact and Repair Utility. If you are receiving the error message "Cannot open database. It may not be...
Read more >
How to Fix "Cannot open database. (Error 3049)" in MS Access
You may come across a message “Cannot open database. (Error 3049)” while working on your Access database. You were probably creating new ...
Read more >
OpenDatabase Error after modifying existing database in Flutter
When the database is newly created onCreate is called with the databse version (here 2). The database version is saved to the database, ......
Read more >
Unable to open a database with connection error - Office
When you open your database in Access, you receive the following error message: Method 'Connection' of object '_Current Project' failed.
Read more >
How to Resolve Access Database Cannot Open Issue
database not opening error, etc. · Reason 1 – Access Database Files on the network are locked · Reason 2 – Connection between...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found