【问题标题】:Issue with select query in sqlite ios phone gap?sqlite ios电话间隙中的选择查询问题?
【发布时间】:2014-05-06 20:03:12
【问题描述】:

谁能帮助我如何从数据库中检索价值?我的代码是

<script type="text/javascript" charset="utf-8">  
       // Wait for Cordova to load  
       document.addEventListener("deviceready", onDeviceReady, false);  
       // Cordova is ready  
       function onDeviceReady() {  
         console.log("Run1");  
         var db = window.sqlitePlugin.openDatabase({name: "MYDB"});  
         db.transaction(function (tx) {  
                 tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');  
         });  
         db.transaction(function (tx){  
                 for (var index = 1; index < 10; index++){  
                   tx.executeSql('INSERT INTO LOGS (id,log) VALUES ('+index+', '+index+')');  
                 }  
         });  
       }  
     </script>

此处创建表并插入 10 行。但我无法检索和显示这些值。

    <input id="DBlist" type="submit" onClick='showList()' data-theme="b" value="Saved values"  data-mini="false">

 function showList()
    {
 var db = window.sqlitePlugin.openDatabase({name: "MYDB2"});
  db.transaction(function(tx) {
  tx.executeSql("select * from LOGS;", [], function(tx, res) {
  // how can I display all the rows in console.log()
   });
   });
  }

任何建议...

【问题讨论】:

    标签: javascript ios sqlite cordova


    【解决方案1】:

    查看文档

    https://github.com/brodysoft/Cordova-SQLitePlugin
    

    对其进行简短的重写:

    function(tx, res) {
        for (var i = 0; i < res.rows.length; i++) {
            console.log("Row = " + i + ", id = " + res.rows.item(i).id + ", log =  " +
                    res.rows.item(i).log);
        }
    });
    

    【讨论】:

    • 会尝试,但我使用的是 sqlite 插件而不是 phonegap 存储
    • @user3300593 我误读了您的问题,是的,但是 SQLite 插件的语法保持不变。我将链接更改为正确的文档
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多