mercredi 8 juillet 2015

Firefox Extension Sqlite Error

So I have the following code in a firefox extension:

Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");

var file = FileUtils.getFile("CmAppData", ["REDACTED"]);
var dbConn = Services.storage.openDatabase(file);


var myExtension = {
    init: function() {
        // The event can be DOMContentLoaded, pageshow, pagehide, load or unload.
        if(gBrowser) gBrowser.addEventListener("DOMContentLoaded", this.onPageLoad, false);
    },
    onPageLoad: function(aEvent) {
        var doc = aEvent.originalTarget; // doc is document that triggered the event
        var content = doc.body.textContent || doc.body.innerText;
        var hasText = content.indexOf("Personalize Portal")!==-1;
        if(hasText)
        {
            console.log("Portal Page Found");
            setInterval(CheckDB, 5000);
        }
    }
}
window.addEventListener("load", function load(event){
    window.removeEventListener("load", load, false); //remove listener, no longer needed
    myExtension.init();  
},false);

function CheckDB()
{
    var statement = dbConn.createStatement("SELECT * FROM tblContactInformation");  
    console.log("Checking DB");
    while(statement.executeStep())
    {
        console.log("Executing Step");
        var value = statement.row.CustID;
    }
    if(value.length == 1)
    {
        console.log("Entering Data");
        EnterId(value);
        dbConn.executeSimpleSQL("DELETE * FROM tblContactInformation");
    }
}

I keep getting the error:

NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]

On line 32 which is:

var statement = dbConn.createStatement("SELECT * FROM tblContactInformation");  

I can't figure out why. Any help is appreciated. I tried using a parameter query for the table name and I tried using executeStep and ExecuteSimpleSql just for testing and nothing worked. I am completely lost.

Aucun commentaire:

Enregistrer un commentaire