How to access a SQLite database inside the data di

2019-05-31 06:01发布

问题:

Is there any way to access a SQLite database inside the Data directory in the add-on builder using add-on sdk v1.5?

this is the code that i am using:

var {Cc, Ci, Cu} = require("chrome");
var data = require('self').data;

// This is an active module of the pankajsingh5k Add-on
exports.main = function() {

var {Services} = Cu.import("resource://gre/modules/Services.jsm");
var {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm");

var file = FileUtils.getFile("Desk", "Helper.sqlite");

var mDBConn = Services.storage.openDatabase(file);

console.log('loading');

var statement = mDBConn.createStatement("SELECT * FROM Words");  

right now FileUtils.getFile() is set to "Desk" which stands for Desktop. I dont know how i can access the sql lite file in the add on builder directory structure.

回答1:

You cannot and there is a very simple reason for that - with bug 638742 fixed (starting with Add-on SDK 1.5 I think) the data directory no longer is a directory on disk. The add-on is installed as an XPI file on disk and this directory is actually a directory inside the packed XPI file. SQLite needs a real file to work with, putting changing data inside the data directory would have been a bad idea anyway.

You should use "ProfD" instead of "Desk" - this is the user's profile directory. Make sure to choose a file name that clearly belongs to your extension, all extension are writing data into the profile.