我正在尝试为我的电话间隙应用程序设置一个数据库。问题是除了设置表的事务之外的所有事务都会产生错误说
“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 成功时被拉取。会话页面启动时会拉取碎片数据。但是我可以用从会话表中提取的代码替换代码以拉出片段表,而不会出现任何问题。由于某种原因,似乎无法访问进入pieces 表的数据