30
30
(with the copy() method), modify the copies, and then pass them to
31
31
MySQL.connect().
32
32
"""
33
+ from decimal import Decimal
33
34
34
- from MySQLdb ._mysql import string_literal , escape , NULL
35
+ from MySQLdb ._mysql import string_literal , escape
35
36
from MySQLdb .constants import FIELD_TYPE , FLAG
36
37
from MySQLdb .times import *
37
38
from MySQLdb .compat import PY2 , long
46
47
ArrayType = array .array
47
48
48
49
49
- def Bool2Str (s , d ): return str (int (s ))
50
-
51
- def Str2Set (s ):
52
- return set ([ i for i in s .split (',' ) if i ])
50
+ def Bool2Str (s , d ):
51
+ return b'1' if s else b'0'
53
52
54
53
def Set2Str (s , d ):
55
54
# Only support ascii string. Not tested.
@@ -73,7 +72,7 @@ def Float2Str(o, d):
73
72
74
73
def None2NULL (o , d ):
75
74
"""Convert None to NULL."""
76
- return NULL # duh
75
+ return b" NULL"
77
76
78
77
def Thing2Literal (o , d ):
79
78
"""Convert something into a SQL string literal. If using
@@ -85,9 +84,6 @@ def Thing2Literal(o, d):
85
84
def Decimal2Literal (o , d ):
86
85
return format (o , 'f' )
87
86
88
- def char_array (s ):
89
- return array .array ('c' , s )
90
-
91
87
def array2Str (o , d ):
92
88
return Thing2Literal (o .tostring (), d )
93
89
@@ -109,18 +105,18 @@ def quote_tuple(t, d):
109
105
DateTimeDeltaType : DateTimeDelta2literal ,
110
106
str : Thing2Literal , # default
111
107
set : Set2Str ,
108
+ Decimal : Decimal2Literal ,
112
109
113
110
FIELD_TYPE .TINY : int ,
114
111
FIELD_TYPE .SHORT : int ,
115
112
FIELD_TYPE .LONG : long ,
116
113
FIELD_TYPE .FLOAT : float ,
117
114
FIELD_TYPE .DOUBLE : float ,
118
- FIELD_TYPE .DECIMAL : float ,
119
- FIELD_TYPE .NEWDECIMAL : float ,
115
+ FIELD_TYPE .DECIMAL : Decimal ,
116
+ FIELD_TYPE .NEWDECIMAL : Decimal ,
120
117
FIELD_TYPE .LONGLONG : long ,
121
118
FIELD_TYPE .INT24 : int ,
122
119
FIELD_TYPE .YEAR : int ,
123
- FIELD_TYPE .SET : Str2Set ,
124
120
FIELD_TYPE .TIMESTAMP : mysql_timestamp_converter ,
125
121
FIELD_TYPE .DATETIME : DateTime_or_None ,
126
122
FIELD_TYPE .TIME : TimeDelta_or_None ,
@@ -134,16 +130,3 @@ def quote_tuple(t, d):
134
130
FIELD_TYPE .VAR_STRING : _bytes_or_str ,
135
131
FIELD_TYPE .VARCHAR : _bytes_or_str ,
136
132
}
137
-
138
- if PY2 :
139
- conversions [unicode ] = Unicode2Str
140
- else :
141
- conversions [bytes ] = Thing2Literal
142
-
143
- try :
144
- from decimal import Decimal
145
- conversions [FIELD_TYPE .DECIMAL ] = Decimal
146
- conversions [FIELD_TYPE .NEWDECIMAL ] = Decimal
147
- conversions [Decimal ] = Decimal2Literal
148
- except ImportError :
149
- pass
0 commit comments