How to get sqlite3 to do regexp in Tcl

I would like to include regexp in my Tcl project, but when I run my code, I get this error:

no such function: REGEXP

my code is as follows:

return [brain eval "select * from bad WHERE input REGEXP '^(.){0}_'"]

I can check this exact code in the database (I use a BD browser for SQLite to view the database) and it works correctly:

select * from uniq WHERE input REGEXP '^(.){1}0'

20 Lines returned from: select * from uniq WHERE input REGEXP '^ (.) {1} 0' (took 18 ms)

So REGEXP will work in the browser, but not in my Tcl Script. Here is what I have found so far on this issue:

, , - , , , . , sqlite3? , ?

?

file mkdir db
sqlite3 db ./brain/brain.sqlite -create true

db eval { create_function('regexp', 2) do |func, pattern, expression|
            func.result = expression.to_s.match(
            Regexp.new(pattern.to_s, Regexp::IGNORECASE)) ? 1 : 0
         end
         }  

, !

+4
1

. , ( , db ), function :

db function regexp -deterministic {regexp --}

SQLite , (, , ) , regexp -- (-- RE, - ).

:

% package require sqlite3
3.8.10.2
% sqlite3 db :memory:
% db eval {select 1 where 'abc' regexp 'b'}
no such function: regexp
% db function regexp -deterministic {regexp --}
% db eval {select 1 where 'abc' regexp 'b'}
1
+6

Source: https://habr.com/ru/post/1618796/


All Articles