Mercurial > p > mysql-python > mysqldb-2
comparison MySQLdb/converters.py @ 74:80164eb2f090 MySQLdb
This passes all test, yet is still broken and ugly in many ways.
However, a lot of ugliness has been removed.
author | adustman |
---|---|
date | Sat, 20 Feb 2010 04:27:21 +0000 |
parents | c0c00294239b |
children | 3b03cb566032 |
comparison
equal
deleted
inserted
replaced
73:24fa6a40c706 | 74:80164eb2f090 |
---|---|
13 mysql_timestamp_converter | 13 mysql_timestamp_converter |
14 from types import InstanceType | 14 from types import InstanceType |
15 import array | 15 import array |
16 import datetime | 16 import datetime |
17 from decimal import Decimal | 17 from decimal import Decimal |
18 from itertools import izip | |
18 | 19 |
19 __revision__ = "$Revision$"[11:-2] | 20 __revision__ = "$Revision$"[11:-2] |
20 __author__ = "$Author$"[9:-2] | 21 __author__ = "$Author$"[9:-2] |
21 | 22 |
22 def bool_to_sql(connection, boolean): | 23 def bool_to_sql(connection, boolean): |
141 if field.charsetnr == 63: # BINARY | 142 if field.charsetnr == 63: # BINARY |
142 return str | 143 return str |
143 | 144 |
144 charset = field.result.connection.character_set_name() | 145 charset = field.result.connection.character_set_name() |
145 def char_to_unicode(s): | 146 def char_to_unicode(s): |
147 if s is None: | |
148 return s | |
146 return s.decode(charset) | 149 return s.decode(charset) |
147 | 150 |
148 return char_to_unicode | 151 return char_to_unicode |
149 | 152 |
150 default_decoders = [ | 153 default_decoders = [ |
156 default_encoders = [ | 159 default_encoders = [ |
157 simple_encoder, | 160 simple_encoder, |
158 default_encoder, | 161 default_encoder, |
159 ] | 162 ] |
160 | 163 |
164 def get_codec(field, codecs): | |
165 for c in codecs: | |
166 func = c(field) | |
167 if func: | |
168 return func | |
169 # the default codec is guaranteed to work | |
170 | |
171 def iter_row_decoder(decoders, row): | |
172 if row is None: | |
173 return None | |
174 return ( d(col) for d, col in izip(decoders, row) ) | |
175 | |
176 def tuple_row_decoder(decoders, row): | |
177 if row is None: | |
178 return None | |
179 return tuple(iter_row_decoder(decoders, row)) | |
161 | 180 |
162 | 181 |
163 | 182 |
164 | 183 |
165 | 184 |
185 |