diff options
-rw-r--r-- | MySQLdb/converters.py | 7 | ||||
-rw-r--r-- | MySQLdb/cursors.py | 14 | ||||
-rw-r--r-- | MySQLdb/times.py | 9 |
3 files changed, 25 insertions, 5 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"): diff --git a/MySQLdb/times.py b/MySQLdb/times.py index f3a92d7..0ff7476 100644 --- a/MySQLdb/times.py +++ b/MySQLdb/times.py @@ -51,7 +51,12 @@ def DateTime_or_None(s): try: d, t = s.split(sep, 1) - return datetime(*[ int(x) for x in d.split('-')+t.split(':') ]) + if '.' in t: + t, ms = t.split('.',1) + ms = ms.ljust(6, '0') + else: + ms = 0 + return datetime(*[ int(x) for x in d.split('-')+t.split(':')+[ms] ]) except (SystemExit, KeyboardInterrupt): raise except: @@ -62,6 +67,7 @@ def TimeDelta_or_None(s): h, m, s = s.split(':') if '.' in s: s, ms = s.split('.') + ms = ms.ljust(6, '0') else: ms = 0 h, m, s, ms = int(h), int(m), int(s), int(ms) @@ -80,6 +86,7 @@ def Time_or_None(s): h, m, s = s.split(':') if '.' in s: s, ms = s.split('.') + ms = ms.ljust(6, '0') else: ms = 0 h, m, s, ms = int(h), int(m), int(s), int(ms) |