title: How to know that Web SQL already exist?
body: <p>I am making very simple application in cordova for ios/android. I have made it all but I am getting problem in database. I am trying to make sure that when app run it look for internet and if internet is available than it login using api, but it also create two databases one for user login(I know it is not good practice, but my requirement will search something to encrypt database) and save only current user in database. While other db will be used to store offline working of user. But when I am not clear how to know if my db is already made. Following are codes, kindly check, as I have search everywhere and seem like there is no solution except to check tables but when I do check tables my program stops to work.</p>
  
  <p>When application start it asks userid, password than after validation following commands run.</p>
  
  <pre><code>document.addEventListener("deviceready", onDeviceReady(user, serviceURL, pass), false)
  </code></pre>
  
  <p>Following is function I am using on deviceready, if internet available it log in user and create db, if internet is not available it access db, but here is problem how I know if db exist so let login user otherwise alert him that internet is required for first time.</p>
  
  <pre><code>function onDeviceReady(user, serviceURL, pass) {
  if(navigator.network.connection.type == Connection.NONE)
  {
    var db = window.openDatabase(
                         'test',
                         '1.0.0',
                          'Test Database',
                          64 * 1024
                          );
  
        db.transaction(function (tx) {
        tx.executeSql('SELECT * FROM USERS', [], function (tx, results) {
        var len = results.rows.length, i;
        msg = "&lt;p&gt;Found rows: " + len + "&lt;/p&gt;";
                                   }
                                   alert(msg);
                                   for (i = 0; i &lt; len; i++){
                                   alert(results.rows.item(i).user );
                                   }
                                   }, null);
                     });
      }
  else
  {
      alert("Internet is available!!");
  
  
  $.getJSON(serviceURL + 'APIjson.php?user='+user+'&amp;pass='+pass+'&amp;action=login',    function(data)
                {
                if(data.error==-1)
                {
                alert("Invalid user id or password.");
                return false;
                }
                else {
                //navigator.notification.activityStop(); // for android only
                // ActivityIndicator.hide(); // for IOS
  
                window.localStorage["user_id"] = data.id;
  
                var db = window.openDatabase(
                                             'test',
                                             '1.0.0',
                                             'Test Database',
                                             64 * 1024
                                             );
  
                db.transaction(function populateDB(tx) {
  
                tx.executeSql('DROP TABLE IF EXISTS USERS');
                tx.executeSql('CREATE TABLE IF NOT EXISTS USERS (id unique, user, pass)');
                var sql = 'INSERT INTO USERS (id, user, pass) VALUES (?, ?, ?)';
                tx.executeSql(sql,[data.id, user, pass]);
                },function errorCB(tx, err) {
                alert("Error processing SQL: "+err);                                 
                               },function successCB() {
                               alert("success!");                                 
                               });
                window.location.href = "contact.html";
                return true;
                }
                })
  }
  }
  </code></pre>
  
  <p>I also tried to add when database retrieve on len that howmany rows came and it should alert, but it failed and my app stop to work                  </p>
  
  <pre><code>   if (!len &gt; 0) {
        alert("Sorry you need to connect internet for first time use");
                                   return false;
  </code></pre>