Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f48a294

Browse filesBrowse files
authored
Fix dict parameter support (PyMySQL#324)
1 parent bf0ef58 commit f48a294
Copy full SHA for f48a294

File tree

Expand file treeCollapse file tree

2 files changed

+18
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-1
lines changed

‎MySQLdb/cursors.py

Copy file name to clipboardExpand all lines: MySQLdb/cursors.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ def execute(self, query, args=None):
181181

182182
if args is not None:
183183
if isinstance(args, dict):
184-
args = dict((key, db.literal(item)) for key, item in args.items())
184+
nargs = {}
185+
for key, item in args.items():
186+
if isinstance(key, unicode):
187+
key = key.encode(db.encoding)
188+
nargs[key] = db.literal(item)
189+
args = nargs
185190
else:
186191
args = tuple(map(db.literal, args))
187192
try:

‎tests/test_cursor.py

Copy file name to clipboardExpand all lines: tests/test_cursor.py
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import print_function, absolute_import
2+
13
import pytest
24
import MySQLdb.cursors
35
from configdb import connection_factory
@@ -76,3 +78,13 @@ def test_executemany():
7678
assert cursor._executed.endswith(b"(3, 4),(5, 6)"), "executemany with %% not in one query"
7779
finally:
7880
cursor.execute("DROP TABLE IF EXISTS percent_test")
81+
82+
83+
def test_pyparam():
84+
conn = connect()
85+
cursor = conn.cursor()
86+
87+
cursor.execute(u"SELECT %(a)s, %(b)s", {u'a': 1, u'b': 2})
88+
assert cursor._executed == b"SELECT 1, 2"
89+
cursor.execute(b"SELECT %(a)s, %(b)s", {b'a': 3, b'b': 4})
90+
assert cursor._executed == b"SELECT 3, 4"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.