X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Fapps%2FPswGen%2FStorage%2Fmodule.cpp;h=b7676abf282f0d1323855a54919a676048619a43;hb=2ed96066b8600d07d9ada5dc44e9768fe56e633c;hp=b0fd6afed017eefccd102ab98a2f96e11c96f5db;hpb=4a856bc600d1819e01c797881e0591810737c2fd;p=evaf
diff --git a/src/apps/PswGen/Storage/module.cpp b/src/apps/PswGen/Storage/module.cpp
index b0fd6af..b7676ab 100644
--- a/src/apps/PswGen/Storage/module.cpp
+++ b/src/apps/PswGen/Storage/module.cpp
@@ -23,7 +23,7 @@
#include
#include
#include
-#include
+#include
#include
#include
@@ -102,13 +102,11 @@ StorageImpl::~StorageImpl()
bool StorageImpl::init()
{
- EVAF_INFO("%s initialized", qPrintable(objectName()));
-
// Open the database
if (!QSqlDatabase::contains(DbConnectionName)) {
// No database connection yet
mDb = QSqlDatabase::addDatabase("QSQLITE", DbConnectionName);
- mDb.setDatabaseName(Common::iEnv::instance()->dataRootDir() + DbName);
+ mDb.setDatabaseName(Common::iApp::instance()->dataRootDir() + DbName);
if (!mDb.open()) {
QSqlError err = mDb.lastError();
EVAF_ERROR("Failed to open database : %s", qPrintable(err.text()));
@@ -131,6 +129,8 @@ bool StorageImpl::init()
/// Register our interface
Common::iRegistry::instance()->registerInterface("iStorage", this);
+ EVAF_INFO("%s initialized", qPrintable(objectName()));
+
return true;
}
@@ -150,7 +150,8 @@ bool StorageImpl::save(QString const & name, QExplicitlySharedDataPointermodified()) {
QSqlQuery q(mDb);
- if (!q.exec(QString("UPDATE data SET length = \'%1\', flags = \'%2\' WHERE name = \'%3\';").arg(data->length()).arg(data->flags()).arg(name))) {
+ if (!q.exec(QString("UPDATE data SET length = \'%1\', flags = \'%2\' WHERE name = \'%3\';")
+ .arg(data->length()).arg(data->flags()).arg(name))) {
QSqlError err = mDb.lastError();
EVAF_ERROR("Failed to update \'%s\' : %s", qPrintable(name), qPrintable(err.text()));
return false;
@@ -160,7 +161,9 @@ bool StorageImpl::save(QString const & name, QExplicitlySharedDataPointerlength()).arg(int(data->flags())))) {
+ if (!q.exec(QString("INSERT INTO data (name, length, flags) VALUES (\'%1\', %2, %3);")
+ .arg(name).arg(data->length())
+ .arg(int(data->flags())))) {
QSqlError err = mDb.lastError();
EVAF_ERROR("Failed to insert \'%s\' : %s", qPrintable(name), qPrintable(err.text()));
return false;
@@ -231,7 +234,7 @@ bool StorageImpl::loadData()
while (q.next()) {
QString name = q.value(0).toString();
- QExplicitlySharedDataPointer data(new Storage::Data(q.value(1).toInt(), uint(q.value(2).toInt())));
+ QExplicitlySharedDataPointer data(new Storage::Data(name, q.value(1).toInt(), uint(q.value(2).toInt())));
mData.insert(name, data);
}