Iczer Posted April 6, 2015 Share Posted April 6, 2015 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" Link to comment Share on other sites More sharing options...
JohnOne Posted April 6, 2015 Share Posted April 6, 2015 What query do you expect? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Iczer Posted April 6, 2015 Author Share Posted April 6, 2015 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. Link to comment Share on other sites More sharing options...
JohnOne Posted April 6, 2015 Share Posted April 6, 2015 I thought you meant the query string was incorrect. I don't see any SQLite code in your script. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Iczer Posted April 6, 2015 Author Share Posted April 6, 2015 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 Link to comment Share on other sites More sharing options...
jchd Posted April 6, 2015 Share Posted April 6, 2015 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 hereRegExp tutorial: enough to get startedPCRE 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) Link to comment Share on other sites More sharing options...
Iczer Posted April 6, 2015 Author Share Posted April 6, 2015 thanks, i try to implement it but - what is FTS3/4 virtual table? Link to comment Share on other sites More sharing options...
jchd Posted April 6, 2015 Share Posted April 6, 2015 https://www.sqlite.org/fts3.html Support for FTS4 is build in sqlite3.dll distributed thru AutoIt. JohnOne and argumentum 1 1 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 hereRegExp tutorial: enough to get startedPCRE 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) Link to comment Share on other sites More sharing options...
Iczer Posted April 6, 2015 Author Share Posted April 6, 2015 thanks again - seems promising Link to comment Share on other sites More sharing options...
jchd Posted April 7, 2015 Share Posted April 7, 2015 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 hereRegExp tutorial: enough to get startedPCRE 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) Link to comment Share on other sites More sharing options...
jchd Posted June 16, 2020 Share Posted June 16, 2020 Current SQLite implements a better search, FTS5. 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 hereRegExp tutorial: enough to get startedPCRE 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) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now