1

我正在尝试查询包含车辆列表的 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);
    }
}
4

0 回答 0