update blocking in oxd + callback in oxff, split modules in ox.jsm and oxff.jsm

This commit is contained in:
j 2010-08-05 18:34:07 +02:00
commit 1be85a89d8
7 changed files with 153 additions and 120 deletions

44
OxFF/modules/oxff.jsm Normal file
View file

@ -0,0 +1,44 @@
// -*- coding: utf-8 -*-
// vi:si:et:sw=4:sts=4:ts=4
let EXPORTED_SYMBOLS = [ "oxff" ];
const Cc = Components.classes;
const Ci = Components.interfaces;
Components.utils.import("resource://ox/utils.jsm");
let oxff = {
getDBFile: function() {
var file = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties)
.get("ProfD", Ci.nsIFile);
file.append("OxFF.sqlite");
return file;
},
getDB: function() {
var file = this.getDBFile();
var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
var conn = storageService.openDatabase(file);
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS site (site varchar(1024) unique, access INT)");
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS setting (key varchar(1024) unique, value text)");
return conn;
},
get: function(key, value) {
var conn = this.getDB();
var q = conn.createStatement("SELECT value FROM setting WHERE key = :key");
q.params.key = key;
if (q.executeStep())
value = q.row.value;
q.finalize();
return value;
},
set: function(key, value) {
var conn = this.getDB();
var q = conn.createStatement("INSERT OR REPLACE INTO setting values (:key, :value)");
q.params.key = key;
q.params.value = value;
q.executeStep();
q.finalize();
},
};