Skip to content

Instantly share code, notes, and snippets.

@snaka
Forked from teramako/reorgSQLite.js
Created April 29, 2009 19:32

Revisions

  1. snaka revised this gist Apr 29, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion reorgSQLite.js
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ let self = {
    dbConnection.executeSimpleSQL("VACUUM");
    dbConnection.executeSimpleSQL("REINDEX");
    } catch(e){
    alert("ERROR: "+ dbConnection.databaseFile.leafName + ": " + e.message);
    alert("ERROR: "+ dbConnection.databaseFile.leafName + ": " + e.message);
    }
    },
    };
  2. @teramako teramako revised this gist Apr 29, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion reorgSQLite.js
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ let self = {
    dbConnection.executeSimpleSQL("VACUUM");
    dbConnection.executeSimpleSQL("REINDEX");
    } catch(e){
    alert("ERROR: "+dbConnection.databaseFile.leafName+": "+e.message);
    alert("ERROR: "+ dbConnection.databaseFile.leafName + ": " + e.message);
    }
    },
    };
  3. @teramako teramako created this gist Apr 29, 2009.
    35 changes: 35 additions & 0 deletions reorgSQLite.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    liberator.plugins.sqliteReorg = (function(){
    const ss = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
    function getSQLiteFiles(){
    let profDir = services.get("directory").get("ProfD", Ci.nsIFile);
    let files = profDir.directoryEntries;
    let reg = new RegExp("\\.sqlite$");
    while (files.hasMoreElements()){
    let file = files.getNext().QueryInterface(Ci.nsIFile);
    if (file.isFile() && reg.test(file.leafName)){
    yield file;
    }
    }
    }
    let self = {
    start: function(){
    for (let file in getSQLiteFiles()){
    liberator.echomsg("Open " + file.leafName, 1);
    let dbc = ss.openDatabase(file);
    this.reorg(dbc);
    dbc.close();
    liberator.echomsg("Close", 1);
    }
    },
    reorg: function(dbConnection){
    try {
    dbConnection.executeSimpleSQL("VACUUM");
    dbConnection.executeSimpleSQL("REINDEX");
    } catch(e){
    alert("ERROR: "+dbConnection.databaseFile.leafName+": "+e.message);
    }
    },
    };
    liberator.registerObserver("shutdown", self.start);
    return self;
    })();