From da4833a49f527fdebd4448475cd11e3c0066381b Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 28 Apr 2011 23:34:02 +0200 Subject: [PATCH] retrieval works --- private/storagethread.cpp | 87 ++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/private/storagethread.cpp b/private/storagethread.cpp index f3515169c..89adcfacb 100644 --- a/private/storagethread.cpp +++ b/private/storagethread.cpp @@ -181,6 +181,7 @@ void StorageThread::retrieve(QWeakPointer wcaller, const QVariantMap return; } + const QString clientName = caller->clientName(); initializeDb(caller); QString valueGroup = params["group"].toString(); if (valueGroup.isEmpty()) { @@ -189,58 +190,58 @@ void StorageThread::retrieve(QWeakPointer wcaller, const QVariantMap QSqlQuery query(m_db); - //a bit redundant but should be the faster way with less string concatenation as possible - if (params["key"].toString().isEmpty()) { - //update modification time - query.prepare("update " + caller->clientName() + " set accessTime=date('now') where valueGroup=:valueGroup"); - query.bindValue(":valueGroup", valueGroup); - query.exec(); + //a bit redundant but should be the faster way with less string concatenation as possible + if (params["key"].toString().isEmpty()) { + //update modification time + query.prepare("update " + clientName + " set accessTime=date('now') where valueGroup=:valueGroup"); + query.bindValue(":valueGroup", valueGroup); + query.exec(); - query.prepare("select * from " + caller->clientName() + " where valueGroup=:valueGroup"); - query.bindValue(":valueGroup", valueGroup); - } else { - //update modification time - query.prepare("update " + caller->clientName() + " set accessTime=date('now') where valueGroup=:valueGroup and id=:key"); - query.bindValue(":valueGroup", valueGroup); - query.bindValue(":key", params["key"].toString()); - query.exec(); + query.prepare("select * from " + clientName + " where valueGroup=:valueGroup"); + query.bindValue(":valueGroup", valueGroup); + } else { + //update modification time + query.prepare("update " + clientName + " set accessTime=date('now') where valueGroup=:valueGroup and id=:key"); + query.bindValue(":valueGroup", valueGroup); + query.bindValue(":key", params["key"].toString()); + query.exec(); - query.prepare("select * from " + caller->clientName() + " where valueGroup=:valueGroup and id=:key"); - query.bindValue(":valueGroup", valueGroup); - query.bindValue(":key", params["key"].toString()); - } + query.prepare("select * from " + clientName + " where valueGroup=:valueGroup and id=:key"); + query.bindValue(":valueGroup", valueGroup); + query.bindValue(":key", params["key"].toString()); + } - const bool success = query.exec(); + const bool success = query.exec(); - QVariant result; + QVariant result; - caller->data().clear(); - if (success) { - QSqlRecord rec = query.record(); - const int keyColumn = rec.indexOf("id"); - const int textColumn = rec.indexOf("txt"); - const int intColumn = rec.indexOf("int"); - const int floatColumn = rec.indexOf("float"); - const int binaryColumn = rec.indexOf("binary"); + if (success) { + QSqlRecord rec = query.record(); + const int keyColumn = rec.indexOf("id"); + const int textColumn = rec.indexOf("txt"); + const int intColumn = rec.indexOf("int"); + const int floatColumn = rec.indexOf("float"); + const int binaryColumn = rec.indexOf("binary"); - while (query.next()) { - const QString key = query.value(keyColumn).toString(); - if (!query.value(textColumn).isNull()) { - caller->data().insert(key, query.value(textColumn)); - } else if (!query.value(intColumn).isNull()) { - caller->data().insert(key, query.value(intColumn)); - } else if (!query.value(floatColumn).isNull()) { - caller->data().insert(key, query.value(floatColumn)); - } else if (!query.value(binaryColumn).isNull()) { - caller->data().insert(key, query.value(binaryColumn)); - } + QVariantHash data; + while (query.next()) { + const QString key = query.value(keyColumn).toString(); + if (!query.value(textColumn).isNull()) { + data.insert(key, query.value(textColumn)); + } else if (!query.value(intColumn).isNull()) { + data.insert(key, query.value(intColumn)); + } else if (!query.value(floatColumn).isNull()) { + data.insert(key, query.value(floatColumn)); + } else if (!query.value(binaryColumn).isNull()) { + data.insert(key, query.value(binaryColumn)); } - - result = caller->data(); - } else { - result = false; } + caller->setData(data); + } else { + result = false; + } + emit newResult(caller, result); }