Skip to content

Commit

Permalink
Added support to regexp operation, based on pull request from @NickBe…
Browse files Browse the repository at this point in the history
…euwsaert (thanks!), minor modifications
  • Loading branch information
Nick Beeuwsaert authored and harelba committed Jan 15, 2014
1 parent 0b8243f commit 7854f4c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions q
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,19 @@ parser.add_option("-e","--encoding",dest="encoding",default=default_encoding,
parser.add_option("-v","--version",dest="version",default=False,action="store_true",
help="Print version")

def regexp(regular_expression, data):
return re.search(regular_expression, data) is not None

class Sqlite3DB(object):
def __init__(self,show_sql=SHOW_SQL):
self.show_sql = show_sql
self.conn = sqlite3.connect(':memory:')
self.cursor = self.conn.cursor()
self.type_names = { str : 'TEXT' , int : 'INT' , float : 'FLOAT' }
self.add_user_functions()

def add_user_functions(self):
self.conn.create_function("regexp", 2, regexp)

def execute_and_fetch(self,q):
try:
Expand Down

0 comments on commit 7854f4c

Please sign in to comment.