1
0
Fork 0
mirror of https://github.com/seiichiro0185/sailotp.git synced 2024-05-16 23:50:54 +00:00

Changed DB Schema

* DB Schema now supports setting favourites
* Added Colums for future addition of HOTP Tokens
* Created DB-Update Logic
This commit is contained in:
seiichiro 2014-01-09 19:56:26 +01:00
parent 26bafc2f18
commit 11072b2f16
2 changed files with 26 additions and 14 deletions

View file

@ -29,20 +29,34 @@
.import QtQuick.LocalStorage 2.0 as LS
// Get DB Connection
// Get DB Connection, Initialize or Upgrade DB
function getDB() {
return LS.LocalStorage.openDatabaseSync("harbour-sailotp", "1.0", "SailOTP Config Storage", 1000000);
}
try {
var db = LS.LocalStorage.openDatabaseSync("harbour-sailotp", "", "SailOTP Config Storage", 1000000);
// Initialize Table if not exists
function initialize() {
var db = getDB();
db.transaction(
function(tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS OTPStorage(title TEXT, secret TEXT);");
if (db.version == "") {
// Initialize an empty DB, Create the Table
db.changeVersion("", "2",
function(tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS OTPStorage(title TEXT, secret TEXT, type TEXT, counter INTEGER, fav INTEGER);");
}
);
} else if (db.version == "1.0") {
// Upgrade DB Schema to Version 2
db.changeVersion("1.0", "2",
function(tx) {
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN type TEXT DEFAULT 'TOTP';");
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN counter INTEGER DEFAULT 0;");
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN fav INTEGER DEFAULT 0;");
}
);
}
)
} catch (e) {
// DB Failed to open
console.log("Could not open DB: " + e);
}
return db;
}
// Get all OTPs into the list model
@ -65,7 +79,7 @@ function addOTP(title, secret) {
db.transaction(
function(tx) {
tx.executeSql("INSERT INTO OTPStorage VALUES(?, ?);", [title, secret]);
tx.executeSql("INSERT INTO OTPStorage VALUES(?, ?, ?, ?, ?);", [title, secret, 'TOTP', 0, 0]);
}
)
}

View file

@ -174,8 +174,6 @@ Page {
VerticalScrollDecorator{}
Component.onCompleted: {
// Initialize DB (create tables etc..)
DB.initialize();
// Load list of OTP-Entries
refreshOTPList();
}