问题描述
我如何从SD卡装入现有的.db文件或使用PhoneGap的或任何插件,将与PhoneGap的SD卡中创建数据库?
我要救我的.db文件的SD卡,因为数据库的大小可能会增加。
我面临着同样的问题,而是长期深入阅读过的PhoneGap,科尔多瓦库后,我找到了自己的不足,提供了灵活的选择路径。
原因可能是因为跨平台的限制,图书馆必然您使用默认的应用程序路径,这样不同的平台上,图书馆可以很容易地获取文件。
但什么!还有一招,以达到目标......
函数onDeviceReady(){
变种DB = window.openDatabase(测试,1.0,测试数据库,1000000);
}
其实时的JavaScript调用的openDatabase()函数,它做以下的事情
- 添加/数据/数据/< package_name_of_your_app> / DB_NAME之前
- 添加。DB DB_NAME后
即:在上述情况下得到的将是;
这样的伎俩放在这里;
函数onDeviceReady(){
变种DB = window.openDatabase(../../../../ MNT / SD卡/考,1.0,测试数据库,1000000);
}
- DB_NAME前添加../../../../mnt/sdcard/,不要因为库添加添加扩展名名.db本身,如果你添加任何扩展,则你的数据库文件将被 DB_NAME。(yourextension).db的
现在该怎么办!它会;
- 添加/数据/数据/< package_name_of_your_app> / DB_NAME之前
- 添加。DB DB_NAME后
- 它将把你的DB_NAME'../../../../ MNT / SD卡/测试
因此,得到的将是;
那么,它会返回到根您的手机,然后到/ mnt / SD卡
How can I load existing .db file from sdcard or create database in sdcard using phoneGap or any plugin that will work with phoneGap?
I want to save my .db file in sdcard because size of database might increase.
Same problem I am facing, but after a long thorough reading over phonegap-cordova library, I found its lacking to provide the flexibility for selecting path.
Reason may be because of cross platform limitation, library bound you to use the default app path so on different platform, library could get the file easily.
but what!! there is a trick to achieve the target ....
function onDeviceReady() {
var db = window.openDatabase("test", "1.0", "Test DB", 1000000);
}
actually when JavaScript call the 'openDatabase()' function, its do following things
- add '/data/data/< package_name_of_your_app>/' before db_name
- and add '.db' after db_name
i.e : in above case resultant will be;
so the trick goes here;
function onDeviceReady() {
var db = window.openDatabase("../../../../mnt/sdcard/test", "1.0", "Test DB", 1000000);
}
- add '../../../../mnt/sdcard/' before db_name, don't add extension since library add '.db' itself, if you add any extension then your db file will be db_name.(yourextension).db
now what! it will;
- add '/data/data/< package_name_of_your_app>/' before db_name
- and add '.db' after db_name
- it will take your db_name '../../../../mnt/sdcard/test'
therefore, resultant will be;
so, it will back to root of your mobile and then /mnt/sdcard
这篇关于是否有可能加载/在Android中使用PhoneGap的SD卡创建的数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!