[英]Debugging Firefox extension - How to see all JS and XUL files contained in the XPI?
[英]How to use SQLite in Firefox Extension (XUL files) with Javascript source?
我想寫一個Firefox擴展,它創建一個SQLite數據庫,然后在其中放入一些記錄。 但是,我在運行語句時遇到錯誤。
這是xul文件:
<?xml version="1.0"?>
<overlay id="sample" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<script type="application/x-javascript" src="chrome://sqlitetry/content/sqlitetry.js"/>
<statusbar id="status-bar">
<statusbarpanel id="my-panel" label="Welcome to SQLite Try 1.0b." />
</statusbar>
<html:div id="status">
</html:div>
</overlay>
這是javascript插件,它試圖創建數據庫和記錄:
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm")
var dbFile = FileUtils.getFile("ProfD", ["test.sqlite"]);
var dbService = Components.classes["@mozilla.org/storage/service;1"].
getService(Components.interfaces.mozIStorageService);
var dbConnection;
console.log("CONNECT...")
dbConnection = dbService.openDatabase(dbFile);
console.log("\tOK")
var statement = dbConnection.createStatement("SELECT * FROM mytest");
var res = statement.executeStep();
但是瀏覽器控制台中有一個錯誤,如下所示:
NS_ERROR_FAILURE:組件返回失敗代碼:0x80004005(NS_ERROR_FAILURE)[mozIStorageConnection.createStatement]
以下是腳本擴展的完整來源: http : //speedy.sh/4nhsf/source4.xpi
請問有人幫忙,問題是什么?
好吧,你沒有創建mytest
表,所以SELECT語句失敗了。 嘗試
...
dbConnection = dbService.openDatabase(dbFile);
console.log("\tOK")
dbConnection.createTable("mytest", "foo INTEGER, bar STRING");
dbConnection.executeSimpleSQL("insert into mytest (foo,bar) values (1,'test')")
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.