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 e78ce1f

Browse filesBrowse files
committed
Fix some BLOBs without binary flag is not decoded.
Fixes PyMySQL#15
1 parent 9271c1a commit e78ce1f
Copy full SHA for e78ce1f

File tree

Expand file treeCollapse file tree

1 file changed

+16
-16
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-16
lines changed

‎MySQLdb/converters.py

Copy file name to clipboardExpand all lines: MySQLdb/converters.py
+16-16Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
Conversion function:
1919
20-
Arguments: Python object of indicated type or class AND
20+
Arguments: Python object of indicated type or class AND
2121
conversion dictionary
2222
2323
Returns: SQL literal value
@@ -58,7 +58,7 @@ def Str2Set(s):
5858

5959
def Set2Str(s, d):
6060
return string_literal(','.join(s), d)
61-
61+
6262
def Thing2Str(s, d):
6363
"""Convert something into a string via str()."""
6464
return str(s)
@@ -74,7 +74,7 @@ def Float2Str(o, d):
7474

7575
def None2NULL(o, d):
7676
"""Convert None to NULL."""
77-
return NULL # duh
77+
return NULL # duh
7878

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

96+
# bytes or str regarding to BINARY_FLAG.
97+
_bytes_or_str = [(FLAG.BINARY, bytes)]
98+
9699
conversions = {
97100
int: Thing2Str,
98101
long: Thing2Str,
@@ -123,19 +126,16 @@ def quote_tuple(t, d):
123126
FIELD_TYPE.DATETIME: DateTime_or_None,
124127
FIELD_TYPE.TIME: TimeDelta_or_None,
125128
FIELD_TYPE.DATE: Date_or_None,
126-
FIELD_TYPE.BLOB: [
127-
(FLAG.BINARY, bytes),
128-
],
129-
FIELD_TYPE.STRING: [
130-
(FLAG.BINARY, bytes),
131-
],
132-
FIELD_TYPE.VAR_STRING: [
133-
(FLAG.BINARY, bytes),
134-
],
135-
FIELD_TYPE.VARCHAR: [
136-
(FLAG.BINARY, bytes),
137-
],
138-
}
129+
130+
FIELD_TYPE.TINY_BLOB: _bytes_or_str,
131+
FIELD_TYPE.MEDIUM_BLOB: _bytes_or_str,
132+
FIELD_TYPE.LONG_BLOB: _bytes_or_str,
133+
FIELD_TYPE.BLOB: _bytes_or_str,
134+
FIELD_TYPE.STRING: _bytes_or_str,
135+
FIELD_TYPE.VAR_STRING: _bytes_or_str,
136+
FIELD_TYPE.VARCHAR: _bytes_or_str,
137+
}
138+
139139
if PY2:
140140
conversions[unicode] = Unicode2Str
141141
else:

0 commit comments

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