Use SQLite

Table of contents
No headers

If you'd like to use an SQLite database in your extension you'll need to look over the Storage docs for an API reference, however this code should get you started. Be careful of multi-thread access to your database.

This will create an SQLite db named tbird.sqlite inside your profile directory with a table called attachments. You can see the schema for the attachments table in the code. To double check the information you've inserted you can query the tbird.sqlite file using regular SQLite programs.

const Cc = Components.classes;
const Ci = Components.interfaces;

var tbirdsqlite = {

  onLoad: function() {
    // initialization code
    this.initialized = true;

  dbConnection: null,

  dbSchema: {
     tables: {
       attachments:"id           INTEGER PRIMARY KEY, \
                    name         TEXT \
                    encoded      TEXT NOT NULL"

  dbInit: function() {
    var dirService = Cc[";1"].

    var dbFile = dirService.get("ProfD", Ci.nsIFile);

    var dbService = Cc[";1"].

    var dbConnection;

    if (!dbFile.exists())
      dbConnection = this._dbCreate(dbService, dbFile);
    else {
      dbConnection = dbService.openDatabase(dbFile);
    this.dbConnection = dbConnection;

  _dbCreate: function(aDBService, aDBFile) {
    var dbConnection = aDBService.openDatabase(aDBFile);
    return dbConnection;

  _dbCreateTables: function(aDBConnection) {
    for(var name in this.dbSchema.tables)
      aDBConnection.createTable(name, this.dbSchema.tables[name]);
window.addEventListener("load", function(e) { tbirdsqlite.onLoad(e); }, false);

Tags (1)

Edit tags

Attachments (0)


Attach file