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)
|
matched = re.match("^" + value + "$", v, re.MULTILINE)
|
||||||
else:
|
else:
|
||||||
matched = False
|
matched = False
|
||||||
|
elif op == "REGEXP":
|
||||||
|
if value and v:
|
||||||
|
matched = re.search(value, v, re.MULTILINE) is not None
|
||||||
|
else:
|
||||||
|
matched = False
|
||||||
else:
|
else:
|
||||||
raise Exception("invalid select operator: '%s'" % op)
|
raise Exception("invalid select operator: '%s'" % op)
|
||||||
return True if matched else False
|
return True if matched else False
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
sqlite3.paramstyle = 'qmark'
|
sqlite3.paramstyle = 'qmark'
|
||||||
|
|
||||||
@ -10,6 +11,7 @@ class Sqlite(object):
|
|||||||
self.connection = sqlite3.connect(*args, **kwargs)
|
self.connection = sqlite3.connect(*args, **kwargs)
|
||||||
self.cursor = self.connection.cursor()
|
self.cursor = self.connection.cursor()
|
||||||
self.queries = {}
|
self.queries = {}
|
||||||
|
self.connection.create_function("regexp", 2, regexp)
|
||||||
|
|
||||||
def execute(self, *args, **kwargs):
|
def execute(self, *args, **kwargs):
|
||||||
self.log.debug(args)
|
self.log.debug(args)
|
||||||
@ -42,3 +44,6 @@ class Sqlite(object):
|
|||||||
def close(self):
|
def close(self):
|
||||||
self.log.debug("closing database...")
|
self.log.debug("closing database...")
|
||||||
self.connection.close()
|
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