我正在尝试从contracts db中选择所有内容,并将HTML5文本框的名字与db条目进行比较以提醒重复。我的第一个目标是将查询结果保存到 sql2 变量中。(我不能这样做,请帮助!)。
db = window.openDatabase("contactDB", "1.0", "Contact Database", 1000000); //name,version,display name, size
addButton.addEventListener(
"click",
function(){
db.transaction(
//function sql statements
function (tx){
ensureTableExists(tx);
var firstName = firstNameBox.value;
var lastName = lastNameBox.value;
var sql = 'INSERT INTO Contacts (firstName, lastName) VALUES ("'+firstName+'","'+lastName+'")';
tx.executeSql(sql);
// Attempting to check for duplicates
var sql2 = 'SELECT * FROM Contacts', WHERE firstName = "'+firstname+'";
tx.executeSql(sql2);
alert(sql2);
},
//error callback
function (err) { alert("error callback "+err.code); },
//success callback
function (err) { //alert("success callback "+err.code);
loadFromDB();
}) // db.trasaction
} // click handler
);