我正在尝试查询包含车辆列表的phonegap SQL数据库。如果我将车辆登记表格加载到存储变量并运行查询,如下所示,我没有返回任何行,但我确信记录存在!如果我硬编码与var veh =“ABC 123”相同的注册并对此运行查询,我会返回一行。我无法理解为什么字符串看起来相同!谁能告诉我我的错误在哪里?
function getVehicleClass() {
var db = window.openDatabase("Database", "1.0", "Vehicles List", 200000);
db.transaction(QueryDB);
}
function QueryDB(tx) {
var veh = localStorage.getItem('_reg');
console.log(veh);
tx.executeSql('SELECT * FROM Vehicles where Registration="' + veh + '"' , [], successCB, errorCB);
}
function errorCB(err) {
alert("Error processing SQL: "+err);
}
function successCB(tx, results) {
var len = results.rows.length;
console.log("Vehicle query: " + 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).Registration + " " + results.rows.item(i).class);
}
}