Enable REGEXP operator
This commit is contained in:
parent
551edbb07a
commit
3c2503fc79
@ -1318,6 +1318,11 @@ class DbReadBase(object):
|
||||
matched = re.match("^" + value + "$", v, re.MULTILINE)
|
||||
else:
|
||||
matched = False
|
||||
elif op == "REGEXP":
|
||||
if value and v:
|
||||
matched = re.search(value, v, re.MULTILINE) is not None
|
||||
else:
|
||||
matched = False
|
||||
else:
|
||||
raise Exception("invalid select operator: '%s'" % op)
|
||||
return True if matched else False
|
||||
|
@ -1,6 +1,7 @@
|
||||
import os
|
||||
import sqlite3
|
||||
import logging
|
||||
import re
|
||||
|
||||
sqlite3.paramstyle = 'qmark'
|
||||
|
||||
@ -10,6 +11,7 @@ class Sqlite(object):
|
||||
self.connection = sqlite3.connect(*args, **kwargs)
|
||||
self.cursor = self.connection.cursor()
|
||||
self.queries = {}
|
||||
self.connection.create_function("regexp", 2, regexp)
|
||||
|
||||
def execute(self, *args, **kwargs):
|
||||
self.log.debug(args)
|
||||
@ -42,3 +44,6 @@ class Sqlite(object):
|
||||
def close(self):
|
||||
self.log.debug("closing database...")
|
||||
self.connection.close()
|
||||
|
||||
def regexp(expr, value):
|
||||
return re.search(expr, value, re.MULTILINE) is not None
|
||||
|
Loading…
Reference in New Issue
Block a user