在 Cordova 中打开预填充的 SQLite 数据库(对于 android)和 Visual Studio
Open prepopulated SQLite database in Cordova (for android) and Visual Studio
我正在使用 Visual Studio 2013 和 Cordova 工具包。
我的大部分应用程序都在运行,现在我已准备好添加数据库逻辑。我有一个充满引号的数据库,我需要将其绑定到应用程序中。
关注此 link:adding dynamic data with SQLite
我能够让 SQLite 与数据库对话 (using the sqlitePlugin) 但是,我不知道如何使用预填充的数据库。它总是创建一个新的空数据库。我在网上发现几篇文章一直在说 "put the db in the www folder"...但是 Cordova 项目没有 www 文件夹。
将 SQLite DB 文件放在根目录中不起作用,我尝试使用路径并将其放在子目录中。也不走运。
有人能做到吗?
老问题,我回答一下作为参考:我是通过换插件解决这个问题的。以前,我使用的是插件 cordova-sqlite-storage
(https://github.com/litehelpers/Cordova-sqlite-storage),但它不会复制预填充的数据库。它总是创建一个空的。
经过几天的折腾,我卸载了插件并安装了这个:cordova-plugin-sqlite
(https://www.npmjs.com/package/cordova-plugin-sqlite)。这个很有用,它将 www 文件夹中的数据库复制到设备。只需按照说明进行操作,不要忘记 createFromLocation
参数。
奇怪的是,这两个插件都来自同一作者,而且似乎都是活跃的项目。去图吧。
Old question, but I will answer to serve as a reference (2)!
cordova-sqlite-ext 项目支持预填充的 SQLite。
步骤简单:
- 将数据库文件放在www目录下,打开数据库如:www/sample.db
然后,使用:
var db = window.sqlitePlugin.openDatabase({name: "sample.db", createFromLocation: 1});
更多信息:https://github.com/litehelpers/cordova-sqlite-ext#pre-populated-databases
许多站点和答案都指向为此使用 Cordova-sqlite-storage。事实上,这个功能在这个项目中,但它被移动到 Cordova-sqlite-ext(它们来自同一个创建者)。
我不推荐使用 cordova-plugin-sqlite。它已被弃用。
我正在使用 Visual Studio 2013 和 Cordova 工具包。
我的大部分应用程序都在运行,现在我已准备好添加数据库逻辑。我有一个充满引号的数据库,我需要将其绑定到应用程序中。
关注此 link:adding dynamic data with SQLite
我能够让 SQLite 与数据库对话 (using the sqlitePlugin) 但是,我不知道如何使用预填充的数据库。它总是创建一个新的空数据库。我在网上发现几篇文章一直在说 "put the db in the www folder"...但是 Cordova 项目没有 www 文件夹。
将 SQLite DB 文件放在根目录中不起作用,我尝试使用路径并将其放在子目录中。也不走运。
有人能做到吗?
老问题,我回答一下作为参考:我是通过换插件解决这个问题的。以前,我使用的是插件 cordova-sqlite-storage
(https://github.com/litehelpers/Cordova-sqlite-storage),但它不会复制预填充的数据库。它总是创建一个空的。
经过几天的折腾,我卸载了插件并安装了这个:cordova-plugin-sqlite
(https://www.npmjs.com/package/cordova-plugin-sqlite)。这个很有用,它将 www 文件夹中的数据库复制到设备。只需按照说明进行操作,不要忘记 createFromLocation
参数。
奇怪的是,这两个插件都来自同一作者,而且似乎都是活跃的项目。去图吧。
Old question, but I will answer to serve as a reference (2)!
cordova-sqlite-ext 项目支持预填充的 SQLite。
步骤简单:
- 将数据库文件放在www目录下,打开数据库如:www/sample.db
然后,使用:
var db = window.sqlitePlugin.openDatabase({name: "sample.db", createFromLocation: 1});
更多信息:https://github.com/litehelpers/cordova-sqlite-ext#pre-populated-databases
许多站点和答案都指向为此使用 Cordova-sqlite-storage。事实上,这个功能在这个项目中,但它被移动到 Cordova-sqlite-ext(它们来自同一个创建者)。
我不推荐使用 cordova-plugin-sqlite。它已被弃用。