Mercurial > p > mysql-python > mysqldb-2
annotate MySQLdb/converters.py @ 59:5db99d9be0fb MySQLdb
Fix #2663436: Character fields with a binary character set should be returned as str, else unicode.
author | adustman |
---|---|
date | Thu, 05 Mar 2009 02:40:50 +0000 |
parents | 9ea2b0e9302e |
children | 2d6a35051f64 |
rev | line source |
---|---|
15 | 1 """ |
2 MySQLdb type conversion module | |
3 ------------------------------ | |
0 | 4 |
15 | 5 This module handles all the type conversions for MySQL. If the default type |
6 conversions aren't what you need, you can make your own. The dictionary | |
7 conversions maps some kind of type to a conversion function which returns the | |
8 corresponding value: | |
0 | 9 |
10 Key: FIELD_TYPE.* (from MySQLdb.constants) | |
11 | |
12 Conversion function: | |
13 | |
14 Arguments: string | |
15 | |
16 Returns: Python object | |
17 | |
18 Key: Python type object (from types) or class | |
19 | |
20 Conversion function: | |
21 | |
22 Arguments: Python object of indicated type or class AND | |
23 conversion dictionary | |
24 | |
25 Returns: SQL literal value | |
26 | |
15 | 27 Notes: Most conversion functions can ignore the dictionary, but it is a |
28 required parameter. It is necessary for converting things like sequences | |
29 and instances. | |
0 | 30 |
31 Don't modify conversions if you can avoid it. Instead, make copies | |
32 (with the copy() method), modify the copies, and then pass them to | |
33 MySQL.connect(). | |
34 | |
35 """ | |
36 | |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
37 from _mysql import string_literal, escape_sequence, escape_dict, NULL |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
38 from MySQLdb.constants import FIELD_TYPE, FLAG |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
39 from MySQLdb.times import datetime_to_sql, timedelta_to_sql, \ |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
40 timedelta_or_None, datetime_or_None, date_or_None, \ |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
41 mysql_timestamp_converter |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
42 from types import InstanceType |
0 | 43 import array |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
44 import datetime |
49
0a5e28ef7564
decimal module always available in Python 2.4 and newer
adustman
parents:
48
diff
changeset
|
45 from decimal import Decimal |
0 | 46 |
14 | 47 __revision__ = "$Revision$"[11:-2] |
48 __author__ = "$Author$"[9:-2] | |
0 | 49 |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
50 def bool_to_sql(boolean, conv): |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
51 """Convert a Python bool to an SQL literal.""" |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
52 return str(int(boolean)) |
0 | 53 |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
54 def SET_to_Set(value): |
35
e7bd07afbcb9
Conflict-filled merge from 1.2br for 558:559 set and exception fixes
kylev
parents:
15
diff
changeset
|
55 """Convert MySQL SET column to Python set.""" |
e7bd07afbcb9
Conflict-filled merge from 1.2br for 558:559 set and exception fixes
kylev
parents:
15
diff
changeset
|
56 return set([ i for i in value.split(',') if i ]) |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
57 |
35
e7bd07afbcb9
Conflict-filled merge from 1.2br for 558:559 set and exception fixes
kylev
parents:
15
diff
changeset
|
58 def Set_to_sql(value, conv): |
50 | 59 """Convert a Python set to an SQL literal.""" |
35
e7bd07afbcb9
Conflict-filled merge from 1.2br for 558:559 set and exception fixes
kylev
parents:
15
diff
changeset
|
60 return string_literal(','.join(value), conv) |
e7bd07afbcb9
Conflict-filled merge from 1.2br for 558:559 set and exception fixes
kylev
parents:
15
diff
changeset
|
61 |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
62 def object_to_sql(obj, conv): |
0 | 63 """Convert something into a string via str().""" |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
64 return str(obj) |
0 | 65 |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
66 def unicode_to_sql(value, conv): |
0 | 67 """Convert a unicode object to a string using the default encoding. |
68 This is only used as a placeholder for the real function, which | |
69 is connection-dependent.""" | |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
70 assert isinstance(value, unicode) |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
71 return value.encode() |
0 | 72 |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
73 def float_to_sql(value, conv): |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
74 return '%.15g' % value |
0 | 75 |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
76 def None_to_sql(value, conv): |
0 | 77 """Convert None to NULL.""" |
78 return NULL # duh | |
79 | |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
80 def object_to_quoted_sql(obj, conv): |
0 | 81 """Convert something into a SQL string literal. If using |
82 MySQL-3.23 or newer, string_literal() is a method of the | |
83 _mysql.MYSQL object, and this function will be overridden with | |
84 that method when the connection is created.""" | |
85 | |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
86 return string_literal(obj, conv) |
0 | 87 |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
88 def instance_to_sql(obj, conv): |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
89 """Convert an Instance to a string representation. If the __str__() |
0 | 90 method produces acceptable output, then you don't need to add the |
91 class to conversions; it will be handled by the default | |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
92 converter. If the exact class is not found in conv, it will use the |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
93 first class it can find for which obj is an instance. |
0 | 94 """ |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
95 if obj.__class__ in conv: |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
96 return conv[obj.__class__](obj, conv) |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
97 classes = [ key for key in conv.keys() |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
98 if isinstance(obj, key) ] |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
99 if not classes: |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
100 return conv[types.StringType](obj, conv) |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
101 conv[obj.__class__] = conv[classes[0]] |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
102 return conv[classes[0]](obj, conv) |
0 | 103 |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
104 def char_array(obj): |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
105 return array.array('c', obj) |
0 | 106 |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
107 def array_to_sql(obj, conv): |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
108 return object_to_quoted_sql(obj.tostring(), conv) |
0 | 109 |
110 conversions = { | |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
111 int: object_to_sql, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
112 long: object_to_sql, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
113 float: float_to_sql, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
114 type(None): None_to_sql, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
115 tuple: escape_sequence, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
116 list: escape_sequence, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
117 dict: escape_dict, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
118 InstanceType: instance_to_sql, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
119 array.array: array_to_sql, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
120 unicode: unicode_to_sql, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
121 object: instance_to_sql, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
122 bool: bool_to_sql, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
123 datetime.datetime: datetime_to_sql, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
124 datetime.timedelta: timedelta_to_sql, |
35
e7bd07afbcb9
Conflict-filled merge from 1.2br for 558:559 set and exception fixes
kylev
parents:
15
diff
changeset
|
125 set: Set_to_sql, |
12
d68fe80ce1c3
More docstrings and doctests for times and other cleanups.
adustman
parents:
11
diff
changeset
|
126 str: object_to_quoted_sql, # default |
35
e7bd07afbcb9
Conflict-filled merge from 1.2br for 558:559 set and exception fixes
kylev
parents:
15
diff
changeset
|
127 |
57
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
128 } |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
129 |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
130 # This is for MySQL column types that can be converted directly |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
131 # into Python types without having to look at metadata (flags, |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
132 # character sets, etc.). This should always be used as the last |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
133 # resort. |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
134 simple_sql_to_python_conversions = { |
0 | 135 FIELD_TYPE.TINY: int, |
136 FIELD_TYPE.SHORT: int, | |
48
f4fd8c20511c
Read a default file in the test setUp. Since Python 2.4, int() will return longs if needed so make all long references int as in Python 3.0 there is no more long due to int/long unification (new ints are old longs).
adustman
parents:
35
diff
changeset
|
137 FIELD_TYPE.LONG: int, |
0 | 138 FIELD_TYPE.FLOAT: float, |
139 FIELD_TYPE.DOUBLE: float, | |
49
0a5e28ef7564
decimal module always available in Python 2.4 and newer
adustman
parents:
48
diff
changeset
|
140 FIELD_TYPE.DECIMAL: Decimal, |
0a5e28ef7564
decimal module always available in Python 2.4 and newer
adustman
parents:
48
diff
changeset
|
141 FIELD_TYPE.NEWDECIMAL: Decimal, |
48
f4fd8c20511c
Read a default file in the test setUp. Since Python 2.4, int() will return longs if needed so make all long references int as in Python 3.0 there is no more long due to int/long unification (new ints are old longs).
adustman
parents:
35
diff
changeset
|
142 FIELD_TYPE.LONGLONG: int, |
0 | 143 FIELD_TYPE.INT24: int, |
144 FIELD_TYPE.YEAR: int, | |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
145 FIELD_TYPE.SET: SET_to_Set, |
0 | 146 FIELD_TYPE.TIMESTAMP: mysql_timestamp_converter, |
11
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
147 FIELD_TYPE.DATETIME: datetime_or_None, |
aef6ea6a9737
More PyLint-inspired cleanups. Added a bunch of doctests in times.
adustman
parents:
5
diff
changeset
|
148 FIELD_TYPE.TIME: timedelta_or_None, |
57
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
149 FIELD_TYPE.DATE: date_or_None, |
0 | 150 } |
151 | |
57
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
152 # Converter plugin protocol |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
153 # Each plugin is passed a cursor object and a field object. |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
154 # The plugin returns a single value: |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
155 # A callable that given an SQL value, returns a Python object. |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
156 # This can be as simple as int or str, etc. If the plugin |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
157 # returns None, this plugin will be ignored and the next plugin |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
158 # on the stack will be checked. |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
159 |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
160 def filter_NULL(f): |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
161 def _filter_NULL(o): |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
162 if o is None: return o |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
163 return f(o) |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
164 _filter_NULL.__name__ = f.__name__ |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
165 return _filter_NULL |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
166 |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
167 def sql_to_python_last_resort_plugin(cursor, field): |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
168 return str |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
169 |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
170 def simple_sql_to_python_plugin(cursor, field): |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
171 return simple_sql_to_python_conversions.get(field.type, None) |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
172 |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
173 character_types = [ |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
174 FIELD_TYPE.BLOB, |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
175 FIELD_TYPE.STRING, |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
176 FIELD_TYPE.VAR_STRING, |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
177 FIELD_TYPE.VARCHAR, |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
178 ] |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
179 |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
180 def character_sql_to_python_plugin(cursor, field): |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
181 if field.type not in character_types: |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
182 return None |
59
5db99d9be0fb
Fix #2663436: Character fields with a binary character set should be returned as str, else unicode.
adustman
parents:
57
diff
changeset
|
183 if field.charsetnr == 63: |
57
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
184 return str |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
185 |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
186 charset = cursor.connection.character_set_name() |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
187 def char_to_unicode(s): |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
188 return s.decode(charset) |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
189 |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
190 return char_to_unicode |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
191 |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
192 sql_to_python_plugins = [ |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
193 character_sql_to_python_plugin, |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
194 simple_sql_to_python_plugin, |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
195 sql_to_python_last_resort_plugin, |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
196 ] |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
197 |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
198 def lookup_converter(cursor, field): |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
199 for plugin in sql_to_python_plugins: |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
200 f = plugin(cursor, field) |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
201 if f: |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
202 return filter_NULL(f) |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
203 return None # this should never happen |
9ea2b0e9302e
The pure Python SQL-to-Python conversion code. TODO: There should be a way to register plugins in the module and in the connection.
adustman
parents:
51
diff
changeset
|
204 |
0 | 205 |
206 | |
207 |