Iczer

Explorer like search in SQLite

10 posts in this topic

I want to make Explorer-like search in SQLite database, but... query come out wrong...

maybe someone can correct me...

#include-once
#include <Array.au3>

Local $sSearchString = 0, $aSearch = 0, $sSearchWord = 0, $aSearchWord = 0, $aSearchWordPermute = 0
$sSearchString = "aaa bb|ccc ddd|eeeeee|ff gg hhhhhh"
$aSearch = StringSplit($sSearchString,"|",1)
$sSearchWord = ""
For $i = 1 To $aSearch[0]
    $aSearchWord = StringSplit($aSearch[$i]," ",2)
    If UBound($aSearchWord) = 2 Then
        $aSearchWordPermute = _ArrayPermute($aSearchWord, "_")
        $sSearchWord &= _ArrayToString($aSearchWordPermute, "% OR %", 1) & "% OR %"
    Else
        $sSearchWord &= StringRegExpReplace($aSearch[$i],"\s","_") & "% OR %"
    EndIf
Next
$sSearchWord = StringTrimRight($sSearchWord,6)
ConsoleWrite($sSearchWord&@crlf)
$sSql_Query = "SELECT FilePath || '\' || FileName FROM IndexingDB WHERE FileName LIKE '%" & $sSearchWord & "%' OR FilePath LIKE '%" & $sSearchWord & "%' ORDER BY FileName"

Share this post


Link to post
Share on other sites



query should return combined string from two columns where some (any) number of patterns can be found. and if pattern consist of two words, then in any combination of this words.

Share this post


Link to post
Share on other sites

query indid incorrect, since later in code i have:

If Not ((_SQLite_GetTable($DB, $sSql_Query, $aList, $iRows, $iColumns) = $SQLITE_OK) And (UBound($aList) > 2)) Then
    MsgBox($MB_SYSTEMMODAL, "SQLiteFileListLoader : SQLite Error", "Error Code: " & _SQLite_ErrCode() & @CRLF & "Error Message: " & _SQLite_ErrMsg())
    Dim $aList[1] = [0]
    Return SetError(7)
EndIf

and msgbox popup - query cannot find anything what was present in database

Share this post


Link to post
Share on other sites

Look at what the resulting query looks like (I added some single quotes but the logic used for building the query is flawed):

SELECT FilePath || '' || FileName FROM IndexingDB WHERE FileName LIKE '%aaa_bb%' OR '%bb_aaa%' OR '%ccc_ddd%' ...

This is incorrect SQL. To use LIKE, this should read:

SELECT FilePath || '' || FileName FROM IndexingDB WHERE FileName LIKE '%aaa_bb%' OR FileName LIKE '%bb_aaa%' OR FileName LIKE '%ccc_ddd%'...

You would benefit from using a FTS3/4 virtual table instead.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

thanks, i try to implement it

but - what is FTS3/4 virtual table?

Share this post


Link to post
Share on other sites

https://www.sqlite.org/fts3.html

Support for FTS4 is build in sqlite3.dll distributed thru AutoIt.

1 person likes this

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

thanks again - seems promising

Share this post


Link to post
Share on other sites

FTS tables work very well once setup correctly for a given application. There is nothing overly complex there, but there are many possibilities and options that may have to be considered. Given the volume of reading involved I prefer to refer you and future readers to the official doc, which is very precise, complete and illustrated with good examples. Paraphrasing it here would be a waste of time for everyone.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now