react-native-sqlite-storage icon indicating copy to clipboard operation
react-native-sqlite-storage copied to clipboard

React-native-sqlite-storage does not error when opening or executingsql.

Open shumii opened this issue 5 years ago • 1 comments

The openDatabase call is not throwing an error even if I purposely write the wrong db name. I can't find documentation on how to properly call openDatabase so my technique is to hack it myself but I would need to know when its wrong and when its right in order to do that. openDatabase succeeds regardless, and the subsequent executesql call just does nothing - no errors or success.

  errorCB(err) {
    console.log("SQL Error: " + err);
  }
 
  openCB() {
    console.log("Database OPENED");
  }

  var db = openDatabase({name : "whatever.db",createFromLocation:"~whatever.db"}, 
  this.openCB,this.errorCB);      
   
        db.executeSql("select top 1 * from anything", 
                      [], (tx, results) => {                    
            console.log("\n\nQuery completed\n");         
         
        });

The above code is what I got from reading online and looks simple enough and should work. I even took out the transaction to make it simpler. No matter what I do, the open database 'succeeds' and the executeSql seems to do nothing.

shumii avatar Jan 10 '20 05:01 shumii

Your executeSql call is missing its own error callback. If there isn't an error callback, any errors from trying to execute the sql statement will be lost (although it does look like the code attempts to catch and log that case: https://github.com/andpor/react-native-sqlite-storage/blob/master/lib/sqlite.core.js#L400-L405). You can pass in the errorCB you defined above.

        db.executeSql("select top 1 * from anything", 
                      [],
                      (tx, results) => {console.log("\n\nQuery completed\n")},
                      errorCB);

It's possible that using the wrong database name has caused a bug that created a blank database, or that happened when you were trying to figure out the correct way to call openDatabase. See what adding an error callback to the executeSql call tells you.

lindboe avatar Feb 28 '20 20:02 lindboe