fix(wpcarro/simple-select): Support regexes
The python lib for sqlite doesn't support REGEXP, so we need to support it manually. Change-Id: I90670ff564d6fb40e8cee30c3d1509feb2c00857 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5347 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
This commit is contained in:
parent
426cc2db2c
commit
81138b25eb
1 changed files with 12 additions and 0 deletions
|
@ -5,6 +5,7 @@ import sqlite3
|
||||||
import string
|
import string
|
||||||
from scanner import Scanner
|
from scanner import Scanner
|
||||||
from parser import Parser
|
from parser import Parser
|
||||||
|
import re
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Predicates
|
# Predicates
|
||||||
|
@ -204,6 +205,14 @@ def compile_query(negate, query):
|
||||||
return "NOT LIKE '%{}%'".format(query_string)
|
return "NOT LIKE '%{}%'".format(query_string)
|
||||||
return "LIKE '%{}%'".format(query_string)
|
return "LIKE '%{}%'".format(query_string)
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Helper Functions
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
def regexp(expr, x):
|
||||||
|
reg = re.compile(expr)
|
||||||
|
return reg.search(x) is not None
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Main
|
# Main
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -212,6 +221,9 @@ def main(csv_path=None, debug=False):
|
||||||
# Import CSV to SQLite
|
# Import CSV to SQLite
|
||||||
table = "main"
|
table = "main"
|
||||||
con = sqlite3.connect(":memory:")
|
con = sqlite3.connect(":memory:")
|
||||||
|
|
||||||
|
con.create_function("REGEXP", 2, regexp)
|
||||||
|
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
with open(csv_path, "r") as f:
|
with open(csv_path, "r") as f:
|
||||||
r = csv.DictReader(f)
|
r = csv.DictReader(f)
|
||||||
|
|
Loading…
Reference in a new issue