Bug 345025 - Wrong sql statement updating thumbnail modification date
Summary: Wrong sql statement updating thumbnail modification date
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Database-Thumbs (show other bugs)
Version: 4.7.0
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-10 20:22 UTC by Alvaro Soliverez
Modified: 2017-07-25 10:47 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 4.9.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alvaro Soliverez 2015-03-10 20:22:49 UTC
While going through slow queries in my MySQL server, I found this query.


UPDATE Thumbnails SET modificationDate=43102 WHERE id='2014-07-13 23:41:14'

There are several more examples of it. It looks like modificationDate and id got swapped.
Of course, the id is invalid and results in id=2011 being updated.

I tried to find the piece of code responsible to provide a patch, but I couldn't find it.



Reproducible: Always
Comment 1 caulier.gilles 2015-03-10 21:37:36 UTC
Code managing thumbnails database is located here :

https://projects.kde.org/projects/extragear/graphics/digikam/repository/revisions/master/show/libs/database/core

Look all thumbnail* files.

Gilles Caulier
Comment 2 Alvaro Soliverez 2015-03-10 21:42:29 UTC
Here is the culprit. The parameter order in that line is wrong.

https://projects.kde.org/projects/extragear/graphics/digikam/repository/revisions/master/entry/libs/database/core/thumbnaildb.cpp#L282
Comment 3 caulier.gilles 2015-03-10 21:46:54 UTC
Git commit 5d2fcc5dd65724cc1e37f645956eb8d1010e861e by Gilles Caulier.
Committed on 10/03/2015 at 21:43.
Pushed by cgilles into branch 'master'.

fix inverted parameters to update thumbnail date in database
FIXED-IN: 4.9.0

M  +5    -5    libs/database/core/thumbnaildb.cpp

http://commits.kde.org/digikam/5d2fcc5dd65724cc1e37f645956eb8d1010e861e
Comment 4 caulier.gilles 2015-03-10 21:52:08 UTC
Git commit c88f5f53bca3aa0bb29fed90edb92b5ea3598ce1 by Gilles Caulier.
Committed on 10/03/2015 at 21:48.
Pushed by cgilles into branch 'frameworks'.

backport commit #5d2fcc5dd65724cc1e37f645956eb8d1010e861e from git/master to frameworks branch

M  +4    -4    libs/database/core/thumbnaildb.cpp

http://commits.kde.org/digikam/c88f5f53bca3aa0bb29fed90edb92b5ea3598ce1

diff --git a/libs/database/core/thumbnaildb.cpp b/libs/database/core/thumbnaildb.cpp
index e330d83..76b782f 100644
--- a/libs/database/core/thumbnaildb.cpp
+++ b/libs/database/core/thumbnaildb.cpp
@@ -255,9 +255,9 @@ DatabaseCoreBackend::QueryState ThumbnailDB::insertThumbnail(const DatabaseThumb
 {
     QVariant id;
     DatabaseCoreBackend::QueryState lastQueryState;
-    lastQueryState= d->db->execSql(QLatin1String("INSERT INTO Thumbnails (type, modificationDate, orientationHint, data) VALUES (?, ?, ?, ?);"),
-                                   info.type, info.modificationDate, info.orientationHint, info.data,
-                                   0, &id);
+    lastQueryState = d->db->execSql(QLatin1String("INSERT INTO Thumbnails (type, modificationDate, orientationHint, data) VALUES (?, ?, ?, ?);"),
+                                    info.type, info.modificationDate, info.orientationHint, info.data,
+                                    0, &id);

     if (DatabaseCoreBackend::NoErrors == lastQueryState)
     {
@@ -279,7 +279,7 @@ DatabaseCoreBackend::QueryState ThumbnailDB::replaceThumbnail(const DatabaseThum

 DatabaseCoreBackend::QueryState ThumbnailDB::updateModificationDate(int thumbId, const QDateTime& modificationDate)
 {
-    return d->db->execSql(QLatin1String("UPDATE Thumbnails SET modificationDate=? WHERE id=?;"), thumbId, modificationDate);
+    return d->db->execSql(QLatin1String("UPDATE Thumbnails SET modificationDate=? WHERE id=?;"), modificationDate, thumbId);
 }

 void ThumbnailDB::replaceUniqueHash(const QString& oldUniqueHash, int oldFileSize,