retrieval works

This commit is contained in:
Aaron Seigo 2011-04-28 23:34:02 +02:00 committed by Marco Martin
parent 33ed49a303
commit da4833a49f

View File

@ -181,6 +181,7 @@ void StorageThread::retrieve(QWeakPointer<StorageJob> wcaller, const QVariantMap
return; return;
} }
const QString clientName = caller->clientName();
initializeDb(caller); initializeDb(caller);
QString valueGroup = params["group"].toString(); QString valueGroup = params["group"].toString();
if (valueGroup.isEmpty()) { if (valueGroup.isEmpty()) {
@ -192,20 +193,20 @@ void StorageThread::retrieve(QWeakPointer<StorageJob> wcaller, const QVariantMap
//a bit redundant but should be the faster way with less string concatenation as possible //a bit redundant but should be the faster way with less string concatenation as possible
if (params["key"].toString().isEmpty()) { if (params["key"].toString().isEmpty()) {
//update modification time //update modification time
query.prepare("update " + caller->clientName() + " set accessTime=date('now') where valueGroup=:valueGroup"); query.prepare("update " + clientName + " set accessTime=date('now') where valueGroup=:valueGroup");
query.bindValue(":valueGroup", valueGroup); query.bindValue(":valueGroup", valueGroup);
query.exec(); query.exec();
query.prepare("select * from " + caller->clientName() + " where valueGroup=:valueGroup"); query.prepare("select * from " + clientName + " where valueGroup=:valueGroup");
query.bindValue(":valueGroup", valueGroup); query.bindValue(":valueGroup", valueGroup);
} else { } else {
//update modification time //update modification time
query.prepare("update " + caller->clientName() + " set accessTime=date('now') where valueGroup=:valueGroup and id=:key"); query.prepare("update " + clientName + " set accessTime=date('now') where valueGroup=:valueGroup and id=:key");
query.bindValue(":valueGroup", valueGroup); query.bindValue(":valueGroup", valueGroup);
query.bindValue(":key", params["key"].toString()); query.bindValue(":key", params["key"].toString());
query.exec(); query.exec();
query.prepare("select * from " + caller->clientName() + " where valueGroup=:valueGroup and id=:key"); query.prepare("select * from " + clientName + " where valueGroup=:valueGroup and id=:key");
query.bindValue(":valueGroup", valueGroup); query.bindValue(":valueGroup", valueGroup);
query.bindValue(":key", params["key"].toString()); query.bindValue(":key", params["key"].toString());
} }
@ -214,7 +215,6 @@ void StorageThread::retrieve(QWeakPointer<StorageJob> wcaller, const QVariantMap
QVariant result; QVariant result;
caller->data().clear();
if (success) { if (success) {
QSqlRecord rec = query.record(); QSqlRecord rec = query.record();
const int keyColumn = rec.indexOf("id"); const int keyColumn = rec.indexOf("id");
@ -223,20 +223,21 @@ void StorageThread::retrieve(QWeakPointer<StorageJob> wcaller, const QVariantMap
const int floatColumn = rec.indexOf("float"); const int floatColumn = rec.indexOf("float");
const int binaryColumn = rec.indexOf("binary"); const int binaryColumn = rec.indexOf("binary");
QVariantHash data;
while (query.next()) { while (query.next()) {
const QString key = query.value(keyColumn).toString(); const QString key = query.value(keyColumn).toString();
if (!query.value(textColumn).isNull()) { if (!query.value(textColumn).isNull()) {
caller->data().insert(key, query.value(textColumn)); data.insert(key, query.value(textColumn));
} else if (!query.value(intColumn).isNull()) { } else if (!query.value(intColumn).isNull()) {
caller->data().insert(key, query.value(intColumn)); data.insert(key, query.value(intColumn));
} else if (!query.value(floatColumn).isNull()) { } else if (!query.value(floatColumn).isNull()) {
caller->data().insert(key, query.value(floatColumn)); data.insert(key, query.value(floatColumn));
} else if (!query.value(binaryColumn).isNull()) { } else if (!query.value(binaryColumn).isNull()) {
caller->data().insert(key, query.value(binaryColumn)); data.insert(key, query.value(binaryColumn));
} }
} }
result = caller->data(); caller->setData(data);
} else { } else {
result = false; result = false;
} }