如何打开现有的WebSQL数据库? [英] How to open an existing WebSQL database?

查看:325
本文介绍了如何打开现有的WebSQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个HTML5 / Phonegap移动应用程序,我想通过WebSQL使用现有的SQLite数据库。
通过现有数据库,我的意思是我已经在应用程序之外创建了db.sqlite文件。我这样做是因为有几个表,并预先填充了一些数据。
我想做的是将这个db文件复制到我的项目中,并且能够使用Javascript打开它,如下所示:

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?

感谢您的帮助。

推荐答案

WebSQl有这个问题。打开没有版本的数据库然后进行版本迁移,例如:

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) {
   ...
}

这篇关于如何打开现有的WebSQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆