Skip to content

Commit

Permalink
fix parameterized execute()
Browse files Browse the repository at this point in the history
  • Loading branch information
nakagami committed Feb 16, 2013
1 parent 991fd8e commit 330818e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cymysql/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ def execute(self, query, args=None):

# TODO: make sure that conn.escape is correct

if PYTHON3 and (not isinstance(query, str)):
query = query.decode(charset)
if (not PYTHON3) and isinstance(query, unicode):
query = query.encode(charset)

if args is not None:
if isinstance(args, tuple) or isinstance(args, list):
escaped_args = tuple(conn.escape(arg) for arg in args)
Expand All @@ -102,9 +107,6 @@ def execute(self, query, args=None):

query = query % escaped_args

if PYTHON3 or isinstance(query, unicode):
query = query.encode(charset)

result = 0
try:
result = self._query(query)
Expand Down
8 changes: 5 additions & 3 deletions cymysql/cursorsx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class Cursor(object):

# TODO: make sure that conn.escape is correct

if PYTHON3 and (not isinstance(query, str)):
query = query.decode(charset)
if (not PYTHON3) and isinstance(query, unicode):
query = query.encode(charset)

if args is not None:
if isinstance(args, tuple) or isinstance(args, list):
escaped_args = tuple(conn.escape(arg) for arg in args)
Expand All @@ -102,9 +107,6 @@ class Cursor(object):

query = query % escaped_args

if PYTHON3 or isinstance(query, unicode):
query = query.encode(charset)

result = 0
try:
result = self._query(query)
Expand Down

0 comments on commit 330818e

Please sign in to comment.