Reputation: 2311
can any one help me how can i retrieve value from db? my code is
<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>
here table is created and 10 rows are inserted. But I am not able to retrieve and display the values.
<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()
});
});
}
Any suggestions...
Upvotes: 2
Views: 1405
Reputation: 5178
Take a look at documentation
https://github.com/brodysoft/Cordova-SQLitePlugin
Short rewrite from it:
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);
}
});
Upvotes: 2