Bug 430147

Summary: Search and escaping of database wildcard characters in filenames
Product: [Applications] digikam Reporter: Quincy <bbc.quincy>
Component: Searches-AdvancedAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: metzpinguin
Priority: NOR    
Version: 7.1.0   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In: 7.2.0
Sentry Crash Report:

Description Quincy 2020-12-08 11:51:45 UTC
I have filenames with underscores "_" in them separating information encoded in them e.g. "56_1607099331_270_3.tif" where the information is an id, a timestamp, a rotation angle and a camera id.

To tag those files properly I wanted to use the (mighty) search tool, but there are several things working differently than expected:
Using the "keyword search" (not the "advanced search") with "_270_" also yields results with filenames containing e.g. "12709". Obviously this field does not use usual wildcards for file managers ("*" and "?") but the database (in my case SQLite) ones for a "LIKE" query which are "_" and "%". This is not documented on https://docs.kde.org/trunk5/en/extragear-graphics/digikam/using-digikam.html#using-mainwindow-searchesview, instead it is stated that special characters are ignored.
It is not possible (or I did not find how) to escape those characters to search for a "real" underscore e.g. escaping with "\" (even multiple ones) does not work.
The same applies for the advanced search with the "File name" field.

Thanks in advance for having a look into that issue and the great work on this software.
Comment 1 Maik Qualmann 2020-12-08 12:22:52 UTC
The search works when I search for "\_270\_" (without quotation marks).

Maik
Comment 2 Maik Qualmann 2020-12-08 12:27:33 UTC
Ok, it works with MySQL but not with SQLite.

Maik
Comment 3 Maik Qualmann 2020-12-08 19:33:27 UTC
Git commit 5e87ffe78349f56a6da3f8ddee62095074d725ff by Maik Qualmann.
Committed on 08/12/2020 at 19:32.
Pushed by mqualmann into branch 'master'.

add escape character '\' to LIKE search with SQLite
FIXED-IN: 7.2.0

M  +2    -1    NEWS
M  +12   -1    core/libs/database/item/query/fieldquerybuilder.cpp

https://invent.kde.org/graphics/digikam/commit/5e87ffe78349f56a6da3f8ddee62095074d725ff
Comment 4 Quincy 2020-12-09 09:14:21 UTC
Thanks for the quick fix.

So the wildcards "_" and "%" will still be usable and have to be escaped if one needs to use them as literal?

Could one please update the documentation accordingly as wildcards may be of nice use, but I think most people will try "*" and "?" otherwise if at all.