gpt4 book ai didi

javascript - sqlite ios 电话差距中的选择查询问题?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:43 25 4
gpt4 key购买 nike

任何人都可以帮助我如何从数据库中检索值?我的代码是

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

任何建议...

最佳答案

查看文档

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

关于javascript - sqlite ios 电话差距中的选择查询问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22694546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com