Bug 512728

Summary: searching for _v in filename to detect versions returns erroneous results
Product: [Applications] digikam Reporter: Steve Franks <stevef48>
Component: Searches-AdvancedAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED WORKSFORME    
Severity: normal CC: caulier.gilles, metzpinguin
Priority: NOR    
Version First Reported In: 8.8.0   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In: 9.0.0
Sentry Crash Report:

Description Steve Franks 2025-11-28 15:26:37 UTC
When searching for versions (file_v1) the results include all files with v in their name, or extension.

SUMMARY
I accidentally ran BQM without changing the option to overwrite original file, so ended up with lots of _v1 files.
To find these I ran search with _v as filename to match. The results included .Avi .WAV and other files that have the letter v in their name, or extension, but not the underscore.

STEPS TO REPRODUCE
1.  Click on Search | New Advanced Search
2.   Enter _v in the filename | click on OK
3.  Cherck the results

OBSERVED RESULT


EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
(available in the Info Center app, or by running `kinfo` in a terminal window)
Linux/KDE Plasma: 
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Steve Franks 2025-11-28 15:35:52 UTC
OBSERVED RESULT


EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows:  11
macOS: 
(available in the Info Center app, or by running `kinfo` in a terminal window)
Linux/KDE Plasma:   Fedora 43
KDE Plasma Version : 6.5.3 
KDE Frameworks Version: 6.20.0
Qt Version:  6.10.1

ADDITIONAL INFORMATION
Comment 2 Maik Qualmann 2025-11-28 17:15:29 UTC
It's a "LIKE" database search. You need to escape such characters with a "\" at the front. So type: \_v

Maik
Comment 3 Maik Qualmann 2025-11-29 04:56:37 UTC
This is the old Bug 430147 from when we added the escape function to SQLite as well.

Maik
Comment 4 caulier.gilles 2025-11-29 05:19:52 UTC
Hi Maik,

Can we do the special characters escape automatically ? As i know, if we search file name with these characters must be prepared previously:

- _ : \_
- % : \%
- ' : ''
- " : ""
- ; : must be removed as it close an sql instruction.

I'm right ?
Gilles
Comment 5 Maik Qualmann 2025-11-29 06:58:18 UTC
There aren't many characters that need to be escaped in a LIKE SQL statement; see this MS Doc. The underscore is one of them.

https://learn.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql?view=sql-server-ver15#using-wildcard-characters-as-literals

The semicolon (";") as the end character is generally unproblematic, since we already encapsulate the search strings in the SQL statement.

I'll look into whether we can escape characters in SQL statements in general and whether there might be any side effects.

Maik