can't seem figure out why works in safari not in chrome. appreciated.
//create or use existing db var db = opendatabase('mytest', '1.0', 'myspecialdatabase', 200000); if (db) { //new transaction db.transaction(function (tx) { tx.executesql('drop table if exists foo'); tx.executesql('create table if not exists foo (id unique, text)'); //insert test data tx.executesql('insert foo (id, text) values (1, "mytest")'); tx.executesql('insert foo (id, text) values (2, "another")'); tx.executesql('insert foo (id, text) values (3, "andyetanother")'); tx.executesql('insert foo (id, text) values (4, "ohandagain")'); }); alert("db success"); } else { alert("oooops"); } db.transaction(function (tx) { // loop rows of db, print values tx.executesql('select * foo',[], function (tx, results) { var rows = results.rows; alert(rows.length); (var index = 0; index < rows.length; index++) { var x = rows.item(index); alert(x.text); } }); });
throw in jsfiddle in either browser, works intended in latest release of safari no such luck in chrome.
edit
i managed working in end - code can seen below.
var db = opendatabase('cbdb', '1.0', 'myspecialdatabasethatwontwork',10*1024*1024); db.transaction(function (tx){ tx.executesql('drop table if exists cb'); alert("dropped table"); createdb(); querydb(); }, function (tx, error) { // error alert('0.something went wrong: '+ error.message); }); function createdb(){ db.transaction(function (tx) { tx.executesql('create table if not exists cb (id unique, text)'); tx.executesql('insert cb (id, text) values (1, "mytest")'); tx.executesql('insert cb (id, text) values (2, "another")'); tx.executesql('insert cb (id, text) values (3, "andyetanother")'); tx.executesql('insert cb (id, text) values (4, "ohandagain")'); alert("db success"); }, function (tx, error) { // error alert('1.something went wrong: '+ error.message); }); } function querydb(){ db.transaction(function (tx) { tx.executesql('select * cb',[], function (tx, results) { var rows = results.rows; alert(rows.length); (var index = 0; index < rows.length; index++) { var x = rows.item(index); alert(x.text); } }, function (tx, error) { // error alert('2.something went wrong: '+ error.message); }); }); }
updated code slightly, , works..
var db = opendatabase('cbdb', '1.0', 'myspecialdatabasethatwontwork',10*1024*1024); db.transaction(function (tx){ tx.executesql('drop table if exists cb'); alert("dropped table"); createdb(); querydb(); }, function (tx, error) { // error alert('0.something went wrong: '+ error.message); }); function createdb(){ db.transaction(function (tx) { tx.executesql('create table if not exists cb (id unique, text)'); tx.executesql('insert cb (id, text) values (1, "mytest")'); tx.executesql('insert cb (id, text) values (2, "another")'); tx.executesql('insert cb (id, text) values (3, "andyetanother")'); tx.executesql('insert cb (id, text) values (4, "ohandagain")'); alert("db success"); }, function (tx, error) { // error alert('1.something went wrong: '+ error.message); }); } function querydb(){ db.transaction(function (tx) { tx.executesql('select * cb',[], function (tx, results) { var rows = results.rows; alert(rows.length); (var index = 0; index < rows.length; index++) { var x = rows.item(index); alert(x.text); } }, function (tx, error) { // error alert('2.something went wrong: '+ error.message); }); }); }
Comments
Post a Comment