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 87d1145

Browse filesBrowse files
committed
Fix the conversion of list or tuple args to a SQL.
When there is one element on the list, the generated SQL was (1,) (python notation of a single element tuple, which is not valid in SQL.
1 parent c8b2744 commit 87d1145
Copy full SHA for 87d1145

File tree

Expand file treeCollapse file tree

2 files changed

+9
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-3
lines changed

‎MySQLdb/converters.py

Copy file name to clipboardExpand all lines: MySQLdb/converters.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,16 @@ def char_array(s):
129129
def array2Str(o, d):
130130
return Thing2Literal(o.tostring(), d)
131131

132+
def quote_tuple(t, d):
133+
return "(%s)" % (','.join(escape_sequence(t, d)))
134+
132135
conversions = {
133136
IntType: Thing2Str,
134137
LongType: Long2Int,
135138
FloatType: Float2Str,
136139
NoneType: None2NULL,
137-
TupleType: escape_sequence,
138-
ListType: escape_sequence,
140+
TupleType: quote_tuple,
141+
ListType: quote_tuple,
139142
DictType: escape_dict,
140143
InstanceType: Instance2Str,
141144
ArrayType: array2Str,

‎MySQLdb/cursors.py

Copy file name to clipboardExpand all lines: MySQLdb/cursors.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ def execute(self, query, args=None):
180180
if isinstance(query, unicode):
181181
query = query.encode(db.unicode_literal.charset)
182182
if args is not None:
183-
query = query % db.literal(args)
183+
if isinstance(args, dict):
184+
query = query % {key: db.literal(item) for key, item in args.iteritems()}
185+
else:
186+
query = query % tuple([db.literal(item) for item in args])
184187
try:
185188
r = None
186189
r = self._query(query)

0 commit comments

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