Database statement is not working in google chrome

76 views Asked by At

I am running chrome 43.0. In console i am running below command:

  >>  var db1 = openDatabase('testDB', '', 'my first database', 2 * 1024 * 1024, function(d){console.log(d);});

  >>  undefined

  >>  db1.transaction(function (tx) { 
      console.log("....................."); 
      console.log(tx.executeSql("INSERT INTO fileLog (fileName, bucketName) VALUES ('123','synergies')"));
    });

  >>  undefined
     .....................
      undefined

The problem is its not inserting any data in fileLog table.

1

There are 1 answers

0
nik On

You have to create the table fileLog before you insert the values into it as follows :

db1.transaction(function (tx) { 
tx.executeSql('CREATE TABLE IF NOT EXISTS fileLog (fileName,bucketName )');    });

And you can select values from it as

db1.transaction(function (tx) { 
      tx.executeSql('SELECT * FROM fileLog ', [], function (tx, results) {
     for (var i = 0; i < results.rows.length; i++){
         console.log(results.rows.item(i).fileName," ",results.rows.item(i).bucketName);
      }

   }, null);
    });