如何在Add on Builder中访问数据目录内的SQLite数据库 [英] How to access a SQLite database inside the data directory in add on builder

查看:89
本文介绍了如何在Add on Builder中访问数据目录内的SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用附件SDK v1.5在附件生成器的Data目录内访问SQLite数据库?

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");  

现在,FileUtils.getFile()设置为"Desk",代表桌面.我不知道如何在添加生成器目录结构中访问sql lite文件.

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.

推荐答案

您不能这样做,原因很简单-使用

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.

您应该使用"ProfD"而不是"Desk"-这是用户的配置文件目录.确保选择一个明显属于您的扩展名的文件名,所有扩展名都将数据写入配置文件中.

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.

这篇关于如何在Add on Builder中访问数据目录内的SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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