我这里有个小问题。我尝试从数据库表中获取最后一个 id,但它给了我一个错误
the statement callback raised an exception or statement error callback did not return false
代码在这里:
function onDeviceReady(){
var db=window.openDatabase("test", "1.0", "Test", 2000000);
db.transaction(creare_baza, eroaredb, succesdb);
//alert("intrat");
}
function creare_baza(tx){
tx.executeSql('DROP TABLE IF EXISTS demo');
tx.executeSql("CREATE TABLE IF NOT EXISTS demo (id unique, info)");
var ult_id=0;
tx.executeSql("SELECT * FROM demo", [], ult_id=function(tx, rez){
return rez.insertId;
}, eroaredb);
tx.executeSql("INSERT INTO demo(id, info) VALUES("+(parseInt(ult_id)+1)+", 'ceva')");
}
function cere(tx){
tx.executeSql("SELECT * FROM demo", [], onsucces, eroaredb);
}
function onsucces(tx, rezultate){
var html="Numar de randuri = "+rezultate.rows.length;
for(var i=0;i<rezultate.rows.length;i++){
html=html+"Randul "+i+" cu id="+rezultate.rows.item(i).id+" si info="+rezultate.rows.item(i).info;
}
alert(html);
}
function eroaredb(err) {
alert("Eroare la procesare: "+err.message);
}
function succesdb() {
var db=window.openDatabase("test", "1.0", "Test", 2000000);
db.transaction(cere, eroaredb);
}
另一个问题是如何向插入新行的函数发送新参数?喜欢:
function new_row(tx, id, data){
tx.executeSql("INSERT INTO demo (id, info) VALUES("+id+", '"+data+"')");
}