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()) {
@ -189,58 +190,58 @@ void StorageThread::retrieve(QWeakPointer<StorageJob> wcaller, const QVariantMap
QSqlQuery query(m_db); QSqlQuery query(m_db);
//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());
} }
const bool success = query.exec(); const bool success = query.exec();
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"); const int textColumn = rec.indexOf("txt");
const int textColumn = rec.indexOf("txt"); const int intColumn = rec.indexOf("int");
const int intColumn = rec.indexOf("int"); const int floatColumn = rec.indexOf("float");
const int floatColumn = rec.indexOf("float"); const int binaryColumn = rec.indexOf("binary");
const int binaryColumn = rec.indexOf("binary");
while (query.next()) { QVariantHash data;
const QString key = query.value(keyColumn).toString(); while (query.next()) {
if (!query.value(textColumn).isNull()) { const QString key = query.value(keyColumn).toString();
caller->data().insert(key, query.value(textColumn)); if (!query.value(textColumn).isNull()) {
} else if (!query.value(intColumn).isNull()) { data.insert(key, query.value(textColumn));
caller->data().insert(key, query.value(intColumn)); } else if (!query.value(intColumn).isNull()) {
} else if (!query.value(floatColumn).isNull()) { data.insert(key, query.value(intColumn));
caller->data().insert(key, query.value(floatColumn)); } else if (!query.value(floatColumn).isNull()) {
} else if (!query.value(binaryColumn).isNull()) { data.insert(key, query.value(floatColumn));
caller->data().insert(key, query.value(binaryColumn)); } 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); emit newResult(caller, result);
} }