summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Dustman <farcepest@gmail.com>2013-11-21 11:52:42 -0800
committerAndy Dustman <farcepest@gmail.com>2013-11-21 11:52:42 -0800
commit44f8b4d2b9864aa72aabc9d959c6c9f2b29b8dfd (patch)
tree966e2e63b2216f66e514587bd594a041207c5481
parenta7c3ce49fcdb4fee1ec6bb69295cb25f467f66ff (diff)
parent8096d8c0530b6c5ccec671c4746d0f94b4831790 (diff)
downloadmysqldb1-44f8b4d2b9864aa72aabc9d959c6c9f2b29b8dfd.tar.gz
Merge pull request #36 from Multiposting/master
Fix the conversion of list or tuple args to SQL.
-rw-r--r--MySQLdb/converters.py7
-rw-r--r--MySQLdb/cursors.py14
2 files changed, 17 insertions, 4 deletions
diff --git a/MySQLdb/converters.py b/MySQLdb/converters.py
index 491d49b..26c1f90 100644
--- a/MySQLdb/converters.py
+++ b/MySQLdb/converters.py
@@ -129,13 +129,16 @@ def char_array(s):
def array2Str(o, d):
return Thing2Literal(o.tostring(), d)
+def quote_tuple(t, d):
+ return "(%s)" % (','.join(escape_sequence(t, d)))
+
conversions = {
IntType: Thing2Str,
LongType: Long2Int,
FloatType: Float2Str,
NoneType: None2NULL,
- TupleType: escape_sequence,
- ListType: escape_sequence,
+ TupleType: quote_tuple,
+ ListType: quote_tuple,
DictType: escape_dict,
InstanceType: Instance2Str,
ArrayType: array2Str,
diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py
index 7e5a887..7c01870 100644
--- a/MySQLdb/cursors.py
+++ b/MySQLdb/cursors.py
@@ -180,7 +180,11 @@ class BaseCursor(object):
if isinstance(query, unicode):
query = query.encode(db.unicode_literal.charset)
if args is not None:
- query = query % db.literal(args)
+ if isinstance(args, dict):
+ query = query % dict((key, db.literal(item))
+ for key, item in args.iteritems())
+ else:
+ query = query % tuple([db.literal(item) for item in args])
try:
r = None
r = self._query(query)
@@ -236,7 +240,13 @@ class BaseCursor(object):
e = m.end(1)
qv = m.group(1)
try:
- q = [ qv % db.literal(a) for a in args ]
+ q = []
+ for a in args:
+ if isinstance(a, dict):
+ q.append(qv % dict((key, db.literal(item))
+ for key, item in a.iteritems()))
+ else:
+ q.append(qv % tuple([db.literal(item) for item in a]))
except TypeError, msg:
if msg.args[0] in ("not enough arguments for format string",
"not all arguments converted"):