vendredi 11 décembre 2015

Querying SQLite database in Thunderbird

I want to make a small Add-on for Thunderbird that works with a SQLite database. I've created my database with "SQLite Manager". My problem is that when I access the database, I get the message that it is empty. But it isn't!

My database:

----------------------------
| table1 | table2 | table3 |
----------------------------
|  ...   |  ...   |  ...   |
|  ...   |  ...   |  ...   |
----------------------------

Here is my JavaScript code. It should return the name of tables. But, I get 0.

  Components.utils.import("resource://gre/modules/Sqlite.jsm");
  Components.utils.import("resource://gre/modules/Task.jsm");

  Task.spawn(function() {
    let db;
    let result;
    try {

      db = yield Sqlite.openConnection({ path: "db.sqlite" });
      result = yield db.execute("SELECT name FROM sqlite_master WHERE type='table'");

      alert(result.length);

    } catch (ex) {
      alert("error: " + ex);
    } finally {
      if (db) yield db.close();
    }
  });

Can one tell me what I'm doing wrong? Is it possible to import and then to read already existing database in Thunderbird?

Thanks!

Aucun commentaire:

Enregistrer un commentaire