1717
1818Conversion 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
5959def Set2Str (s , d ):
6060 return string_literal (',' .join (s ), d )
61-
61+
6262def Thing2Str (s , d ):
6363 """Convert something into a string via str()."""
6464 return str (s )
@@ -74,7 +74,7 @@ def Float2Str(o, d):
7474
7575def None2NULL (o , d ):
7676 """Convert None to NULL."""
77- return NULL # duh
77+ return NULL # duh
7878
7979def Thing2Literal (o , d ):
8080 """Convert something into a SQL string literal. If using
@@ -93,6 +93,9 @@ def array2Str(o, d):
9393def 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+
9699conversions = {
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+
139139if PY2 :
140140 conversions [unicode ] = Unicode2Str
141141else :
0 commit comments