Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
map params to ?
  • Loading branch information
David Cramer authored and David Cramer committed Nov 30, 2009
1 parent 16aa7ea commit 047b214
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mysql_oursql/base.py
Expand Up @@ -58,6 +58,8 @@
# standard util.CursorDebugWrapper can be used. Also, using sql_mode
# TRADITIONAL will automatically cause most warnings to be treated as errors.

params_re = re.compile(r'%[a-zA-Z]')

class CursorWrapper(object):
"""
A thin wrapper around oursql's normal cursor class so that we can catch
Expand All @@ -70,8 +72,12 @@ class CursorWrapper(object):

def __init__(self, cursor):
self.cursor = cursor

def _replace_params(self, query):
return params_re.replace('?', query)

def execute(self, query, args=None):
query = self._replace_params(query)
try:
return self.cursor.execute(query, args)
except Database.OperationalError, e:
Expand All @@ -82,6 +88,7 @@ def execute(self, query, args=None):
raise

def executemany(self, query, args):
query = self._replace_params(query)
try:
return self.cursor.executemany(query, args)
except Database.OperationalError, e:
Expand Down

0 comments on commit 047b214

Please sign in to comment.