[英]How to use SQLite in Firefox Extension (XUL files) with Javascript source?
I wanted to write a Firefox Extension which creates an SQLite database, then puts some records in it. 我想写一个Firefox扩展,它创建一个SQLite数据库,然后在其中放入一些记录。 However, I have an error during running the statement.
但是,我在运行语句时遇到错误。
Here's the xul file: 这是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>
This is the javascript plugin which tries to create the database and the records: 这是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();
But there is an error in the browser console like this: 但是浏览器控制台中有一个错误,如下所示:
NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]
NS_ERROR_FAILURE:组件返回失败代码:0x80004005(NS_ERROR_FAILURE)[mozIStorageConnection.createStatement]
Here's the complete source of the extension with the script: http://speedy.sh/4nhsf/source4.xpi 以下是脚本扩展的完整来源: http : //speedy.sh/4nhsf/source4.xpi
Could someone help please, what the problem is? 请问有人帮忙,问题是什么?
Well, you didn't create the mytest
table, so the SELECT statement fails. 好吧,你没有创建
mytest
表,所以SELECT语句失败了。 Try 尝试
...
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.