How to handle a client-side db drop table transaction?

120 Views Asked by At

I've got the following function on my client-side db:

      dropTable = function (a, tbl) {
        a.executeSql('Drop Table If Exists ' + tbl + ';', [], 
          function(a, b){
            console.log('Table "' + tbl + '" dropped.');
          }
        , errorHandler);
      };

What do I have to do to show the console message only when a table is dropped? It currently shows on every function call.

1

There are 1 best solutions below

0
On BEST ANSWER

Looks like your query is "successful" whether it exists or not (since you guard for the case of nonexistence). If you want to fail hard:

     dropTable = function (a, tbl) {
        a.executeSql('Drop Table ' + tbl + ';', [], 
          function(a, b){
            console.log('Table "' + tbl + '" dropped.');
          }
        , errorHandler);
      };

This should call the errorHandler if it doesn't exist. Cheers!