如何在PhoneGap App中实现数据库?

时间:2022-09-02 11:12:16

I'm new to this, and I am trying to build an app to be deployed with PhoneGap, to both Android and iOS. I am wondering how to link to a database which will store timetable data.

我是新手,我正在尝试构建一个与PhoneGap一起部署到Android和iOS的应用程序。我想知道如何链接到一个存储时间表数据的数据库。

My question is how to include the database so it can be packaged with PhoneGap.

我的问题是如何包含数据库,以便它可以与PhoneGap打包。

I have looked at the PhoneGap docs, and they don't really make sense to me as to how to set up/create the database

我看了一下PhoneGap文档,对于我如何设置/创建数据库他们真的没有意义


Update: This website shows some info on local storage, but when i put it in, hangs on the loading image.

更新:此网站显示有关本地存储的一些信息,但是当我把它放入时,挂在加载图像上。

Any further ideas?

还有什么想法?

http://www.aquim.com/web-article-237.html

http://www.aquim.com/web-article-237.html

3 个解决方案

#1


14  

Please refer below link for simple operation with Sq-lite.and also you can get basic idea of Storage API from above link.

请参考以下链接,了解Sq-lite的简单操作。您还可以从上面的链接获得Storage API的基本概念。

Simple operation with Sq-lite : http://www.raymondcamden.com/index.cfm/2011/10/20/Example-of-PhoneGaps-Database-Support

使用Sq-lite进行简单操作:http://www.raymondcamden.com/index.cfm/2011/10/20/Example-of-PhoneGaps-Database-Support

Edited on 8th MAY 2013 and fixed 19th January 2016

于2013年5月8日编辑并于2016年1月19日修订

Basic operation with DB :

DB的基本操作:

<script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
function onDeviceReady() {
    var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
    db.transaction(populateDB, errorCB, successCB);
}

// Populate the database 
function populateDB(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")');
}

// Transaction error callback
function errorCB(err) {
    alert("Error processing SQL: " + err);
}

// Transaction success callback
function successCB() {
    alert("success!");
}
</script>

refrence

refrence

You can check Data base in File explorer

您可以在File explorer中检查数据库

In ADT bundle Window>>show view>> File Explorer

在ADT包窗口>>显示视图>>文件资源管理器中

#2


1  

PhoneGap has a storage api that you should use instead of using HTML5 local storage directly. On both Android and iOS, it will use the native implementation.

PhoneGap有一个存储API,你应该使用它而不是直接使用HTML5本地存储。在Android和iOS上,它将使用本机实现。

see http://docs.phonegap.com/en/2.7.0/cordova_storage_storage.md.html#Storage

见http://docs.phonegap.com/en/2.7.0/cordova_storage_storage.md.html#Storage

#3


0  

Careful because maxSize of database in Android Gingerbread 2.3.3 emulator must be 65535.

小心,因为Android Gingerbread 2.3.3模拟器中的数据库的maxSize必须是65535。

With this OS 200000 maxSize it could give an error.

使用此OS 200000 maxSize可能会出错。

200000 maxSize works for newer OS.

200000 maxSize适用于较新的操作系统。

#1


14  

Please refer below link for simple operation with Sq-lite.and also you can get basic idea of Storage API from above link.

请参考以下链接,了解Sq-lite的简单操作。您还可以从上面的链接获得Storage API的基本概念。

Simple operation with Sq-lite : http://www.raymondcamden.com/index.cfm/2011/10/20/Example-of-PhoneGaps-Database-Support

使用Sq-lite进行简单操作:http://www.raymondcamden.com/index.cfm/2011/10/20/Example-of-PhoneGaps-Database-Support

Edited on 8th MAY 2013 and fixed 19th January 2016

于2013年5月8日编辑并于2016年1月19日修订

Basic operation with DB :

DB的基本操作:

<script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
function onDeviceReady() {
    var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
    db.transaction(populateDB, errorCB, successCB);
}

// Populate the database 
function populateDB(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")');
}

// Transaction error callback
function errorCB(err) {
    alert("Error processing SQL: " + err);
}

// Transaction success callback
function successCB() {
    alert("success!");
}
</script>

refrence

refrence

You can check Data base in File explorer

您可以在File explorer中检查数据库

In ADT bundle Window>>show view>> File Explorer

在ADT包窗口>>显示视图>>文件资源管理器中

#2


1  

PhoneGap has a storage api that you should use instead of using HTML5 local storage directly. On both Android and iOS, it will use the native implementation.

PhoneGap有一个存储API,你应该使用它而不是直接使用HTML5本地存储。在Android和iOS上,它将使用本机实现。

see http://docs.phonegap.com/en/2.7.0/cordova_storage_storage.md.html#Storage

见http://docs.phonegap.com/en/2.7.0/cordova_storage_storage.md.html#Storage

#3


0  

Careful because maxSize of database in Android Gingerbread 2.3.3 emulator must be 65535.

小心,因为Android Gingerbread 2.3.3模拟器中的数据库的maxSize必须是65535。

With this OS 200000 maxSize it could give an error.

使用此OS 200000 maxSize可能会出错。

200000 maxSize works for newer OS.

200000 maxSize适用于较新的操作系统。