From 4aacdd086943923b1f3d08bc77fea2460cd4309c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Couturier?= Date: Sat, 28 Sep 2024 14:08:17 +0200 Subject: [PATCH] https://github.com/StephaneCouturier/Katalog/issues/550 --- src/device.cpp | 12 ++++++------ src/searchprocess.cpp | 39 +++++++++++++++------------------------ src/searchprocess.h | 2 -- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/device.cpp b/src/device.cpp index 9b5d038..464af33 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -783,16 +783,16 @@ void Device::updateActive(QString connectionName) active = false; } - QSqlQuery query(QSqlDatabase::database(connectionName)); - QString querySQL = QLatin1String(R"( + QSqlQuery queryUpdateActive(QSqlDatabase::database(connectionName)); + QString queryUpdateActiveSQL = QLatin1String(R"( UPDATE device SET device_active =:device_active WHERE device_id =:device_id )"); - query.prepare(querySQL); - query.bindValue(":device_active", active); - query.bindValue(":device_id", ID); - query.exec(); + queryUpdateActive.prepare(queryUpdateActiveSQL); + queryUpdateActive.bindValue(":device_active", active); + queryUpdateActive.bindValue(":device_id", ID); + queryUpdateActive.exec(); } void Device::saveStatistics(QDateTime dateTime, QString requestSource) diff --git a/src/searchprocess.cpp b/src/searchprocess.cpp index c9825b6..8472797 100644 --- a/src/searchprocess.cpp +++ b/src/searchprocess.cpp @@ -4,7 +4,6 @@ #include "searchprocess.h" #include "device.h" -#include "src/filesview.h" #include #include #include @@ -32,6 +31,14 @@ void SearchProcess::run() return; } + //Clear search results + mainWindow->newSearch->fileNames.clear(); + mainWindow->newSearch->filePaths.clear(); + mainWindow->newSearch->fileSizes.clear(); + mainWindow->newSearch->fileDateTimes.clear(); + mainWindow->newSearch->fileCatalogs.clear(); + mainWindow->newSearch->fileCatalogIDs.clear(); + //Process the SEARCH in CATALOGS or DIRECTORY ------------------------------ //Prepare the SEARCH ------------------------------- @@ -587,6 +594,7 @@ void SearchProcess::searchFilesInDirectory(const QString &sourceDirectory) mainWindow->newSearch->fileSizes.append(lineFileSize); mainWindow->newSearch->fileDateTimes.append(lineFileDatetime); mainWindow->newSearch->fileCatalogs.append(sourceDirectory); + mainWindow->newSearch->fileCatalogIDs.append(0); } } else{ @@ -611,6 +619,7 @@ void SearchProcess::searchFilesInDirectory(const QString &sourceDirectory) mainWindow->newSearch->fileSizes.append(lineFileSize); mainWindow->newSearch->fileDateTimes.append(lineFileDatetime); mainWindow->newSearch->fileCatalogs.append(sourceDirectory); + mainWindow->newSearch->fileCatalogIDs.append(0); } } } @@ -697,21 +706,6 @@ void SearchProcess::processSearchResults() mainWindow->newSearch->fileSizes.append(0); mainWindow->newSearch->fileDateTimes.append(""); } - - // Populate model with data - fileViewModel->caseSensitive = mainWindow->fileSortCaseSensitive; - fileViewModel->setSourceModel(mainWindow->newSearch); - } - - //Populate model with Files (if the Folder option is not selected) - else - { - // Populate model with data - fileViewModel->caseSensitive = mainWindow->fileSortCaseSensitive; - fileViewModel->setSourceModel(mainWindow->newSearch); - if (mainWindow->newSearch->searchInConnectedChecked == true){ - fileViewModel->setHeaderData(3, Qt::Horizontal, QCoreApplication::translate("MainWindow", "Search Directory")); - } } //Process DUPLICATES ------------------------------- @@ -748,11 +742,9 @@ void SearchProcess::processSearchResults() insertQuery.prepare(insertSQL); //loop through the result list and populate database - int rows = mainWindow->newSearch->rowCount(); for (int i=0; inewSearch->index(i,0).data().toString()); insertQuery.bindValue(":file_size", mainWindow->newSearch->index(i,1).data().toString()); @@ -824,9 +816,6 @@ void SearchProcess::processSearchResults() mainWindow->newSearch->fileCatalogs.append(duplicatesQuery.value(4).toString()); mainWindow->newSearch->fileCatalogIDs.append(duplicatesQuery.value(5).toInt()); } - - //Update search statistics - mainWindow->newSearch->filesFoundNumber = fileViewModel->rowCount(); } //Process DIFFERENCES ------------------------------- @@ -838,6 +827,9 @@ void SearchProcess::processSearchResults() or mainWindow->newSearch->differencesOnDate == true)){ //Load Search results into the database + QSqlQuery transactionQuery(QSqlDatabase::database(connectionName)); + transactionQuery.exec("BEGIN TRANSACTION"); + //Clear database QSqlQuery deleteQuery(QSqlDatabase::database(connectionName)); deleteQuery.exec("DELETE FROM filetemp"); @@ -992,6 +984,8 @@ void SearchProcess::processSearchResults() if (!differencesQuery.exec()) qDebug() << "DEBUG: differencesQuery failed:" << differencesQuery.lastError(); + transactionQuery.exec("COMMIT"); + //Recapture file results for Stats mainWindow->newSearch->fileNames.clear(); mainWindow->newSearch->fileSizes.clear(); @@ -1018,9 +1012,6 @@ void SearchProcess::processSearchResults() mainWindow->newSearch->filesFoundMinDate = ""; mainWindow->newSearch->filesFoundMaxDate = ""; - //Number of files found - mainWindow->newSearch->filesFoundNumber = fileViewModel->rowCount(); - //Total size of files found qint64 sizeItem; mainWindow->newSearch->filesFoundTotalSize = 0; diff --git a/src/searchprocess.h b/src/searchprocess.h index de8c2b3..634ac62 100644 --- a/src/searchprocess.h +++ b/src/searchprocess.h @@ -4,7 +4,6 @@ #include #include #include "mainwindow.h" -#include "filesview.h" class SearchProcess : public QThread { @@ -13,7 +12,6 @@ class SearchProcess : public QThread public: explicit SearchProcess(MainWindow *mainWindow, QString databaseMode, QObject *parent = nullptr); void stop(); - FilesView *fileViewModel = new FilesView(this); QString databaseMode; QString connectionName;