JSFiddle - React, Tailwind, and code Playground
by Alexander
JavaScript
console.clear();
var db = openDatabase('mydb', '1.0', 'my first database', 2 * 1024 * 1024); // 2Mb
db.transaction(function(tx) {
//tx.executeSql('DROp TABLE foo');
tx.executeSql(
"SELECT COUNT(*) FROM foo",
[],
null,
function (tx, error) {
tx.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text, field_3, field_4)');
for (var i=1;i<30;i++){
//tx.executeSql('INSERT INTO foo (id, text) VALUES ('+i+', "Some data #' +i+ '")');
tx.executeSql('INSERT INTO foo (id, text, field_3) VALUES (?, ?, ?)', [ i, new Date().toString(), Math.random() ]);
}
}
);
});
db.transaction(function(tx) {
tx.executeSql(
"SELECT * FROM foo", [],
function(tx, result) {
var row;
for(var i = 0; i < result.rows.length; i++) {
row = result.rows.item(i);
console.log( row );
}
},
function(){
console.log(arguments);
}
)
});
if (0){
db.changeVersion('', '1.0',
function (t) {
tx.executeSql('INSERT INTO foo (id, text) VALUES (?, ?)', [ i, new Date().toString() ]);
},
function(){
console.log(arguments);
}
);
}