在phonegap android中使用预填充的sqlite数据库
我有一个 sqlite 数据库 test_db.db,我保存在 www 文件夹中,我使用cordova cli 在本地机器上构建android 应用程序.
I have an sqlite database test_db.db i have kept in the www folder i am using cordova cli to build android app on my local machine.
当我尝试打开数据库时,它正在打开新数据库,而不是访问预填充的数据库.
when i am trying to open the database it is opening new database instead of accessing the prepopulated.
我使用以下代码对此进行了测试.
I tested this using following code.
// Open the existing database
var db = window.sqlitePlugin.openDatabase({ name : "test_db.db" });
db.transaction(function (tx) {
alert("database opened");
var _strQuery = "select * from mst_users;";
tx.executeSql(_strQuery, [], function (tx, res) {
alert("Populated Successfully with " + res.rows.length + " Records.");
}, CommonError);
}, CommonError, DoNothing);
并且每次我收到一个错误,即表 mst_users 不存在但它存在于预填充的数据库中.
And every time i am getting an error that table mst_users does not exist but it is there in the prepopulated db.
我已经尝试了各种方法来实现这一目标,但还是卡住了.我想访问预填充数据库中的数据.
I have tried various things for achieving this but yet stucked. I want access the data in the prepopulated database .
非常感谢任何帮助..
在cordova项目中打开prepopulated db,需要做3个步骤:
To open prepopulated db in cordova project, you need to do 3 steps:
将 .db 文件复制到 www 主目录
Copy .db file into main www directory
安装 this 插件并使用复制方法(这将复制 .db文件到您的操作系统/设备的指定目录)
Install this plugin and use copy method(this will copy the .db file to the specified directory for your os/device)
使用这个插件打开.db文件
Use this plugin to open the .db file
就是这样... :)