gpt4 book ai didi

sqlite - 将 SQLite 与 Phonegap 桌面结合使用

转载 作者:行者123 更新时间:2023-12-03 17:57:07 25 4
gpt4 key购买 nike

我在 phonegap 中打开一个 SQLite 数据库。
这是我的 javascript 代码:

      var myDB = null;

function onDeviceReady()
{

myDB = window.openDatabase("test", "1.0", "Test DB", 1000000);
//myDB = window.sqlitePlugin.openDatabase({name: 'test.db', location: 'default'});


alert("yal");


myDB.transaction(PopulateDatabase,errorDB,successDB);
myDB.transaction(queryDB, errorCB, querySuccess);

}

function PopulateDatabase(tx)
{
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}

function errorDB(error)
{
alert("Error on Database creation : " + error);
}

function successDB()
{
alert("Database is created successfully");
}

function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}

function querySuccess(tx, results) {
var len = results.rows.length;
alert("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
alert("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
}
alert("success");
}

function errorCB(err) {
alert("Error processing SQL: "+err.code);
}

这是工作,我可以从我的数据库中获取数据。
我的问题是我无法在我的计算机上找到我的数据库。
有人可以告诉我在哪里可以找到它吗?

我试过这个,但它对我不起作用。
myDB = window.sqlitePlugin.openDatabase({name: 'test.db', location: 'default'});

我正在使用 cordova-sqlite-storage 插件。

这是我的项目的 config.xml 文件:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.helloworld" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>yal</name>
<description>
A blank PhoneGap app.
</description>
<author email="support@phonegap.com" href="http://phonegap.com">
PhoneGap Team
</author>
<content src="index.html" />
<access origin="*" />
<plugin name="cordova-sqlite-ext" spec="~0.10.2" />

最佳答案

使用 window.openDatabase 存储数据库的位置

使用 window.openDatabase 时,您使用“Web SQL”。此功能由浏览器直接提供。数据的存储位置取决于您使用的浏览器。默认情况下,Web SQL 中可用的存储空间是有限的。根据您使用的浏览器,您可以增加允许的存储空间量。

例如,在 Chrome 中,您可以通过开发人员工具访问数据库:

enter image description here

将 SQLite 与 Phonegap 桌面结合使用

使用 SQLite 不适用于您当前使用的设置。在普通浏览器中打开 Phonegap Desktop 提供的应用程序时,您无权访问本地计算机/设备。为了使用需要访问设备的插件,您必须在移动设备上的“Phonegap Developer App”中打开Phonegap Desktop提供的应用程序。

this doc page获取说明。

关于sqlite - 将 SQLite 与 Phonegap 桌面结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40960339/

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