错误选择WebSQL

时间:2013-10-09 14:26:47

标签: html5 select undefined web-sql

我在尝试从我的本地websql数据库中选择时遇到问题。

我有一个名为“clientes”的表。这是我的代码:

var db = openDatabase("test", "", "", 1024*1024);
db.transaction(function (tx) {
     tx.executeSql('SELECT * FROM clientes', [], function (tx, results) {
        var len = results.rows.length;
        for (i = 0; i < len; i++) {                 
            console.log(results.rows.item(i));
        }
    });         
})

我收到了行

{
    "ClienteCiudad": "MADRID",
    "ClienteFechaDesde": 2013,
    "ClienteLegalDenominacion": null,
    "ClienteLegalNrTributario": null
}

但是当我尝试使用WHERE过滤时,我得到了未定义的

db.transaction(function (tx) {
     tx.executeSql('SELECT * FROM clientes WHERE ClienteCiudad="Madrid"', [], function (tx, results) {
        var len = results.rows.length;
        for (i = 0; i < len; i++) {                 
            console.log(results.rows.item(i));
        }
    });         
})

有人能帮助我吗?

由于

1 个答案:

答案 0 :(得分:0)

尝试以下代码

db.transaction(function (tx) {
      var searchfor = "Madrid";
      tx.executeSql('SELECT * FROM clientes WHERE ClienteCiudad=?', [searchfor], function (tx, results) {
         var len = results.rows.length;
         for (i = 0; i < len; i++) {                 
             console.log(results.rows.item(i));
          }
       });         
})