gpt4 book ai didi

sql - Phonegap 数据库错误

转载 作者:行者123 更新时间:2023-12-04 20:25:05 25 4
gpt4 key购买 nike

我正在尝试为我的手机间隙应用程序设置一个数据库。问题是除了设置表的交易之外的所有交易都会产生错误提示

“SQLTransactionCallback 为空或抛出异常”

这是代码

function Datasetup()
{
db=window.openDatabase("PracticeData","1.0","saveData",300000);
alert("1");
db.transaction(getDB,onDBError,onDBSuccess);
}
function onDBError(error)
{
alert("Database Error"+error.message);
}

function onDBSuccess(tx,results)
{
alert("successfull");
}

function getDB(tx)
{
alert("2");
tx.executeSql("CREATE TABLE IF NOT EXISTS session(date,length,activity,pieces)");
alert("3");
tx.executeSql("CREATE TABLE IF NOT EXISTS pieces(newpiece,name,composer,youtube,images_src,date_Added)");
alert("4");
tx.executeSql('SELECT * FROM session', [], onSelectSessionSuccess, onDBError());
tx.executeSql("SELECT * FROM session",[],onSelectSessionSuccess,onDBError());
alert("5");
tx.executeSql("SELECT * FROM pieces",[],onSelectPiecesSuccess,onDBError());
}

function savepiece(tx)
{
tx.executeSql("INSERT INTO NOTES(newpiece,name,composer,youtube,images_src,date_Added)VALUES(?,?,?,?,?,?)",[true,pieceData.name,pieceData.composer,"tube","images",date()]);
}

我没有得到这个或创建表的错误信息

       db.transaction(getDB,onDBError,onDBSuccess)

我收到错误信息

        tx.executeSql('SELECT * FROM session', [], onSelectSessionSuccess, onDBError());

tx.executeSql("SELECT * FROM session",[],onSelectSessionSuccess,onDBError());
alert("5");
tx.executeSql("SELECT * FROM pieces",[],onSelectPiecesSuccess,onDBError());

这是一个很大的帮助,现在我的一个选择工作另一个然而想出了

“语句回调引发异常或语句错误回调未返回false”

这是不起作用的sql

     tx.executeSql('SELECT * FROM session', [],onSelectPiecesSuccess, onDBError);

这是更新后的代码

    function Datasetup(){

db=window.openDatabase("PracticeData","1.0","PracticeData",300000);
db.transaction(getDB,onDBError,onDBSuccess);
}

function onDBError(error){
alert("Database Error "+error.message);
}
function onDBSuccess(tx,results){
//db.transaction(query,onDBError);
db.transaction(query,onDBError);
alert("before");

}


function getDB(tx){
//alert("dropping")
//tx.executeSql("DROP TABLE pieces");

tx.executeSql("CREATE TABLE IF NOT EXISTS session(date,length,activity,pieces)");
tx.executeSql("CREATE TABLE IF NOT EXISTS pieces(newpiece,name,composer,youtube,images_src,date_added)");
//tx.executeSql('INSERT INTO session(date, length, activity,pieces) VALUES ("10-2-12", "15","2","11")');
//tx.executeSql('INSERT INTO session (date, length, activity,pieces) VALUES ("11-2-12", "15","2","11")');
//tx.executeSql('INSERT INTO session (date, length, activity,pieces) VALUES ("12-2-12", "15","2","11")');*/
tx.executeSql('INSERT INTO session (date, length, activity,pieces) VALUES ("13-2-12", "15","2","violin")');
tx.executeSql('INSERT INTO pieces (newpiece, name, youtube,images_src,date_Added) VALUES ("true", "15","tube","11",13-9-13)');
//tx.executeSql("DROP TABLE pieces");
//tx.executeSql("DROP TABLE session");
//alert("vi");
}
/**sessions**/
function query(tx){
tx.executeSql('SELECT * FROM session', [], onSelectSessionSuccess, onDBError);
}
function onSelectSessionSuccess(tx,results){
dbResult = results;
var len= results.rows.length;
var sessionList="";

for(var i=0;i<len;i++)
{
sessionList = sessionList+"<li>"+results.rows.item(i).date+"</li>"
}
alert(sessionList);
//tx.executeSql("SELECT * FROM pieces",[],onSelectPiecesSuccess,onDBError());
db.transaction(piecesquery,onDBError);
}

/**pieces**/
function piecesquery(tx){
//alert("piecesquery");
tx.executeSql('SELECT * FROM session', [],onSelectPiecesSuccess, onDBError);
}
function onSelectPiecesSuccess(tx,results){
var len= results.rows.length;
var PiecesList="";
var newPiecesList="";
var res;
alert(len);
for(var i=0;i<len;i++)
{
newPiecesList=newPiecesList+"<li>"+results.rows.item(i).newpiece + results.rows.item(i).composer +"</li>"
}
alert(newPiecesList);
$('#newPiecesList').innerHTML(newPiecesList);

}

我的流程: 创建表并填充 getDB。getDb成功拉取session数据。片段数据在 session 页面启动时被拉取。但是我可以用从 session 表中提取的代码替换提取 pieces 表的代码,没有任何问题。由于某种原因,似乎无法访问进入 pieces 表的数据

最佳答案

我已经完成了建表、插入和选择过程,希望对你有用。

var db=null;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {

db = window.openDatabase("TestDatabase","1.0","TestingDatabase",'200000000');

alert("db1");
db.transaction(populateDatabase,errorDb,successDb);


}
function populateDatabase(tx){

tx.executeSql('DROP TABLE IF EXISTS TestTable');
tx.executeSql('CREATE TABLE IF NOT EXISTS TestTable(RollNo INT PRIMARY KEY,FirstName text,LastName text,MobileNo text)');

tx.executeSql('INSERT INTO TESTTABLE (RollNo, FirstName, LastName, MobileNo) VALUES (1, "Nisari", "Balakrishnan", "8891924207")');
tx.executeSql('INSERT INTO TESTTABLE (RollNo, FirstName, LastName, MobileNo) VALUES (2, "Mikhil", "Anandan", "9605432101")');

}
function queryDB(tx) {
tx.executeSql('SELECT * FROM TESTTABLE', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
var len = results.rows.length;
alert(len);
console.log("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
//console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
alert("Row = " + i + " ID = " + results.rows.item(i).RollNo + " FirstName = " + results.rows.item(i).FirstName + " LastName = " + results.rows.item(i).LastName + " MobileNo = " + results.rows.item(i).MobileNo);

// db = window.openDatabase("TestDatabase","1.0","TestingDatabase",'200000000');
// db.transaction(updateDB, errorCB);
// console.log("After Open DB");


}
}
function errorCB(err) {
console.log("Error processing SQL: "+err.code);
}



function errorDb()
{
alert("Error on Database creation:" + Error);
}
function successDb()
{
alert("Database is created successfully");
db = window.openDatabase("TestDatabase","1.0","TestingDatabase",'200000000');
db.transaction(queryDB, errorCB);
}

关于sql - Phonegap 数据库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18762574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com