I need to read values from an sqlite database in my plugin. For that I found sqlite.jsm module. My problem is I want to make a row as a global variable, but the code used in sqlite (promises and tasks) is asynchronous. Is there any way I can collect information from my database into a global variable ?
let iDs = [];
Task.spawn(function* () {
let db = yield Sqlite.openConnection({ path:
permissionFilePath});
try {
let row = yield db.execute(
"SELECT id FROM 'moz_hosts'");
for ( i=0; i < row.length; i++) {
console.log("row["+ i +"] :" +
row[i].getResultByIndex(0));
yield iDs.push(row[i].getResultByIndex(0));
}
}
finally {
yield db.close();
}
});
//part of the code that doesn't work, because iDs is not yet assigned any values!
console.log("debug");
for (i=0; i<iDs.length; i++) {
yield console.log("iDs ["+i+"] = "+ iDs[i]);
}
Aucun commentaire:
Enregistrer un commentaire