From 23cca9a318d20333205517c523ab2109cf1da333 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 22 Oct 2010 21:22:15 +0000 Subject: [PATCH] source or key parameters in retrieve expire action svn path=/trunk/KDE/kdelibs/; revision=1188661 --- private/storage.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/private/storage.cpp b/private/storage.cpp index 0e732ce11..44cececae 100644 --- a/private/storage.cpp +++ b/private/storage.cpp @@ -80,8 +80,22 @@ void StorageJob::start() query.bindValue(":date", time.toTime_t()); query.exec(); - query.prepare("select * from data where source=:source"); - query.bindValue(":source", params["source"].toString()); + //a bit redundant but should be the faster way with less string concatenation as possible + if (params["source"].isNull() && params["key"].isNull()) { + setError(true); + return; + } else if (params["source"].isNull()) { + query.prepare("select * from data where key=:key"); + query.bindValue(":source", params["source"].toString()); + } else if (params["key"].isNull()) { + query.prepare("select * from data where source=:source"); + query.bindValue(":source", params["source"].toString()); + } else { + query.prepare("select * from data where source=:source and key=:key"); + query.bindValue(":source", params["source"].toString()); + query.bindValue(":key", params["key"].toString()); + } + const bool success = query.exec(); QHash h; @@ -100,6 +114,14 @@ void StorageJob::start() return; } + } else if (operationName() == "expire") { + QSqlQuery query(m_db); + query.prepare("delete from data where date < :date"); + QDateTime time(QDateTime::currentDateTime()); + time.addDays(-2); + query.bindValue(":date", time.toTime_t()); + query.exec(); + } else { setError(true); }