How to open an existing WebSQL database?

爱⌒轻易说出口 提交于 2019-12-31 02:49:17

问题


I'm building an HTML5/Phonegap mobile application and I want to use an existing SQLite database through WebSQL. By an "existing" database I mean I had already created the db.sqlite file outside of the app. I did this because there are several tables and it is pre-populated with some data. What I wanna do is copy this db file into my project and be able to open it with Javascript just like this:

var db = openDatabase('mydb', '1.0', 'my first database', 2 * 1024 * 1024);

It seems like this command only creates a new db or opens an existing db that was created with this command. If it's possible to open a DB that was created outside my app, how can I open it? How can I set the db path, filename, etc?

Thanks for any help.


回答1:


WebSQl has that gotcha. Open database without version and then do version migration, eg:

var db = openDatabase('mydb', '', 'my first database', 2 * 1024 * 1024);

if (db.version != '1.0) {
   ...
}


来源:https://stackoverflow.com/questions/10626918/how-to-open-an-existing-websql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!