Sign in to follow this  
Followers 0
jchd

REGEX in SQLite

3 posts in this topic

#1 ·  Posted (edited)

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.

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)

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
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)

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
Sign in to follow this  
Followers 0