SQLAlchemy 2.0.36__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. SQLAlchemy-2.0.36.dist-info/LICENSE +19 -0
  2. SQLAlchemy-2.0.36.dist-info/METADATA +243 -0
  3. SQLAlchemy-2.0.36.dist-info/RECORD +273 -0
  4. SQLAlchemy-2.0.36.dist-info/WHEEL +5 -0
  5. SQLAlchemy-2.0.36.dist-info/top_level.txt +1 -0
  6. sqlalchemy/__init__.py +294 -0
  7. sqlalchemy/connectors/__init__.py +18 -0
  8. sqlalchemy/connectors/aioodbc.py +174 -0
  9. sqlalchemy/connectors/asyncio.py +213 -0
  10. sqlalchemy/connectors/pyodbc.py +249 -0
  11. sqlalchemy/cyextension/__init__.py +6 -0
  12. sqlalchemy/cyextension/collections.cp313-win_amd64.pyd +0 -0
  13. sqlalchemy/cyextension/collections.pyx +409 -0
  14. sqlalchemy/cyextension/immutabledict.cp313-win_amd64.pyd +0 -0
  15. sqlalchemy/cyextension/immutabledict.pxd +8 -0
  16. sqlalchemy/cyextension/immutabledict.pyx +133 -0
  17. sqlalchemy/cyextension/processors.cp313-win_amd64.pyd +0 -0
  18. sqlalchemy/cyextension/processors.pyx +68 -0
  19. sqlalchemy/cyextension/resultproxy.cp313-win_amd64.pyd +0 -0
  20. sqlalchemy/cyextension/resultproxy.pyx +102 -0
  21. sqlalchemy/cyextension/util.cp313-win_amd64.pyd +0 -0
  22. sqlalchemy/cyextension/util.pyx +91 -0
  23. sqlalchemy/dialects/__init__.py +61 -0
  24. sqlalchemy/dialects/_typing.py +25 -0
  25. sqlalchemy/dialects/mssql/__init__.py +88 -0
  26. sqlalchemy/dialects/mssql/aioodbc.py +64 -0
  27. sqlalchemy/dialects/mssql/base.py +4010 -0
  28. sqlalchemy/dialects/mssql/information_schema.py +254 -0
  29. sqlalchemy/dialects/mssql/json.py +133 -0
  30. sqlalchemy/dialects/mssql/provision.py +162 -0
  31. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  32. sqlalchemy/dialects/mssql/pyodbc.py +745 -0
  33. sqlalchemy/dialects/mysql/__init__.py +101 -0
  34. sqlalchemy/dialects/mysql/aiomysql.py +333 -0
  35. sqlalchemy/dialects/mysql/asyncmy.py +337 -0
  36. sqlalchemy/dialects/mysql/base.py +3494 -0
  37. sqlalchemy/dialects/mysql/cymysql.py +84 -0
  38. sqlalchemy/dialects/mysql/dml.py +219 -0
  39. sqlalchemy/dialects/mysql/enumerated.py +244 -0
  40. sqlalchemy/dialects/mysql/expression.py +141 -0
  41. sqlalchemy/dialects/mysql/json.py +81 -0
  42. sqlalchemy/dialects/mysql/mariadb.py +32 -0
  43. sqlalchemy/dialects/mysql/mariadbconnector.py +277 -0
  44. sqlalchemy/dialects/mysql/mysqlconnector.py +180 -0
  45. sqlalchemy/dialects/mysql/mysqldb.py +303 -0
  46. sqlalchemy/dialects/mysql/provision.py +110 -0
  47. sqlalchemy/dialects/mysql/pymysql.py +137 -0
  48. sqlalchemy/dialects/mysql/pyodbc.py +138 -0
  49. sqlalchemy/dialects/mysql/reflection.py +677 -0
  50. sqlalchemy/dialects/mysql/reserved_words.py +571 -0
  51. sqlalchemy/dialects/mysql/types.py +774 -0
  52. sqlalchemy/dialects/oracle/__init__.py +67 -0
  53. sqlalchemy/dialects/oracle/base.py +3271 -0
  54. sqlalchemy/dialects/oracle/cx_oracle.py +1483 -0
  55. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  56. sqlalchemy/dialects/oracle/oracledb.py +431 -0
  57. sqlalchemy/dialects/oracle/provision.py +220 -0
  58. sqlalchemy/dialects/oracle/types.py +287 -0
  59. sqlalchemy/dialects/postgresql/__init__.py +167 -0
  60. sqlalchemy/dialects/postgresql/_psycopg_common.py +187 -0
  61. sqlalchemy/dialects/postgresql/array.py +425 -0
  62. sqlalchemy/dialects/postgresql/asyncpg.py +1274 -0
  63. sqlalchemy/dialects/postgresql/base.py +5008 -0
  64. sqlalchemy/dialects/postgresql/dml.py +310 -0
  65. sqlalchemy/dialects/postgresql/ext.py +496 -0
  66. sqlalchemy/dialects/postgresql/hstore.py +397 -0
  67. sqlalchemy/dialects/postgresql/json.py +333 -0
  68. sqlalchemy/dialects/postgresql/named_types.py +509 -0
  69. sqlalchemy/dialects/postgresql/operators.py +129 -0
  70. sqlalchemy/dialects/postgresql/pg8000.py +662 -0
  71. sqlalchemy/dialects/postgresql/pg_catalog.py +300 -0
  72. sqlalchemy/dialects/postgresql/provision.py +175 -0
  73. sqlalchemy/dialects/postgresql/psycopg.py +772 -0
  74. sqlalchemy/dialects/postgresql/psycopg2.py +886 -0
  75. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  76. sqlalchemy/dialects/postgresql/ranges.py +1029 -0
  77. sqlalchemy/dialects/postgresql/types.py +303 -0
  78. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  79. sqlalchemy/dialects/sqlite/aiosqlite.py +396 -0
  80. sqlalchemy/dialects/sqlite/base.py +2805 -0
  81. sqlalchemy/dialects/sqlite/dml.py +240 -0
  82. sqlalchemy/dialects/sqlite/json.py +92 -0
  83. sqlalchemy/dialects/sqlite/provision.py +198 -0
  84. sqlalchemy/dialects/sqlite/pysqlcipher.py +155 -0
  85. sqlalchemy/dialects/sqlite/pysqlite.py +756 -0
  86. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  87. sqlalchemy/engine/__init__.py +62 -0
  88. sqlalchemy/engine/_py_processors.py +136 -0
  89. sqlalchemy/engine/_py_row.py +128 -0
  90. sqlalchemy/engine/_py_util.py +74 -0
  91. sqlalchemy/engine/base.py +3375 -0
  92. sqlalchemy/engine/characteristics.py +155 -0
  93. sqlalchemy/engine/create.py +875 -0
  94. sqlalchemy/engine/cursor.py +2181 -0
  95. sqlalchemy/engine/default.py +2365 -0
  96. sqlalchemy/engine/events.py +951 -0
  97. sqlalchemy/engine/interfaces.py +3403 -0
  98. sqlalchemy/engine/mock.py +131 -0
  99. sqlalchemy/engine/processors.py +61 -0
  100. sqlalchemy/engine/reflection.py +2098 -0
  101. sqlalchemy/engine/result.py +2382 -0
  102. sqlalchemy/engine/row.py +401 -0
  103. sqlalchemy/engine/strategies.py +19 -0
  104. sqlalchemy/engine/url.py +910 -0
  105. sqlalchemy/engine/util.py +167 -0
  106. sqlalchemy/event/__init__.py +25 -0
  107. sqlalchemy/event/api.py +225 -0
  108. sqlalchemy/event/attr.py +655 -0
  109. sqlalchemy/event/base.py +470 -0
  110. sqlalchemy/event/legacy.py +246 -0
  111. sqlalchemy/event/registry.py +386 -0
  112. sqlalchemy/events.py +17 -0
  113. sqlalchemy/exc.py +830 -0
  114. sqlalchemy/ext/__init__.py +11 -0
  115. sqlalchemy/ext/associationproxy.py +2013 -0
  116. sqlalchemy/ext/asyncio/__init__.py +25 -0
  117. sqlalchemy/ext/asyncio/base.py +279 -0
  118. sqlalchemy/ext/asyncio/engine.py +1466 -0
  119. sqlalchemy/ext/asyncio/exc.py +21 -0
  120. sqlalchemy/ext/asyncio/result.py +961 -0
  121. sqlalchemy/ext/asyncio/scoping.py +1614 -0
  122. sqlalchemy/ext/asyncio/session.py +1936 -0
  123. sqlalchemy/ext/automap.py +1691 -0
  124. sqlalchemy/ext/baked.py +574 -0
  125. sqlalchemy/ext/compiler.py +570 -0
  126. sqlalchemy/ext/declarative/__init__.py +65 -0
  127. sqlalchemy/ext/declarative/extensions.py +548 -0
  128. sqlalchemy/ext/horizontal_shard.py +481 -0
  129. sqlalchemy/ext/hybrid.py +1514 -0
  130. sqlalchemy/ext/indexable.py +341 -0
  131. sqlalchemy/ext/instrumentation.py +450 -0
  132. sqlalchemy/ext/mutable.py +1073 -0
  133. sqlalchemy/ext/mypy/__init__.py +6 -0
  134. sqlalchemy/ext/mypy/apply.py +320 -0
  135. sqlalchemy/ext/mypy/decl_class.py +515 -0
  136. sqlalchemy/ext/mypy/infer.py +590 -0
  137. sqlalchemy/ext/mypy/names.py +335 -0
  138. sqlalchemy/ext/mypy/plugin.py +303 -0
  139. sqlalchemy/ext/mypy/util.py +357 -0
  140. sqlalchemy/ext/orderinglist.py +416 -0
  141. sqlalchemy/ext/serializer.py +181 -0
  142. sqlalchemy/future/__init__.py +16 -0
  143. sqlalchemy/future/engine.py +15 -0
  144. sqlalchemy/inspection.py +174 -0
  145. sqlalchemy/log.py +288 -0
  146. sqlalchemy/orm/__init__.py +170 -0
  147. sqlalchemy/orm/_orm_constructors.py +2571 -0
  148. sqlalchemy/orm/_typing.py +179 -0
  149. sqlalchemy/orm/attributes.py +2835 -0
  150. sqlalchemy/orm/base.py +973 -0
  151. sqlalchemy/orm/bulk_persistence.py +2123 -0
  152. sqlalchemy/orm/clsregistry.py +571 -0
  153. sqlalchemy/orm/collections.py +1620 -0
  154. sqlalchemy/orm/context.py +3268 -0
  155. sqlalchemy/orm/decl_api.py +1883 -0
  156. sqlalchemy/orm/decl_base.py +2190 -0
  157. sqlalchemy/orm/dependency.py +1304 -0
  158. sqlalchemy/orm/descriptor_props.py +1076 -0
  159. sqlalchemy/orm/dynamic.py +300 -0
  160. sqlalchemy/orm/evaluator.py +379 -0
  161. sqlalchemy/orm/events.py +3261 -0
  162. sqlalchemy/orm/exc.py +228 -0
  163. sqlalchemy/orm/identity.py +302 -0
  164. sqlalchemy/orm/instrumentation.py +754 -0
  165. sqlalchemy/orm/interfaces.py +1474 -0
  166. sqlalchemy/orm/loading.py +1682 -0
  167. sqlalchemy/orm/mapped_collection.py +557 -0
  168. sqlalchemy/orm/mapper.py +4432 -0
  169. sqlalchemy/orm/path_registry.py +811 -0
  170. sqlalchemy/orm/persistence.py +1782 -0
  171. sqlalchemy/orm/properties.py +886 -0
  172. sqlalchemy/orm/query.py +3396 -0
  173. sqlalchemy/orm/relationships.py +3500 -0
  174. sqlalchemy/orm/scoping.py +2165 -0
  175. sqlalchemy/orm/session.py +5301 -0
  176. sqlalchemy/orm/state.py +1143 -0
  177. sqlalchemy/orm/state_changes.py +198 -0
  178. sqlalchemy/orm/strategies.py +3473 -0
  179. sqlalchemy/orm/strategy_options.py +2569 -0
  180. sqlalchemy/orm/sync.py +164 -0
  181. sqlalchemy/orm/unitofwork.py +796 -0
  182. sqlalchemy/orm/util.py +2424 -0
  183. sqlalchemy/orm/writeonly.py +678 -0
  184. sqlalchemy/pool/__init__.py +44 -0
  185. sqlalchemy/pool/base.py +1515 -0
  186. sqlalchemy/pool/events.py +370 -0
  187. sqlalchemy/pool/impl.py +581 -0
  188. sqlalchemy/py.typed +0 -0
  189. sqlalchemy/schema.py +70 -0
  190. sqlalchemy/sql/__init__.py +145 -0
  191. sqlalchemy/sql/_dml_constructors.py +140 -0
  192. sqlalchemy/sql/_elements_constructors.py +1850 -0
  193. sqlalchemy/sql/_orm_types.py +20 -0
  194. sqlalchemy/sql/_py_util.py +75 -0
  195. sqlalchemy/sql/_selectable_constructors.py +635 -0
  196. sqlalchemy/sql/_typing.py +460 -0
  197. sqlalchemy/sql/annotation.py +585 -0
  198. sqlalchemy/sql/base.py +2185 -0
  199. sqlalchemy/sql/cache_key.py +1057 -0
  200. sqlalchemy/sql/coercions.py +1405 -0
  201. sqlalchemy/sql/compiler.py +7818 -0
  202. sqlalchemy/sql/crud.py +1669 -0
  203. sqlalchemy/sql/ddl.py +1378 -0
  204. sqlalchemy/sql/default_comparator.py +552 -0
  205. sqlalchemy/sql/dml.py +1817 -0
  206. sqlalchemy/sql/elements.py +5499 -0
  207. sqlalchemy/sql/events.py +455 -0
  208. sqlalchemy/sql/expression.py +162 -0
  209. sqlalchemy/sql/functions.py +2055 -0
  210. sqlalchemy/sql/lambdas.py +1449 -0
  211. sqlalchemy/sql/naming.py +212 -0
  212. sqlalchemy/sql/operators.py +2579 -0
  213. sqlalchemy/sql/roles.py +323 -0
  214. sqlalchemy/sql/schema.py +6158 -0
  215. sqlalchemy/sql/selectable.py +7004 -0
  216. sqlalchemy/sql/sqltypes.py +3827 -0
  217. sqlalchemy/sql/traversals.py +1024 -0
  218. sqlalchemy/sql/type_api.py +2339 -0
  219. sqlalchemy/sql/util.py +1486 -0
  220. sqlalchemy/sql/visitors.py +1165 -0
  221. sqlalchemy/testing/__init__.py +96 -0
  222. sqlalchemy/testing/assertions.py +989 -0
  223. sqlalchemy/testing/assertsql.py +516 -0
  224. sqlalchemy/testing/asyncio.py +135 -0
  225. sqlalchemy/testing/config.py +427 -0
  226. sqlalchemy/testing/engines.py +472 -0
  227. sqlalchemy/testing/entities.py +117 -0
  228. sqlalchemy/testing/exclusions.py +435 -0
  229. sqlalchemy/testing/fixtures/__init__.py +28 -0
  230. sqlalchemy/testing/fixtures/base.py +366 -0
  231. sqlalchemy/testing/fixtures/mypy.py +312 -0
  232. sqlalchemy/testing/fixtures/orm.py +227 -0
  233. sqlalchemy/testing/fixtures/sql.py +503 -0
  234. sqlalchemy/testing/pickleable.py +155 -0
  235. sqlalchemy/testing/plugin/__init__.py +6 -0
  236. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  237. sqlalchemy/testing/plugin/plugin_base.py +779 -0
  238. sqlalchemy/testing/plugin/pytestplugin.py +868 -0
  239. sqlalchemy/testing/profiling.py +324 -0
  240. sqlalchemy/testing/provision.py +496 -0
  241. sqlalchemy/testing/requirements.py +1818 -0
  242. sqlalchemy/testing/schema.py +224 -0
  243. sqlalchemy/testing/suite/__init__.py +19 -0
  244. sqlalchemy/testing/suite/test_cte.py +211 -0
  245. sqlalchemy/testing/suite/test_ddl.py +389 -0
  246. sqlalchemy/testing/suite/test_deprecations.py +153 -0
  247. sqlalchemy/testing/suite/test_dialect.py +740 -0
  248. sqlalchemy/testing/suite/test_insert.py +630 -0
  249. sqlalchemy/testing/suite/test_reflection.py +3225 -0
  250. sqlalchemy/testing/suite/test_results.py +502 -0
  251. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  252. sqlalchemy/testing/suite/test_select.py +1999 -0
  253. sqlalchemy/testing/suite/test_sequence.py +317 -0
  254. sqlalchemy/testing/suite/test_types.py +2141 -0
  255. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  256. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  257. sqlalchemy/testing/util.py +537 -0
  258. sqlalchemy/testing/warnings.py +52 -0
  259. sqlalchemy/types.py +76 -0
  260. sqlalchemy/util/__init__.py +160 -0
  261. sqlalchemy/util/_collections.py +715 -0
  262. sqlalchemy/util/_concurrency_py3k.py +288 -0
  263. sqlalchemy/util/_has_cy.py +40 -0
  264. sqlalchemy/util/_py_collections.py +541 -0
  265. sqlalchemy/util/compat.py +301 -0
  266. sqlalchemy/util/concurrency.py +108 -0
  267. sqlalchemy/util/deprecations.py +401 -0
  268. sqlalchemy/util/langhelpers.py +2218 -0
  269. sqlalchemy/util/preloaded.py +150 -0
  270. sqlalchemy/util/queue.py +322 -0
  271. sqlalchemy/util/tool_support.py +201 -0
  272. sqlalchemy/util/topological.py +120 -0
  273. sqlalchemy/util/typing.py +629 -0
@@ -0,0 +1,774 @@
1
+ # dialects/mysql/types.py
2
+ # Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
3
+ # <see AUTHORS file>
4
+ #
5
+ # This module is part of SQLAlchemy and is released under
6
+ # the MIT License: https://www.opensource.org/licenses/mit-license.php
7
+ # mypy: ignore-errors
8
+
9
+
10
+ import datetime
11
+
12
+ from ... import exc
13
+ from ... import util
14
+ from ...sql import sqltypes
15
+
16
+
17
+ class _NumericType:
18
+ """Base for MySQL numeric types.
19
+
20
+ This is the base both for NUMERIC as well as INTEGER, hence
21
+ it's a mixin.
22
+
23
+ """
24
+
25
+ def __init__(self, unsigned=False, zerofill=False, **kw):
26
+ self.unsigned = unsigned
27
+ self.zerofill = zerofill
28
+ super().__init__(**kw)
29
+
30
+ def __repr__(self):
31
+ return util.generic_repr(
32
+ self, to_inspect=[_NumericType, sqltypes.Numeric]
33
+ )
34
+
35
+
36
+ class _FloatType(_NumericType, sqltypes.Float):
37
+ def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
38
+ if isinstance(self, (REAL, DOUBLE)) and (
39
+ (precision is None and scale is not None)
40
+ or (precision is not None and scale is None)
41
+ ):
42
+ raise exc.ArgumentError(
43
+ "You must specify both precision and scale or omit "
44
+ "both altogether."
45
+ )
46
+ super().__init__(precision=precision, asdecimal=asdecimal, **kw)
47
+ self.scale = scale
48
+
49
+ def __repr__(self):
50
+ return util.generic_repr(
51
+ self, to_inspect=[_FloatType, _NumericType, sqltypes.Float]
52
+ )
53
+
54
+
55
+ class _IntegerType(_NumericType, sqltypes.Integer):
56
+ def __init__(self, display_width=None, **kw):
57
+ self.display_width = display_width
58
+ super().__init__(**kw)
59
+
60
+ def __repr__(self):
61
+ return util.generic_repr(
62
+ self, to_inspect=[_IntegerType, _NumericType, sqltypes.Integer]
63
+ )
64
+
65
+
66
+ class _StringType(sqltypes.String):
67
+ """Base for MySQL string types."""
68
+
69
+ def __init__(
70
+ self,
71
+ charset=None,
72
+ collation=None,
73
+ ascii=False, # noqa
74
+ binary=False,
75
+ unicode=False,
76
+ national=False,
77
+ **kw,
78
+ ):
79
+ self.charset = charset
80
+
81
+ # allow collate= or collation=
82
+ kw.setdefault("collation", kw.pop("collate", collation))
83
+
84
+ self.ascii = ascii
85
+ self.unicode = unicode
86
+ self.binary = binary
87
+ self.national = national
88
+ super().__init__(**kw)
89
+
90
+ def __repr__(self):
91
+ return util.generic_repr(
92
+ self, to_inspect=[_StringType, sqltypes.String]
93
+ )
94
+
95
+
96
+ class _MatchType(sqltypes.Float, sqltypes.MatchType):
97
+ def __init__(self, **kw):
98
+ # TODO: float arguments?
99
+ sqltypes.Float.__init__(self)
100
+ sqltypes.MatchType.__init__(self)
101
+
102
+
103
+ class NUMERIC(_NumericType, sqltypes.NUMERIC):
104
+ """MySQL NUMERIC type."""
105
+
106
+ __visit_name__ = "NUMERIC"
107
+
108
+ def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
109
+ """Construct a NUMERIC.
110
+
111
+ :param precision: Total digits in this number. If scale and precision
112
+ are both None, values are stored to limits allowed by the server.
113
+
114
+ :param scale: The number of digits after the decimal point.
115
+
116
+ :param unsigned: a boolean, optional.
117
+
118
+ :param zerofill: Optional. If true, values will be stored as strings
119
+ left-padded with zeros. Note that this does not effect the values
120
+ returned by the underlying database API, which continue to be
121
+ numeric.
122
+
123
+ """
124
+ super().__init__(
125
+ precision=precision, scale=scale, asdecimal=asdecimal, **kw
126
+ )
127
+
128
+
129
+ class DECIMAL(_NumericType, sqltypes.DECIMAL):
130
+ """MySQL DECIMAL type."""
131
+
132
+ __visit_name__ = "DECIMAL"
133
+
134
+ def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
135
+ """Construct a DECIMAL.
136
+
137
+ :param precision: Total digits in this number. If scale and precision
138
+ are both None, values are stored to limits allowed by the server.
139
+
140
+ :param scale: The number of digits after the decimal point.
141
+
142
+ :param unsigned: a boolean, optional.
143
+
144
+ :param zerofill: Optional. If true, values will be stored as strings
145
+ left-padded with zeros. Note that this does not effect the values
146
+ returned by the underlying database API, which continue to be
147
+ numeric.
148
+
149
+ """
150
+ super().__init__(
151
+ precision=precision, scale=scale, asdecimal=asdecimal, **kw
152
+ )
153
+
154
+
155
+ class DOUBLE(_FloatType, sqltypes.DOUBLE):
156
+ """MySQL DOUBLE type."""
157
+
158
+ __visit_name__ = "DOUBLE"
159
+
160
+ def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
161
+ """Construct a DOUBLE.
162
+
163
+ .. note::
164
+
165
+ The :class:`.DOUBLE` type by default converts from float
166
+ to Decimal, using a truncation that defaults to 10 digits.
167
+ Specify either ``scale=n`` or ``decimal_return_scale=n`` in order
168
+ to change this scale, or ``asdecimal=False`` to return values
169
+ directly as Python floating points.
170
+
171
+ :param precision: Total digits in this number. If scale and precision
172
+ are both None, values are stored to limits allowed by the server.
173
+
174
+ :param scale: The number of digits after the decimal point.
175
+
176
+ :param unsigned: a boolean, optional.
177
+
178
+ :param zerofill: Optional. If true, values will be stored as strings
179
+ left-padded with zeros. Note that this does not effect the values
180
+ returned by the underlying database API, which continue to be
181
+ numeric.
182
+
183
+ """
184
+ super().__init__(
185
+ precision=precision, scale=scale, asdecimal=asdecimal, **kw
186
+ )
187
+
188
+
189
+ class REAL(_FloatType, sqltypes.REAL):
190
+ """MySQL REAL type."""
191
+
192
+ __visit_name__ = "REAL"
193
+
194
+ def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
195
+ """Construct a REAL.
196
+
197
+ .. note::
198
+
199
+ The :class:`.REAL` type by default converts from float
200
+ to Decimal, using a truncation that defaults to 10 digits.
201
+ Specify either ``scale=n`` or ``decimal_return_scale=n`` in order
202
+ to change this scale, or ``asdecimal=False`` to return values
203
+ directly as Python floating points.
204
+
205
+ :param precision: Total digits in this number. If scale and precision
206
+ are both None, values are stored to limits allowed by the server.
207
+
208
+ :param scale: The number of digits after the decimal point.
209
+
210
+ :param unsigned: a boolean, optional.
211
+
212
+ :param zerofill: Optional. If true, values will be stored as strings
213
+ left-padded with zeros. Note that this does not effect the values
214
+ returned by the underlying database API, which continue to be
215
+ numeric.
216
+
217
+ """
218
+ super().__init__(
219
+ precision=precision, scale=scale, asdecimal=asdecimal, **kw
220
+ )
221
+
222
+
223
+ class FLOAT(_FloatType, sqltypes.FLOAT):
224
+ """MySQL FLOAT type."""
225
+
226
+ __visit_name__ = "FLOAT"
227
+
228
+ def __init__(self, precision=None, scale=None, asdecimal=False, **kw):
229
+ """Construct a FLOAT.
230
+
231
+ :param precision: Total digits in this number. If scale and precision
232
+ are both None, values are stored to limits allowed by the server.
233
+
234
+ :param scale: The number of digits after the decimal point.
235
+
236
+ :param unsigned: a boolean, optional.
237
+
238
+ :param zerofill: Optional. If true, values will be stored as strings
239
+ left-padded with zeros. Note that this does not effect the values
240
+ returned by the underlying database API, which continue to be
241
+ numeric.
242
+
243
+ """
244
+ super().__init__(
245
+ precision=precision, scale=scale, asdecimal=asdecimal, **kw
246
+ )
247
+
248
+ def bind_processor(self, dialect):
249
+ return None
250
+
251
+
252
+ class INTEGER(_IntegerType, sqltypes.INTEGER):
253
+ """MySQL INTEGER type."""
254
+
255
+ __visit_name__ = "INTEGER"
256
+
257
+ def __init__(self, display_width=None, **kw):
258
+ """Construct an INTEGER.
259
+
260
+ :param display_width: Optional, maximum display width for this number.
261
+
262
+ :param unsigned: a boolean, optional.
263
+
264
+ :param zerofill: Optional. If true, values will be stored as strings
265
+ left-padded with zeros. Note that this does not effect the values
266
+ returned by the underlying database API, which continue to be
267
+ numeric.
268
+
269
+ """
270
+ super().__init__(display_width=display_width, **kw)
271
+
272
+
273
+ class BIGINT(_IntegerType, sqltypes.BIGINT):
274
+ """MySQL BIGINTEGER type."""
275
+
276
+ __visit_name__ = "BIGINT"
277
+
278
+ def __init__(self, display_width=None, **kw):
279
+ """Construct a BIGINTEGER.
280
+
281
+ :param display_width: Optional, maximum display width for this number.
282
+
283
+ :param unsigned: a boolean, optional.
284
+
285
+ :param zerofill: Optional. If true, values will be stored as strings
286
+ left-padded with zeros. Note that this does not effect the values
287
+ returned by the underlying database API, which continue to be
288
+ numeric.
289
+
290
+ """
291
+ super().__init__(display_width=display_width, **kw)
292
+
293
+
294
+ class MEDIUMINT(_IntegerType):
295
+ """MySQL MEDIUMINTEGER type."""
296
+
297
+ __visit_name__ = "MEDIUMINT"
298
+
299
+ def __init__(self, display_width=None, **kw):
300
+ """Construct a MEDIUMINTEGER
301
+
302
+ :param display_width: Optional, maximum display width for this number.
303
+
304
+ :param unsigned: a boolean, optional.
305
+
306
+ :param zerofill: Optional. If true, values will be stored as strings
307
+ left-padded with zeros. Note that this does not effect the values
308
+ returned by the underlying database API, which continue to be
309
+ numeric.
310
+
311
+ """
312
+ super().__init__(display_width=display_width, **kw)
313
+
314
+
315
+ class TINYINT(_IntegerType):
316
+ """MySQL TINYINT type."""
317
+
318
+ __visit_name__ = "TINYINT"
319
+
320
+ def __init__(self, display_width=None, **kw):
321
+ """Construct a TINYINT.
322
+
323
+ :param display_width: Optional, maximum display width for this number.
324
+
325
+ :param unsigned: a boolean, optional.
326
+
327
+ :param zerofill: Optional. If true, values will be stored as strings
328
+ left-padded with zeros. Note that this does not effect the values
329
+ returned by the underlying database API, which continue to be
330
+ numeric.
331
+
332
+ """
333
+ super().__init__(display_width=display_width, **kw)
334
+
335
+
336
+ class SMALLINT(_IntegerType, sqltypes.SMALLINT):
337
+ """MySQL SMALLINTEGER type."""
338
+
339
+ __visit_name__ = "SMALLINT"
340
+
341
+ def __init__(self, display_width=None, **kw):
342
+ """Construct a SMALLINTEGER.
343
+
344
+ :param display_width: Optional, maximum display width for this number.
345
+
346
+ :param unsigned: a boolean, optional.
347
+
348
+ :param zerofill: Optional. If true, values will be stored as strings
349
+ left-padded with zeros. Note that this does not effect the values
350
+ returned by the underlying database API, which continue to be
351
+ numeric.
352
+
353
+ """
354
+ super().__init__(display_width=display_width, **kw)
355
+
356
+
357
+ class BIT(sqltypes.TypeEngine):
358
+ """MySQL BIT type.
359
+
360
+ This type is for MySQL 5.0.3 or greater for MyISAM, and 5.0.5 or greater
361
+ for MyISAM, MEMORY, InnoDB and BDB. For older versions, use a
362
+ MSTinyInteger() type.
363
+
364
+ """
365
+
366
+ __visit_name__ = "BIT"
367
+
368
+ def __init__(self, length=None):
369
+ """Construct a BIT.
370
+
371
+ :param length: Optional, number of bits.
372
+
373
+ """
374
+ self.length = length
375
+
376
+ def result_processor(self, dialect, coltype):
377
+ """Convert a MySQL's 64 bit, variable length binary string to a long.
378
+
379
+ TODO: this is MySQL-db, pyodbc specific. OurSQL and mysqlconnector
380
+ already do this, so this logic should be moved to those dialects.
381
+
382
+ """
383
+
384
+ def process(value):
385
+ if value is not None:
386
+ v = 0
387
+ for i in value:
388
+ if not isinstance(i, int):
389
+ i = ord(i) # convert byte to int on Python 2
390
+ v = v << 8 | i
391
+ return v
392
+ return value
393
+
394
+ return process
395
+
396
+
397
+ class TIME(sqltypes.TIME):
398
+ """MySQL TIME type."""
399
+
400
+ __visit_name__ = "TIME"
401
+
402
+ def __init__(self, timezone=False, fsp=None):
403
+ """Construct a MySQL TIME type.
404
+
405
+ :param timezone: not used by the MySQL dialect.
406
+ :param fsp: fractional seconds precision value.
407
+ MySQL 5.6 supports storage of fractional seconds;
408
+ this parameter will be used when emitting DDL
409
+ for the TIME type.
410
+
411
+ .. note::
412
+
413
+ DBAPI driver support for fractional seconds may
414
+ be limited; current support includes
415
+ MySQL Connector/Python.
416
+
417
+ """
418
+ super().__init__(timezone=timezone)
419
+ self.fsp = fsp
420
+
421
+ def result_processor(self, dialect, coltype):
422
+ time = datetime.time
423
+
424
+ def process(value):
425
+ # convert from a timedelta value
426
+ if value is not None:
427
+ microseconds = value.microseconds
428
+ seconds = value.seconds
429
+ minutes = seconds // 60
430
+ return time(
431
+ minutes // 60,
432
+ minutes % 60,
433
+ seconds - minutes * 60,
434
+ microsecond=microseconds,
435
+ )
436
+ else:
437
+ return None
438
+
439
+ return process
440
+
441
+
442
+ class TIMESTAMP(sqltypes.TIMESTAMP):
443
+ """MySQL TIMESTAMP type."""
444
+
445
+ __visit_name__ = "TIMESTAMP"
446
+
447
+ def __init__(self, timezone=False, fsp=None):
448
+ """Construct a MySQL TIMESTAMP type.
449
+
450
+ :param timezone: not used by the MySQL dialect.
451
+ :param fsp: fractional seconds precision value.
452
+ MySQL 5.6.4 supports storage of fractional seconds;
453
+ this parameter will be used when emitting DDL
454
+ for the TIMESTAMP type.
455
+
456
+ .. note::
457
+
458
+ DBAPI driver support for fractional seconds may
459
+ be limited; current support includes
460
+ MySQL Connector/Python.
461
+
462
+ """
463
+ super().__init__(timezone=timezone)
464
+ self.fsp = fsp
465
+
466
+
467
+ class DATETIME(sqltypes.DATETIME):
468
+ """MySQL DATETIME type."""
469
+
470
+ __visit_name__ = "DATETIME"
471
+
472
+ def __init__(self, timezone=False, fsp=None):
473
+ """Construct a MySQL DATETIME type.
474
+
475
+ :param timezone: not used by the MySQL dialect.
476
+ :param fsp: fractional seconds precision value.
477
+ MySQL 5.6.4 supports storage of fractional seconds;
478
+ this parameter will be used when emitting DDL
479
+ for the DATETIME type.
480
+
481
+ .. note::
482
+
483
+ DBAPI driver support for fractional seconds may
484
+ be limited; current support includes
485
+ MySQL Connector/Python.
486
+
487
+ """
488
+ super().__init__(timezone=timezone)
489
+ self.fsp = fsp
490
+
491
+
492
+ class YEAR(sqltypes.TypeEngine):
493
+ """MySQL YEAR type, for single byte storage of years 1901-2155."""
494
+
495
+ __visit_name__ = "YEAR"
496
+
497
+ def __init__(self, display_width=None):
498
+ self.display_width = display_width
499
+
500
+
501
+ class TEXT(_StringType, sqltypes.TEXT):
502
+ """MySQL TEXT type, for character storage encoded up to 2^16 bytes."""
503
+
504
+ __visit_name__ = "TEXT"
505
+
506
+ def __init__(self, length=None, **kw):
507
+ """Construct a TEXT.
508
+
509
+ :param length: Optional, if provided the server may optimize storage
510
+ by substituting the smallest TEXT type sufficient to store
511
+ ``length`` bytes of characters.
512
+
513
+ :param charset: Optional, a column-level character set for this string
514
+ value. Takes precedence to 'ascii' or 'unicode' short-hand.
515
+
516
+ :param collation: Optional, a column-level collation for this string
517
+ value. Takes precedence to 'binary' short-hand.
518
+
519
+ :param ascii: Defaults to False: short-hand for the ``latin1``
520
+ character set, generates ASCII in schema.
521
+
522
+ :param unicode: Defaults to False: short-hand for the ``ucs2``
523
+ character set, generates UNICODE in schema.
524
+
525
+ :param national: Optional. If true, use the server's configured
526
+ national character set.
527
+
528
+ :param binary: Defaults to False: short-hand, pick the binary
529
+ collation type that matches the column's character set. Generates
530
+ BINARY in schema. This does not affect the type of data stored,
531
+ only the collation of character data.
532
+
533
+ """
534
+ super().__init__(length=length, **kw)
535
+
536
+
537
+ class TINYTEXT(_StringType):
538
+ """MySQL TINYTEXT type, for character storage encoded up to 2^8 bytes."""
539
+
540
+ __visit_name__ = "TINYTEXT"
541
+
542
+ def __init__(self, **kwargs):
543
+ """Construct a TINYTEXT.
544
+
545
+ :param charset: Optional, a column-level character set for this string
546
+ value. Takes precedence to 'ascii' or 'unicode' short-hand.
547
+
548
+ :param collation: Optional, a column-level collation for this string
549
+ value. Takes precedence to 'binary' short-hand.
550
+
551
+ :param ascii: Defaults to False: short-hand for the ``latin1``
552
+ character set, generates ASCII in schema.
553
+
554
+ :param unicode: Defaults to False: short-hand for the ``ucs2``
555
+ character set, generates UNICODE in schema.
556
+
557
+ :param national: Optional. If true, use the server's configured
558
+ national character set.
559
+
560
+ :param binary: Defaults to False: short-hand, pick the binary
561
+ collation type that matches the column's character set. Generates
562
+ BINARY in schema. This does not affect the type of data stored,
563
+ only the collation of character data.
564
+
565
+ """
566
+ super().__init__(**kwargs)
567
+
568
+
569
+ class MEDIUMTEXT(_StringType):
570
+ """MySQL MEDIUMTEXT type, for character storage encoded up
571
+ to 2^24 bytes."""
572
+
573
+ __visit_name__ = "MEDIUMTEXT"
574
+
575
+ def __init__(self, **kwargs):
576
+ """Construct a MEDIUMTEXT.
577
+
578
+ :param charset: Optional, a column-level character set for this string
579
+ value. Takes precedence to 'ascii' or 'unicode' short-hand.
580
+
581
+ :param collation: Optional, a column-level collation for this string
582
+ value. Takes precedence to 'binary' short-hand.
583
+
584
+ :param ascii: Defaults to False: short-hand for the ``latin1``
585
+ character set, generates ASCII in schema.
586
+
587
+ :param unicode: Defaults to False: short-hand for the ``ucs2``
588
+ character set, generates UNICODE in schema.
589
+
590
+ :param national: Optional. If true, use the server's configured
591
+ national character set.
592
+
593
+ :param binary: Defaults to False: short-hand, pick the binary
594
+ collation type that matches the column's character set. Generates
595
+ BINARY in schema. This does not affect the type of data stored,
596
+ only the collation of character data.
597
+
598
+ """
599
+ super().__init__(**kwargs)
600
+
601
+
602
+ class LONGTEXT(_StringType):
603
+ """MySQL LONGTEXT type, for character storage encoded up to 2^32 bytes."""
604
+
605
+ __visit_name__ = "LONGTEXT"
606
+
607
+ def __init__(self, **kwargs):
608
+ """Construct a LONGTEXT.
609
+
610
+ :param charset: Optional, a column-level character set for this string
611
+ value. Takes precedence to 'ascii' or 'unicode' short-hand.
612
+
613
+ :param collation: Optional, a column-level collation for this string
614
+ value. Takes precedence to 'binary' short-hand.
615
+
616
+ :param ascii: Defaults to False: short-hand for the ``latin1``
617
+ character set, generates ASCII in schema.
618
+
619
+ :param unicode: Defaults to False: short-hand for the ``ucs2``
620
+ character set, generates UNICODE in schema.
621
+
622
+ :param national: Optional. If true, use the server's configured
623
+ national character set.
624
+
625
+ :param binary: Defaults to False: short-hand, pick the binary
626
+ collation type that matches the column's character set. Generates
627
+ BINARY in schema. This does not affect the type of data stored,
628
+ only the collation of character data.
629
+
630
+ """
631
+ super().__init__(**kwargs)
632
+
633
+
634
+ class VARCHAR(_StringType, sqltypes.VARCHAR):
635
+ """MySQL VARCHAR type, for variable-length character data."""
636
+
637
+ __visit_name__ = "VARCHAR"
638
+
639
+ def __init__(self, length=None, **kwargs):
640
+ """Construct a VARCHAR.
641
+
642
+ :param charset: Optional, a column-level character set for this string
643
+ value. Takes precedence to 'ascii' or 'unicode' short-hand.
644
+
645
+ :param collation: Optional, a column-level collation for this string
646
+ value. Takes precedence to 'binary' short-hand.
647
+
648
+ :param ascii: Defaults to False: short-hand for the ``latin1``
649
+ character set, generates ASCII in schema.
650
+
651
+ :param unicode: Defaults to False: short-hand for the ``ucs2``
652
+ character set, generates UNICODE in schema.
653
+
654
+ :param national: Optional. If true, use the server's configured
655
+ national character set.
656
+
657
+ :param binary: Defaults to False: short-hand, pick the binary
658
+ collation type that matches the column's character set. Generates
659
+ BINARY in schema. This does not affect the type of data stored,
660
+ only the collation of character data.
661
+
662
+ """
663
+ super().__init__(length=length, **kwargs)
664
+
665
+
666
+ class CHAR(_StringType, sqltypes.CHAR):
667
+ """MySQL CHAR type, for fixed-length character data."""
668
+
669
+ __visit_name__ = "CHAR"
670
+
671
+ def __init__(self, length=None, **kwargs):
672
+ """Construct a CHAR.
673
+
674
+ :param length: Maximum data length, in characters.
675
+
676
+ :param binary: Optional, use the default binary collation for the
677
+ national character set. This does not affect the type of data
678
+ stored, use a BINARY type for binary data.
679
+
680
+ :param collation: Optional, request a particular collation. Must be
681
+ compatible with the national character set.
682
+
683
+ """
684
+ super().__init__(length=length, **kwargs)
685
+
686
+ @classmethod
687
+ def _adapt_string_for_cast(cls, type_):
688
+ # copy the given string type into a CHAR
689
+ # for the purposes of rendering a CAST expression
690
+ type_ = sqltypes.to_instance(type_)
691
+ if isinstance(type_, sqltypes.CHAR):
692
+ return type_
693
+ elif isinstance(type_, _StringType):
694
+ return CHAR(
695
+ length=type_.length,
696
+ charset=type_.charset,
697
+ collation=type_.collation,
698
+ ascii=type_.ascii,
699
+ binary=type_.binary,
700
+ unicode=type_.unicode,
701
+ national=False, # not supported in CAST
702
+ )
703
+ else:
704
+ return CHAR(length=type_.length)
705
+
706
+
707
+ class NVARCHAR(_StringType, sqltypes.NVARCHAR):
708
+ """MySQL NVARCHAR type.
709
+
710
+ For variable-length character data in the server's configured national
711
+ character set.
712
+ """
713
+
714
+ __visit_name__ = "NVARCHAR"
715
+
716
+ def __init__(self, length=None, **kwargs):
717
+ """Construct an NVARCHAR.
718
+
719
+ :param length: Maximum data length, in characters.
720
+
721
+ :param binary: Optional, use the default binary collation for the
722
+ national character set. This does not affect the type of data
723
+ stored, use a BINARY type for binary data.
724
+
725
+ :param collation: Optional, request a particular collation. Must be
726
+ compatible with the national character set.
727
+
728
+ """
729
+ kwargs["national"] = True
730
+ super().__init__(length=length, **kwargs)
731
+
732
+
733
+ class NCHAR(_StringType, sqltypes.NCHAR):
734
+ """MySQL NCHAR type.
735
+
736
+ For fixed-length character data in the server's configured national
737
+ character set.
738
+ """
739
+
740
+ __visit_name__ = "NCHAR"
741
+
742
+ def __init__(self, length=None, **kwargs):
743
+ """Construct an NCHAR.
744
+
745
+ :param length: Maximum data length, in characters.
746
+
747
+ :param binary: Optional, use the default binary collation for the
748
+ national character set. This does not affect the type of data
749
+ stored, use a BINARY type for binary data.
750
+
751
+ :param collation: Optional, request a particular collation. Must be
752
+ compatible with the national character set.
753
+
754
+ """
755
+ kwargs["national"] = True
756
+ super().__init__(length=length, **kwargs)
757
+
758
+
759
+ class TINYBLOB(sqltypes._Binary):
760
+ """MySQL TINYBLOB type, for binary data up to 2^8 bytes."""
761
+
762
+ __visit_name__ = "TINYBLOB"
763
+
764
+
765
+ class MEDIUMBLOB(sqltypes._Binary):
766
+ """MySQL MEDIUMBLOB type, for binary data up to 2^24 bytes."""
767
+
768
+ __visit_name__ = "MEDIUMBLOB"
769
+
770
+
771
+ class LONGBLOB(sqltypes._Binary):
772
+ """MySQL LONGBLOB type, for binary data up to 2^32 bytes."""
773
+
774
+ __visit_name__ = "LONGBLOB"