0

我有一个 Sqlite 数据库。我想通过 indexedDB 连接到我的文件。我也尝试了 indexedDB,它在配置文件中创建了新的 sqlite 文件。这个新的 sqlite 文件有一个名为“database”的表。该表包含我的文件名。

我的源代码是:

var indexedDB = window.indexedDB 
    || window.webkitIndexedDB 
    || window.mozIndexedDB
    || window.msIndexedDB;

var db;
var request = indexedDB.open("rule");
request.onerror = function(evt) {
  console.log("Database error code: " + evt.target.errorCode);
};
request.onsuccess = function(evt) {
  console.log("Database connect success");
  db = request.result;
};

代码运行时,db变量为空。

4

2 回答 2

1

这是不可能的。

虽然Firefox 以 SQLite 格式存储自己的 IndexedDB 数据库,但您不能直接查询或访问这些数据库。相反,您需要使用异步 IDB API。

于 2013-01-29T15:43:07.123 回答
0

If I am understanding your question correctly, you have a pre-existing SQLite database and you are trying to connect to it using IndexedDB?

As editor said in his answer, this is not possible. IndexedDB is not a generic interface for accessing databases. The name is kind of deceptive, IndexedDB is not a relational database; it actually allows you to create Object Stores in the browser to store JavaScript objects in. These stores are created in the browser using JavaScript, the current implementation in Firefox does store IndexedDB data in a SQLite database but the spec does not require this, each browser may store the data however they like behind the scenes. Other browsers, and future versions of Firefox may or may not use SQLite at all, again that doesn't really matter because IndexedDB does not provide access to the backend databases it uses anyway. Even the current implementation in Firefox does not solely rely on SQLite, it stores things like File and Blob objects separate from the SQLite DB.

于 2013-01-31T23:09:41.690 回答