Skip to content

Commit

Permalink
Fix some BLOBs without binary flag is not decoded.
Browse files Browse the repository at this point in the history
Fixes #15
  • Loading branch information
methane committed Jan 5, 2015
1 parent 9271c1a commit e78ce1f
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions MySQLdb/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Conversion function:
Arguments: Python object of indicated type or class AND
Arguments: Python object of indicated type or class AND
conversion dictionary
Returns: SQL literal value
Expand Down Expand Up @@ -58,7 +58,7 @@ def Str2Set(s):

def Set2Str(s, d):
return string_literal(','.join(s), d)

def Thing2Str(s, d):
"""Convert something into a string via str()."""
return str(s)
Expand All @@ -74,7 +74,7 @@ def Float2Str(o, d):

def None2NULL(o, d):
"""Convert None to NULL."""
return NULL # duh
return NULL # duh

def Thing2Literal(o, d):
"""Convert something into a SQL string literal. If using
Expand All @@ -93,6 +93,9 @@ def array2Str(o, d):
def quote_tuple(t, d):
return "(%s)" % (','.join(escape_sequence(t, d)))

# bytes or str regarding to BINARY_FLAG.
_bytes_or_str = [(FLAG.BINARY, bytes)]

conversions = {
int: Thing2Str,
long: Thing2Str,
Expand Down Expand Up @@ -123,19 +126,16 @@ def quote_tuple(t, d):
FIELD_TYPE.DATETIME: DateTime_or_None,
FIELD_TYPE.TIME: TimeDelta_or_None,
FIELD_TYPE.DATE: Date_or_None,
FIELD_TYPE.BLOB: [
(FLAG.BINARY, bytes),
],
FIELD_TYPE.STRING: [
(FLAG.BINARY, bytes),
],
FIELD_TYPE.VAR_STRING: [
(FLAG.BINARY, bytes),
],
FIELD_TYPE.VARCHAR: [
(FLAG.BINARY, bytes),
],
}

FIELD_TYPE.TINY_BLOB: _bytes_or_str,
FIELD_TYPE.MEDIUM_BLOB: _bytes_or_str,
FIELD_TYPE.LONG_BLOB: _bytes_or_str,
FIELD_TYPE.BLOB: _bytes_or_str,
FIELD_TYPE.STRING: _bytes_or_str,
FIELD_TYPE.VAR_STRING: _bytes_or_str,
FIELD_TYPE.VARCHAR: _bytes_or_str,
}

if PY2:
conversions[unicode] = Unicode2Str
else:
Expand Down

0 comments on commit e78ce1f

Please sign in to comment.