Jump to content

REGEX in SQLite


jchd
 Share

Recommended Posts

Ticket #2778 is asking for an implementation. I don't believe there is a common need for inclusion of such feature in the standard delivery.

I compiled the regex.c source from the official SQLite 3.8.5 distribution and tested it. It works decently well but don't expect it to be fast compared to built-in possibilities. Please refer to the official source where you'll find details about supported pattern elements.

For those who want to try it, you can download a 32-bit extension DLL. It has been compiled with x86 tcc so it's not highly optimized (which doesn't matter much in this case). You'll find >in this post support to manage SQLite extensions.

EDIT: Dropbox once again decided to kill old links. Files are there:

sqlite3-pcre.zip sqlite3-pcre-src.zip

Edited by jchd
Solve dead D/L link

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)

Link to comment
Share on other sites

  • 2 weeks later...

Thanks for sharing. I made an example script:

#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <SQLiteExtLoad.au3>

Local $aResult, $iRows, $iColumns

_SQLite_Startup()
$hDB = _SQLite_Open()
_SQLite_EnableExtensions($hDB,1)
_SQLite_LoadExtension($hDB,@ScriptDir & '\regexp.dll','sqlite3_regexp_init')
_SQLite_Exec($hDB,"CREATE TABLE Example(ID int,Data varchar(50))")
For $Index = 1 To 2000
    _SQLite_Exec($hDB,"INSERT INTO Example(ID,Data) VALUES(" & $Index & "," & _SQLite_FastEscape(RandomChars()) & ")")
Next
_SQLite_GetTable2d($hDB,"SELECT ID,Data FROM Example WHERE Data REGEXP '^\d{3}'",$aResult,$iRows,$iColumns)
_SQLite_Display2DResult($aResult)
_SQLite_Close($hDB)

Func RandomChars()
    Local $sChars
    Local $aCharset = StringSplit('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789','')
    For $Index = 1 To 50
        $sChars &= $aCharset[Random(1,$aCharset[0],1)]
    Next
    Return $sChars
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

Fine, thanks.

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)

Link to comment
Share on other sites

  • 2 years later...

Easy. Here's the X86 .dll and the source file:

sqlite3-pcre.zip

sqlite3-pcre-src.zip

The regex engine used is PCRE v1, the same as AutoIt currently uses.

Edited by jchd

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)

Link to comment
Share on other sites

BTW these files are the same as in post #1 of this very same thread.

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)

Link to comment
Share on other sites

On 1/1/2023 at 2:37 AM, jchd said:

Easy. Here's the X86 .dll and the source file:

sqlite3-pcre.zip 81.17 kB · 18 downloads

sqlite3-pcre-src.zip 329.38 kB · 18 downloads

The regex engine used is PCRE v1, the same as AutoIt currently uses.

Yes , I had downloaded it previously. but  it threw an error when I run Andreik's  scirpt  such as below:

!   SQLite.au3 Error
--> Function: _SQLite_Query
--> Query:    SELECT ID,Data FROM Example WHERE Data REGEXP '^\d{3}'
--> Error:    no such function: REGEXP

And of course , Error still occurs when I re-download these files you offer and rename the file to regexp.dll within sqlite3-pcre.zip

Would you please tell me what's wrong with it ?

Much Tanks

Link to comment
Share on other sites

Post a _short_ & self-contained reproducer script.

Edited by jchd

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)

Link to comment
Share on other sites

Sorry, I didn't look at the example code dated 2014!

This code was for the first version of the DLL, which used the minimal regex engine available in the SQLite source tree.

My version uses a differently named init function. So change the code to:

_SQLite_LoadExtension($hDB,@ScriptDir & '\sqlite3-pcre.dll','sqlite3_extension_init')

Of course, adapt DLL name and location.

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)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...