0

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

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

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 过滤时,我得到了 undefined

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));
        }
    });         
})

有人能帮我吗?

谢谢

4

1 回答 1

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));
          }
       });         
})
于 2014-03-08T09:33:36.463 回答