简体   繁体   English

如何在HTML5中使用现有的sqlite数据库

[英]How to use an existing sqlite database in html5

I have created an sqlite database file using sqlite browser.I have a file "sample.sqlite", now i wanted to know how to import this file in javascript and use the data in the sqlite file.I have been using this below mentioned script 我已经使用sqlite浏览器创建了一个sqlite数据库文件。我有一个文件“ sample.sqlite”,现在我想知道如何在javascript中导入该文件并使用sqlite文件中的数据。我一直在使用下面提到的脚本

var db;

try {
    if (window.openDatabase) {
        db = openDatabase("sample.sqlite", "1.0", "HTML5 Database API example", 200000);
        if (!db)
            alert("Error Failed to open the database, check version");
    } else
        alert("Error Not supported? Not gonna happen");
} catch(err) {}

By using this code i am not able to get the data from sqlite file.Please suggest me how to proceed.i have seen some sites where steps have been mentioned to create table,insert data by writing code in java script itself.But i don't know to do it that way i want to import the existing sqlite file. 通过使用此代码,我无法从sqlite文件中获取数据。请建议我如何进行操作。我已经看到一些站点提到了创建表的步骤,通过在Java脚本本身中编写代码来插入数据。我不知道要以这种方式导入现有的sqlite文件。

Web apps are not allowed to access arbitrary files on the computer. 不允许Web应用访问计算机上的任意文件。

You could download some data from the same server where your JavaScript code comes from, but it would be easier and faster to embed the SQL commands to create your database in your code. 您可以从JavaScript代码所在的同一服务器上下载一些数据,但是将SQL命令嵌入到代码中创建数据库将更加容易和快捷。 (Use the .dump command of the sqlite3 command-line tool to get these SQL commands.) (使用sqlite3命令行工具的.dump命令获取这些SQL命令。)

for Safari browser: 对于Safari浏览器:

create dummy database in your HTML5. 在HTML5中创建虚拟数据库。

after that copy database file name from mentioned location. 然后从提到的位置复制数据库文件名。

\\Application Data\\Apple Computer\\Safari\\Databases{your domain name}{database File name} \\ Application Data \\ Apple Computer \\ Safari \\ Databases {您的域名} {database文件名}

replace your database file name from newer one. 从较新的数据库文件名中替换您的数据库文件名。 and paste into the above mentioned location. 并粘贴到上述位置。

open your HTML5 page i hope it's work's good. 打开您的HTML5页面,希望一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM