这里是我用来在基于phonegap 2.9.0的应用程序中存储和初始化数据库的代码
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
function populateDB(tx)
{
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
function successCB()
{
alert("Sucesss")
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(queryDB, errorCBs);
}
function queryDB(tx)
{
tx.executeSql('SELECT * FROM DEMO', [],errorCB, querySuccess);
}
function querySuccess(tx, results)
{
alert("Insert ID = ",results.insertId);
alert("Rows Affected = ",results.rowAffected);
alert("Insert ID = ",results.rows.length);
}
function errorCBs(err)
{
alert("2nd error ",err.code);
}
function errorCB(err)
{
alert("Error processing SQL: ",err.code);
}
当应用程序调用
时 db.transaction(populateDB, errorCB, successCB);
它首先显示successCB的警告,然后显示警告errorCB。我的code.please有什么问题帮我解决
答案 0 :(得分:0)
您不需要两次打开数据库。
取出部分:
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
来自successCB
函数。