File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Original file line number Diff line number Diff line change @@ -181,7 +181,12 @@ def execute(self, query, args=None):
181
181
182
182
if args is not None :
183
183
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
185
190
else :
186
191
args = tuple (map (db .literal , args ))
187
192
try :
Original file line number Diff line number Diff line change
1
+ from __future__ import print_function , absolute_import
2
+
1
3
import pytest
2
4
import MySQLdb .cursors
3
5
from configdb import connection_factory
@@ -76,3 +78,13 @@ def test_executemany():
76
78
assert cursor ._executed .endswith (b"(3, 4),(5, 6)" ), "executemany with %% not in one query"
77
79
finally :
78
80
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"
You can’t perform that action at this time.
0 commit comments