Commit 4ee9aa05 authored by Karel Slaný's avatar Karel Slaný

Returning list of qint64 as message identifiers from file database.

parent 544011a3
......@@ -83,8 +83,7 @@ void Files::deleteExpiredFilesFromDbs(int days)
return;
}
QStringList msgIDList;
QStringList userNameList(GlobInstcs::acntMapPtr->keys());
const QStringList userNameList(GlobInstcs::acntMapPtr->keys());
foreach (const QString &userName, userNameList) {
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
......@@ -94,7 +93,7 @@ void Files::deleteExpiredFilesFromDbs(int days)
<< userName;
return;
}
msgIDList = fDb->cleanFilesInDb(days);
const QList<qint64> msgIDList(fDb->cleanFilesInDb(days));
if (msgIDList.isEmpty()) {
continue;
}
......@@ -107,9 +106,8 @@ void Files::deleteExpiredFilesFromDbs(int days)
return;
}
msgDb->beginTransaction();
foreach (const QString &msgId, msgIDList) {
msgDb->setAttachmentDownloaded(msgId.toLongLong(),
false);
foreach (qint64 msgId, msgIDList) {
msgDb->setAttachmentDownloaded(msgId, false);
}
msgDb->commitTransaction();
}
......
......@@ -702,7 +702,7 @@ int Messages::searchMsg(const QVariant &msgModelVariant, const QString &phrase,
foreach (const QString &userName, userNameList) {
/* First step: Search in attachment names, return msg ID list */
QStringList msgIds;
QList<qint64> msgIds;
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
......
......@@ -24,6 +24,7 @@
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QSet>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
......@@ -43,10 +44,10 @@ FileDb::FileDb(const QString &connectionName)
{
}
QStringList FileDb::cleanFilesInDb(int days)
QList<qint64> FileDb::cleanFilesInDb(int days)
{
QSqlQuery query(m_db);
QStringList msgIDList;
QSet<qint64> msgIdSet;
/* count split date based on days */
QDate now = QDate::currentDate();
......@@ -56,35 +57,33 @@ QStringList FileDb::cleanFilesInDb(int days)
if (!query.prepare(queryStr)) {
qCritical() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
return QStringList();
return QList<qint64>();
}
query.bindValue(":date", now);
if (query.exec() && query.isActive()) {
query.first();
while (query.isValid()) {
msgIDList.append(query.value(0).toString());
msgIdSet.insert(query.value(0).toLongLong());
query.next();
}
} else {
return QStringList();
return QList<qint64>();
}
queryStr = "DELETE FROM files WHERE _dmDownloadDate < :date";
if (!query.prepare(queryStr)) {
qCritical() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
return QStringList();
return QList<qint64>();
}
query.bindValue(":date", now);
if (!query.exec()) {
return QStringList();
return QList<qint64>();
}
msgIDList.removeDuplicates();
return msgIDList;
return msgIdSet.toList();
}
bool FileDb::copyDb(const QString &newFileName)
......@@ -313,10 +312,10 @@ bool FileDb::vacuumFileDb(void)
return false;
}
QStringList FileDb::searchAttachmentName(const QString &phrase)
QList<qint64> FileDb::searchAttachmentName(const QString &phrase) const
{
QSqlQuery query(m_db);
QStringList msgIds;
QList<qint64> msgIds;
QString queryStr = "SELECT DISTINCT dmID FROM files WHERE "
"dmFileDescr LIKE '%'||:_phrase||'%'";
......@@ -331,7 +330,7 @@ QStringList FileDb::searchAttachmentName(const QString &phrase)
if (query.exec() && query.isActive()) {
query.first();
while (query.isValid()) {
msgIds.append(query.value(0).toString());
msgIds.append(query.value(0).toLongLong());
query.next();
}
return msgIds;
......@@ -344,7 +343,7 @@ QStringList FileDb::searchAttachmentName(const QString &phrase)
<< query.lastError().text().toUtf8().constData();
}
fail:
return QStringList();
return QList<qint64>();
}
QList<class SQLiteTbl *> FileDb::listOfTables(void) const
......
......@@ -47,7 +47,7 @@ public:
* @param[in] days How many days.
* @return List of message IDs where files were deleted.
*/
QStringList cleanFilesInDb(int days);
QList<qint64> cleanFilesInDb(int days);
/*!
* @brief Copy db.
......@@ -132,12 +132,12 @@ public:
bool vacuumFileDb(void);
/*!
* @brief Search in attachment names.
* @brief Search messages with attachment names matching supplied phrase.
*
* @param[in] phrase Search phrase.
* @return Messsage ID list where attachment name contains search phrase.
* @return List of message IDs whose attachment names contain the phrase.
*/
QStringList searchAttachmentName(const QString &phrase);
QList<qint64> searchAttachmentName(const QString &phrase) const;
protected:
/*!
......
......@@ -759,7 +759,7 @@ bool MessageDb::openDb(const QString &fileName, bool storeToDisk)
int MessageDb::searchMessagesAndSetModelFromDb(MessageListModel *msgModel,
const QString &userName, const QString &phrase,
enum MessageType messageType, const QStringList &msgIds)
enum MessageType messageType, const QList<qint64> &msgIds)
{
if (msgModel == Q_NULLPTR) {
Q_ASSERT(0);
......@@ -782,9 +782,11 @@ int MessageDb::searchMessagesAndSetModelFromDb(MessageListModel *msgModel,
"_dmAttachDownloaded, _dmMessageType "
"FROM messages WHERE _dmMessageType = :_dmMessageType "
"AND dmID IN (";
for (int i = 0; i < msgIds.count(); i++) {
(i == msgIds.count()-1) ? queryStr += msgIds.at(i) :
queryStr += msgIds.at(i) + ", ";
for (int i = 0; i < msgIds.count(); ++i) {
queryStr += QString::number(msgIds.at(i));
if (i != (msgIds.count() - 1)) {
queryStr += ", ";
}
}
queryStr += ") ORDER BY dmID DESC";
......
......@@ -226,12 +226,12 @@ public:
* @param[in] phrase Search phrase.
* @param[in] messageType Type of the sought messages.
* @param[in] msgIds List of message IDs where attachment name
* contains search phrase.
* contains sought phrase.
* @return Number of results.
*/
int searchMessagesAndSetModelFromDb(MessageListModel *msgModel,
const QString &userName, const QString &phrase,
enum MessageType messageType, const QStringList &msgIds);
enum MessageType messageType, const QList<qint64> &msgIds);
/*!
* @brief Set flag if message attachment is present.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment