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.
This commit is contained in:
Guillaume Bandet
2013-11-04 16:17:57 +01:00
parent c8b2744ea2
commit 87d1145c0d
2 changed files with 9 additions and 3 deletions

View File

@ -129,13 +129,16 @@ def char_array(s):
def array2Str(o, d): def array2Str(o, d):
return Thing2Literal(o.tostring(), d) return Thing2Literal(o.tostring(), d)
def quote_tuple(t, d):
return "(%s)" % (','.join(escape_sequence(t, d)))
conversions = { conversions = {
IntType: Thing2Str, IntType: Thing2Str,
LongType: Long2Int, LongType: Long2Int,
FloatType: Float2Str, FloatType: Float2Str,
NoneType: None2NULL, NoneType: None2NULL,
TupleType: escape_sequence, TupleType: quote_tuple,
ListType: escape_sequence, ListType: quote_tuple,
DictType: escape_dict, DictType: escape_dict,
InstanceType: Instance2Str, InstanceType: Instance2Str,
ArrayType: array2Str, ArrayType: array2Str,

View File

@ -180,7 +180,10 @@ class BaseCursor(object):
if isinstance(query, unicode): if isinstance(query, unicode):
query = query.encode(db.unicode_literal.charset) query = query.encode(db.unicode_literal.charset)
if args is not None: if args is not None:
query = query % db.literal(args) if isinstance(args, dict):
query = query % {key: db.literal(item) for key, item in args.iteritems()}
else:
query = query % tuple([db.literal(item) for item in args])
try: try:
r = None r = None
r = self._query(query) r = self._query(query)