-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.js
61 lines (52 loc) · 1.51 KB
/
storage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
.pragma library
.import QtQuick.LocalStorage 2.0 as LocalStorage
var sessioniCaricate = false;
var listaSessioni = []
function getSessioni() {
if (!sessioniCaricate) {
listaSessioni = JSON.parse(get("listaSessioni", "[]"));
// console.log(get("listaSessioni", "[]"));
sessioniCaricate = true;
}
return listaSessioni;
}
function setSessioni(lista) {
listaSessioni = lista;
set("listaSessioni",JSON.stringify(lista));
}
function getDatabase() {
return LocalStorage.LocalStorage.openDatabaseSync("SSHExec", "0.1", "SettingsDatabase", 100);
}
function set(setting, value) {
var db = getDatabase();
var res = "";
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS settings(setting TEXT UNIQUE, value TEXT)');
var rs = tx.executeSql('INSERT OR REPLACE INTO settings VALUES (?,?);', [setting,value]);
if (rs.rowsAffected > 0) {
res = "OK";
} else {
res = "Error";
}
}
);
return res;
}
function get(setting, default_value) {
var db = getDatabase();
var res="";
try {
db.transaction(function(tx) {
var rs = tx.executeSql('SELECT value FROM settings WHERE setting=?;', [setting]);
if (rs.rows.length > 0) {
res = rs.rows.item(0).value;
} else {
res = default_value;
}
})
} catch (err) {
//console.log("Database " + err);
res = default_value;
};
return res
}