2014-03-27 59 views
2

任何人都可以幫助我如何從數據庫檢索值?我的代碼是問題與選擇查詢在sqlite IOS手機差距?

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

任何建議...

回答

2

看看文檔

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

將嘗試,但我使用SQLite插件不存儲的PhoneGap – Vinod

+0

@ user3300593我誤解了你的問題,是的,但SQLite插件的語法保持不變。我將鏈接更改爲正確的文檔 – Regent