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,745 @@
1
+ # dialects/mssql/pyodbc.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
+ r"""
10
+ .. dialect:: mssql+pyodbc
11
+ :name: PyODBC
12
+ :dbapi: pyodbc
13
+ :connectstring: mssql+pyodbc://<username>:<password>@<dsnname>
14
+ :url: https://pypi.org/project/pyodbc/
15
+
16
+ Connecting to PyODBC
17
+ --------------------
18
+
19
+ The URL here is to be translated to PyODBC connection strings, as
20
+ detailed in `ConnectionStrings <https://code.google.com/p/pyodbc/wiki/ConnectionStrings>`_.
21
+
22
+ DSN Connections
23
+ ^^^^^^^^^^^^^^^
24
+
25
+ A DSN connection in ODBC means that a pre-existing ODBC datasource is
26
+ configured on the client machine. The application then specifies the name
27
+ of this datasource, which encompasses details such as the specific ODBC driver
28
+ in use as well as the network address of the database. Assuming a datasource
29
+ is configured on the client, a basic DSN-based connection looks like::
30
+
31
+ engine = create_engine("mssql+pyodbc://scott:tiger@some_dsn")
32
+
33
+ Which above, will pass the following connection string to PyODBC::
34
+
35
+ DSN=some_dsn;UID=scott;PWD=tiger
36
+
37
+ If the username and password are omitted, the DSN form will also add
38
+ the ``Trusted_Connection=yes`` directive to the ODBC string.
39
+
40
+ Hostname Connections
41
+ ^^^^^^^^^^^^^^^^^^^^
42
+
43
+ Hostname-based connections are also supported by pyodbc. These are often
44
+ easier to use than a DSN and have the additional advantage that the specific
45
+ database name to connect towards may be specified locally in the URL, rather
46
+ than it being fixed as part of a datasource configuration.
47
+
48
+ When using a hostname connection, the driver name must also be specified in the
49
+ query parameters of the URL. As these names usually have spaces in them, the
50
+ name must be URL encoded which means using plus signs for spaces::
51
+
52
+ engine = create_engine("mssql+pyodbc://scott:tiger@myhost:port/databasename?driver=ODBC+Driver+17+for+SQL+Server")
53
+
54
+ The ``driver`` keyword is significant to the pyodbc dialect and must be
55
+ specified in lowercase.
56
+
57
+ Any other names passed in the query string are passed through in the pyodbc
58
+ connect string, such as ``authentication``, ``TrustServerCertificate``, etc.
59
+ Multiple keyword arguments must be separated by an ampersand (``&``); these
60
+ will be translated to semicolons when the pyodbc connect string is generated
61
+ internally::
62
+
63
+ e = create_engine(
64
+ "mssql+pyodbc://scott:tiger@mssql2017:1433/test?"
65
+ "driver=ODBC+Driver+18+for+SQL+Server&TrustServerCertificate=yes"
66
+ "&authentication=ActiveDirectoryIntegrated"
67
+ )
68
+
69
+ The equivalent URL can be constructed using :class:`_sa.engine.URL`::
70
+
71
+ from sqlalchemy.engine import URL
72
+ connection_url = URL.create(
73
+ "mssql+pyodbc",
74
+ username="scott",
75
+ password="tiger",
76
+ host="mssql2017",
77
+ port=1433,
78
+ database="test",
79
+ query={
80
+ "driver": "ODBC Driver 18 for SQL Server",
81
+ "TrustServerCertificate": "yes",
82
+ "authentication": "ActiveDirectoryIntegrated",
83
+ },
84
+ )
85
+
86
+
87
+ Pass through exact Pyodbc string
88
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
89
+
90
+ A PyODBC connection string can also be sent in pyodbc's format directly, as
91
+ specified in `the PyODBC documentation
92
+ <https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-databases>`_,
93
+ using the parameter ``odbc_connect``. A :class:`_sa.engine.URL` object
94
+ can help make this easier::
95
+
96
+ from sqlalchemy.engine import URL
97
+ connection_string = "DRIVER={SQL Server Native Client 10.0};SERVER=dagger;DATABASE=test;UID=user;PWD=password"
98
+ connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": connection_string})
99
+
100
+ engine = create_engine(connection_url)
101
+
102
+ .. _mssql_pyodbc_access_tokens:
103
+
104
+ Connecting to databases with access tokens
105
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
106
+
107
+ Some database servers are set up to only accept access tokens for login. For
108
+ example, SQL Server allows the use of Azure Active Directory tokens to connect
109
+ to databases. This requires creating a credential object using the
110
+ ``azure-identity`` library. More information about the authentication step can be
111
+ found in `Microsoft's documentation
112
+ <https://docs.microsoft.com/en-us/azure/developer/python/azure-sdk-authenticate?tabs=bash>`_.
113
+
114
+ After getting an engine, the credentials need to be sent to ``pyodbc.connect``
115
+ each time a connection is requested. One way to do this is to set up an event
116
+ listener on the engine that adds the credential token to the dialect's connect
117
+ call. This is discussed more generally in :ref:`engines_dynamic_tokens`. For
118
+ SQL Server in particular, this is passed as an ODBC connection attribute with
119
+ a data structure `described by Microsoft
120
+ <https://docs.microsoft.com/en-us/sql/connect/odbc/using-azure-active-directory#authenticating-with-an-access-token>`_.
121
+
122
+ The following code snippet will create an engine that connects to an Azure SQL
123
+ database using Azure credentials::
124
+
125
+ import struct
126
+ from sqlalchemy import create_engine, event
127
+ from sqlalchemy.engine.url import URL
128
+ from azure import identity
129
+
130
+ SQL_COPT_SS_ACCESS_TOKEN = 1256 # Connection option for access tokens, as defined in msodbcsql.h
131
+ TOKEN_URL = "https://database.windows.net/" # The token URL for any Azure SQL database
132
+
133
+ connection_string = "mssql+pyodbc://@my-server.database.windows.net/myDb?driver=ODBC+Driver+17+for+SQL+Server"
134
+
135
+ engine = create_engine(connection_string)
136
+
137
+ azure_credentials = identity.DefaultAzureCredential()
138
+
139
+ @event.listens_for(engine, "do_connect")
140
+ def provide_token(dialect, conn_rec, cargs, cparams):
141
+ # remove the "Trusted_Connection" parameter that SQLAlchemy adds
142
+ cargs[0] = cargs[0].replace(";Trusted_Connection=Yes", "")
143
+
144
+ # create token credential
145
+ raw_token = azure_credentials.get_token(TOKEN_URL).token.encode("utf-16-le")
146
+ token_struct = struct.pack(f"<I{len(raw_token)}s", len(raw_token), raw_token)
147
+
148
+ # apply it to keyword arguments
149
+ cparams["attrs_before"] = {SQL_COPT_SS_ACCESS_TOKEN: token_struct}
150
+
151
+ .. tip::
152
+
153
+ The ``Trusted_Connection`` token is currently added by the SQLAlchemy
154
+ pyodbc dialect when no username or password is present. This needs
155
+ to be removed per Microsoft's
156
+ `documentation for Azure access tokens
157
+ <https://docs.microsoft.com/en-us/sql/connect/odbc/using-azure-active-directory#authenticating-with-an-access-token>`_,
158
+ stating that a connection string when using an access token must not contain
159
+ ``UID``, ``PWD``, ``Authentication`` or ``Trusted_Connection`` parameters.
160
+
161
+ .. _azure_synapse_ignore_no_transaction_on_rollback:
162
+
163
+ Avoiding transaction-related exceptions on Azure Synapse Analytics
164
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
165
+
166
+ Azure Synapse Analytics has a significant difference in its transaction
167
+ handling compared to plain SQL Server; in some cases an error within a Synapse
168
+ transaction can cause it to be arbitrarily terminated on the server side, which
169
+ then causes the DBAPI ``.rollback()`` method (as well as ``.commit()``) to
170
+ fail. The issue prevents the usual DBAPI contract of allowing ``.rollback()``
171
+ to pass silently if no transaction is present as the driver does not expect
172
+ this condition. The symptom of this failure is an exception with a message
173
+ resembling 'No corresponding transaction found. (111214)' when attempting to
174
+ emit a ``.rollback()`` after an operation had a failure of some kind.
175
+
176
+ This specific case can be handled by passing ``ignore_no_transaction_on_rollback=True`` to
177
+ the SQL Server dialect via the :func:`_sa.create_engine` function as follows::
178
+
179
+ engine = create_engine(connection_url, ignore_no_transaction_on_rollback=True)
180
+
181
+ Using the above parameter, the dialect will catch ``ProgrammingError``
182
+ exceptions raised during ``connection.rollback()`` and emit a warning
183
+ if the error message contains code ``111214``, however will not raise
184
+ an exception.
185
+
186
+ .. versionadded:: 1.4.40 Added the
187
+ ``ignore_no_transaction_on_rollback=True`` parameter.
188
+
189
+ Enable autocommit for Azure SQL Data Warehouse (DW) connections
190
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
191
+
192
+ Azure SQL Data Warehouse does not support transactions,
193
+ and that can cause problems with SQLAlchemy's "autobegin" (and implicit
194
+ commit/rollback) behavior. We can avoid these problems by enabling autocommit
195
+ at both the pyodbc and engine levels::
196
+
197
+ connection_url = sa.engine.URL.create(
198
+ "mssql+pyodbc",
199
+ username="scott",
200
+ password="tiger",
201
+ host="dw.azure.example.com",
202
+ database="mydb",
203
+ query={
204
+ "driver": "ODBC Driver 17 for SQL Server",
205
+ "autocommit": "True",
206
+ },
207
+ )
208
+
209
+ engine = create_engine(connection_url).execution_options(
210
+ isolation_level="AUTOCOMMIT"
211
+ )
212
+
213
+ Avoiding sending large string parameters as TEXT/NTEXT
214
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
215
+
216
+ By default, for historical reasons, Microsoft's ODBC drivers for SQL Server
217
+ send long string parameters (greater than 4000 SBCS characters or 2000 Unicode
218
+ characters) as TEXT/NTEXT values. TEXT and NTEXT have been deprecated for many
219
+ years and are starting to cause compatibility issues with newer versions of
220
+ SQL_Server/Azure. For example, see `this
221
+ issue <https://github.com/mkleehammer/pyodbc/issues/835>`_.
222
+
223
+ Starting with ODBC Driver 18 for SQL Server we can override the legacy
224
+ behavior and pass long strings as varchar(max)/nvarchar(max) using the
225
+ ``LongAsMax=Yes`` connection string parameter::
226
+
227
+ connection_url = sa.engine.URL.create(
228
+ "mssql+pyodbc",
229
+ username="scott",
230
+ password="tiger",
231
+ host="mssqlserver.example.com",
232
+ database="mydb",
233
+ query={
234
+ "driver": "ODBC Driver 18 for SQL Server",
235
+ "LongAsMax": "Yes",
236
+ },
237
+ )
238
+
239
+
240
+ Pyodbc Pooling / connection close behavior
241
+ ------------------------------------------
242
+
243
+ PyODBC uses internal `pooling
244
+ <https://github.com/mkleehammer/pyodbc/wiki/The-pyodbc-Module#pooling>`_ by
245
+ default, which means connections will be longer lived than they are within
246
+ SQLAlchemy itself. As SQLAlchemy has its own pooling behavior, it is often
247
+ preferable to disable this behavior. This behavior can only be disabled
248
+ globally at the PyODBC module level, **before** any connections are made::
249
+
250
+ import pyodbc
251
+
252
+ pyodbc.pooling = False
253
+
254
+ # don't use the engine before pooling is set to False
255
+ engine = create_engine("mssql+pyodbc://user:pass@dsn")
256
+
257
+ If this variable is left at its default value of ``True``, **the application
258
+ will continue to maintain active database connections**, even when the
259
+ SQLAlchemy engine itself fully discards a connection or if the engine is
260
+ disposed.
261
+
262
+ .. seealso::
263
+
264
+ `pooling <https://github.com/mkleehammer/pyodbc/wiki/The-pyodbc-Module#pooling>`_ -
265
+ in the PyODBC documentation.
266
+
267
+ Driver / Unicode Support
268
+ -------------------------
269
+
270
+ PyODBC works best with Microsoft ODBC drivers, particularly in the area
271
+ of Unicode support on both Python 2 and Python 3.
272
+
273
+ Using the FreeTDS ODBC drivers on Linux or OSX with PyODBC is **not**
274
+ recommended; there have been historically many Unicode-related issues
275
+ in this area, including before Microsoft offered ODBC drivers for Linux
276
+ and OSX. Now that Microsoft offers drivers for all platforms, for
277
+ PyODBC support these are recommended. FreeTDS remains relevant for
278
+ non-ODBC drivers such as pymssql where it works very well.
279
+
280
+
281
+ Rowcount Support
282
+ ----------------
283
+
284
+ Previous limitations with the SQLAlchemy ORM's "versioned rows" feature with
285
+ Pyodbc have been resolved as of SQLAlchemy 2.0.5. See the notes at
286
+ :ref:`mssql_rowcount_versioning`.
287
+
288
+ .. _mssql_pyodbc_fastexecutemany:
289
+
290
+ Fast Executemany Mode
291
+ ---------------------
292
+
293
+ The PyODBC driver includes support for a "fast executemany" mode of execution
294
+ which greatly reduces round trips for a DBAPI ``executemany()`` call when using
295
+ Microsoft ODBC drivers, for **limited size batches that fit in memory**. The
296
+ feature is enabled by setting the attribute ``.fast_executemany`` on the DBAPI
297
+ cursor when an executemany call is to be used. The SQLAlchemy PyODBC SQL
298
+ Server dialect supports this parameter by passing the
299
+ ``fast_executemany`` parameter to
300
+ :func:`_sa.create_engine` , when using the **Microsoft ODBC driver only**::
301
+
302
+ engine = create_engine(
303
+ "mssql+pyodbc://scott:tiger@mssql2017:1433/test?driver=ODBC+Driver+17+for+SQL+Server",
304
+ fast_executemany=True)
305
+
306
+ .. versionchanged:: 2.0.9 - the ``fast_executemany`` parameter now has its
307
+ intended effect of this PyODBC feature taking effect for all INSERT
308
+ statements that are executed with multiple parameter sets, which don't
309
+ include RETURNING. Previously, SQLAlchemy 2.0's :term:`insertmanyvalues`
310
+ feature would cause ``fast_executemany`` to not be used in most cases
311
+ even if specified.
312
+
313
+ .. versionadded:: 1.3
314
+
315
+ .. seealso::
316
+
317
+ `fast executemany <https://github.com/mkleehammer/pyodbc/wiki/Features-beyond-the-DB-API#fast_executemany>`_
318
+ - on github
319
+
320
+ .. _mssql_pyodbc_setinputsizes:
321
+
322
+ Setinputsizes Support
323
+ -----------------------
324
+
325
+ As of version 2.0, the pyodbc ``cursor.setinputsizes()`` method is used for
326
+ all statement executions, except for ``cursor.executemany()`` calls when
327
+ fast_executemany=True where it is not supported (assuming
328
+ :ref:`insertmanyvalues <engine_insertmanyvalues>` is kept enabled,
329
+ "fastexecutemany" will not take place for INSERT statements in any case).
330
+
331
+ The use of ``cursor.setinputsizes()`` can be disabled by passing
332
+ ``use_setinputsizes=False`` to :func:`_sa.create_engine`.
333
+
334
+ When ``use_setinputsizes`` is left at its default of ``True``, the
335
+ specific per-type symbols passed to ``cursor.setinputsizes()`` can be
336
+ programmatically customized using the :meth:`.DialectEvents.do_setinputsizes`
337
+ hook. See that method for usage examples.
338
+
339
+ .. versionchanged:: 2.0 The mssql+pyodbc dialect now defaults to using
340
+ ``use_setinputsizes=True`` for all statement executions with the exception of
341
+ cursor.executemany() calls when fast_executemany=True. The behavior can
342
+ be turned off by passing ``use_setinputsizes=False`` to
343
+ :func:`_sa.create_engine`.
344
+
345
+ """ # noqa
346
+
347
+
348
+ import datetime
349
+ import decimal
350
+ import re
351
+ import struct
352
+
353
+ from .base import _MSDateTime
354
+ from .base import _MSUnicode
355
+ from .base import _MSUnicodeText
356
+ from .base import BINARY
357
+ from .base import DATETIMEOFFSET
358
+ from .base import MSDialect
359
+ from .base import MSExecutionContext
360
+ from .base import VARBINARY
361
+ from .json import JSON as _MSJson
362
+ from .json import JSONIndexType as _MSJsonIndexType
363
+ from .json import JSONPathType as _MSJsonPathType
364
+ from ... import exc
365
+ from ... import types as sqltypes
366
+ from ... import util
367
+ from ...connectors.pyodbc import PyODBCConnector
368
+ from ...engine import cursor as _cursor
369
+
370
+
371
+ class _ms_numeric_pyodbc:
372
+ """Turns Decimals with adjusted() < 0 or > 7 into strings.
373
+
374
+ The routines here are needed for older pyodbc versions
375
+ as well as current mxODBC versions.
376
+
377
+ """
378
+
379
+ def bind_processor(self, dialect):
380
+ super_process = super().bind_processor(dialect)
381
+
382
+ if not dialect._need_decimal_fix:
383
+ return super_process
384
+
385
+ def process(value):
386
+ if self.asdecimal and isinstance(value, decimal.Decimal):
387
+ adjusted = value.adjusted()
388
+ if adjusted < 0:
389
+ return self._small_dec_to_string(value)
390
+ elif adjusted > 7:
391
+ return self._large_dec_to_string(value)
392
+
393
+ if super_process:
394
+ return super_process(value)
395
+ else:
396
+ return value
397
+
398
+ return process
399
+
400
+ # these routines needed for older versions of pyodbc.
401
+ # as of 2.1.8 this logic is integrated.
402
+
403
+ def _small_dec_to_string(self, value):
404
+ return "%s0.%s%s" % (
405
+ (value < 0 and "-" or ""),
406
+ "0" * (abs(value.adjusted()) - 1),
407
+ "".join([str(nint) for nint in value.as_tuple()[1]]),
408
+ )
409
+
410
+ def _large_dec_to_string(self, value):
411
+ _int = value.as_tuple()[1]
412
+ if "E" in str(value):
413
+ result = "%s%s%s" % (
414
+ (value < 0 and "-" or ""),
415
+ "".join([str(s) for s in _int]),
416
+ "0" * (value.adjusted() - (len(_int) - 1)),
417
+ )
418
+ else:
419
+ if (len(_int) - 1) > value.adjusted():
420
+ result = "%s%s.%s" % (
421
+ (value < 0 and "-" or ""),
422
+ "".join([str(s) for s in _int][0 : value.adjusted() + 1]),
423
+ "".join([str(s) for s in _int][value.adjusted() + 1 :]),
424
+ )
425
+ else:
426
+ result = "%s%s" % (
427
+ (value < 0 and "-" or ""),
428
+ "".join([str(s) for s in _int][0 : value.adjusted() + 1]),
429
+ )
430
+ return result
431
+
432
+
433
+ class _MSNumeric_pyodbc(_ms_numeric_pyodbc, sqltypes.Numeric):
434
+ pass
435
+
436
+
437
+ class _MSFloat_pyodbc(_ms_numeric_pyodbc, sqltypes.Float):
438
+ pass
439
+
440
+
441
+ class _ms_binary_pyodbc:
442
+ """Wraps binary values in dialect-specific Binary wrapper.
443
+ If the value is null, return a pyodbc-specific BinaryNull
444
+ object to prevent pyODBC [and FreeTDS] from defaulting binary
445
+ NULL types to SQLWCHAR and causing implicit conversion errors.
446
+ """
447
+
448
+ def bind_processor(self, dialect):
449
+ if dialect.dbapi is None:
450
+ return None
451
+
452
+ DBAPIBinary = dialect.dbapi.Binary
453
+
454
+ def process(value):
455
+ if value is not None:
456
+ return DBAPIBinary(value)
457
+ else:
458
+ # pyodbc-specific
459
+ return dialect.dbapi.BinaryNull
460
+
461
+ return process
462
+
463
+
464
+ class _ODBCDateTimeBindProcessor:
465
+ """Add bind processors to handle datetimeoffset behaviors"""
466
+
467
+ has_tz = False
468
+
469
+ def bind_processor(self, dialect):
470
+ def process(value):
471
+ if value is None:
472
+ return None
473
+ elif isinstance(value, str):
474
+ # if a string was passed directly, allow it through
475
+ return value
476
+ elif not value.tzinfo or (not self.timezone and not self.has_tz):
477
+ # for DateTime(timezone=False)
478
+ return value
479
+ else:
480
+ # for DATETIMEOFFSET or DateTime(timezone=True)
481
+ #
482
+ # Convert to string format required by T-SQL
483
+ dto_string = value.strftime("%Y-%m-%d %H:%M:%S.%f %z")
484
+ # offset needs a colon, e.g., -0700 -> -07:00
485
+ # "UTC offset in the form (+-)HHMM[SS[.ffffff]]"
486
+ # backend currently rejects seconds / fractional seconds
487
+ dto_string = re.sub(
488
+ r"([\+\-]\d{2})([\d\.]+)$", r"\1:\2", dto_string
489
+ )
490
+ return dto_string
491
+
492
+ return process
493
+
494
+
495
+ class _ODBCDateTime(_ODBCDateTimeBindProcessor, _MSDateTime):
496
+ pass
497
+
498
+
499
+ class _ODBCDATETIMEOFFSET(_ODBCDateTimeBindProcessor, DATETIMEOFFSET):
500
+ has_tz = True
501
+
502
+
503
+ class _VARBINARY_pyodbc(_ms_binary_pyodbc, VARBINARY):
504
+ pass
505
+
506
+
507
+ class _BINARY_pyodbc(_ms_binary_pyodbc, BINARY):
508
+ pass
509
+
510
+
511
+ class _String_pyodbc(sqltypes.String):
512
+ def get_dbapi_type(self, dbapi):
513
+ if self.length in (None, "max") or self.length >= 2000:
514
+ return (dbapi.SQL_VARCHAR, 0, 0)
515
+ else:
516
+ return dbapi.SQL_VARCHAR
517
+
518
+
519
+ class _Unicode_pyodbc(_MSUnicode):
520
+ def get_dbapi_type(self, dbapi):
521
+ if self.length in (None, "max") or self.length >= 2000:
522
+ return (dbapi.SQL_WVARCHAR, 0, 0)
523
+ else:
524
+ return dbapi.SQL_WVARCHAR
525
+
526
+
527
+ class _UnicodeText_pyodbc(_MSUnicodeText):
528
+ def get_dbapi_type(self, dbapi):
529
+ if self.length in (None, "max") or self.length >= 2000:
530
+ return (dbapi.SQL_WVARCHAR, 0, 0)
531
+ else:
532
+ return dbapi.SQL_WVARCHAR
533
+
534
+
535
+ class _JSON_pyodbc(_MSJson):
536
+ def get_dbapi_type(self, dbapi):
537
+ return (dbapi.SQL_WVARCHAR, 0, 0)
538
+
539
+
540
+ class _JSONIndexType_pyodbc(_MSJsonIndexType):
541
+ def get_dbapi_type(self, dbapi):
542
+ return dbapi.SQL_WVARCHAR
543
+
544
+
545
+ class _JSONPathType_pyodbc(_MSJsonPathType):
546
+ def get_dbapi_type(self, dbapi):
547
+ return dbapi.SQL_WVARCHAR
548
+
549
+
550
+ class MSExecutionContext_pyodbc(MSExecutionContext):
551
+ _embedded_scope_identity = False
552
+
553
+ def pre_exec(self):
554
+ """where appropriate, issue "select scope_identity()" in the same
555
+ statement.
556
+
557
+ Background on why "scope_identity()" is preferable to "@@identity":
558
+ https://msdn.microsoft.com/en-us/library/ms190315.aspx
559
+
560
+ Background on why we attempt to embed "scope_identity()" into the same
561
+ statement as the INSERT:
562
+ https://code.google.com/p/pyodbc/wiki/FAQs#How_do_I_retrieve_autogenerated/identity_values?
563
+
564
+ """
565
+
566
+ super().pre_exec()
567
+
568
+ # don't embed the scope_identity select into an
569
+ # "INSERT .. DEFAULT VALUES"
570
+ if (
571
+ self._select_lastrowid
572
+ and self.dialect.use_scope_identity
573
+ and len(self.parameters[0])
574
+ ):
575
+ self._embedded_scope_identity = True
576
+
577
+ self.statement += "; select scope_identity()"
578
+
579
+ def post_exec(self):
580
+ if self._embedded_scope_identity:
581
+ # Fetch the last inserted id from the manipulated statement
582
+ # We may have to skip over a number of result sets with
583
+ # no data (due to triggers, etc.)
584
+ while True:
585
+ try:
586
+ # fetchall() ensures the cursor is consumed
587
+ # without closing it (FreeTDS particularly)
588
+ rows = self.cursor.fetchall()
589
+ except self.dialect.dbapi.Error:
590
+ # no way around this - nextset() consumes the previous set
591
+ # so we need to just keep flipping
592
+ self.cursor.nextset()
593
+ else:
594
+ if not rows:
595
+ # async adapter drivers just return None here
596
+ self.cursor.nextset()
597
+ continue
598
+ row = rows[0]
599
+ break
600
+
601
+ self._lastrowid = int(row[0])
602
+
603
+ self.cursor_fetch_strategy = _cursor._NO_CURSOR_DML
604
+ else:
605
+ super().post_exec()
606
+
607
+
608
+ class MSDialect_pyodbc(PyODBCConnector, MSDialect):
609
+ supports_statement_cache = True
610
+
611
+ # note this parameter is no longer used by the ORM or default dialect
612
+ # see #9414
613
+ supports_sane_rowcount_returning = False
614
+
615
+ execution_ctx_cls = MSExecutionContext_pyodbc
616
+
617
+ colspecs = util.update_copy(
618
+ MSDialect.colspecs,
619
+ {
620
+ sqltypes.Numeric: _MSNumeric_pyodbc,
621
+ sqltypes.Float: _MSFloat_pyodbc,
622
+ BINARY: _BINARY_pyodbc,
623
+ # support DateTime(timezone=True)
624
+ sqltypes.DateTime: _ODBCDateTime,
625
+ DATETIMEOFFSET: _ODBCDATETIMEOFFSET,
626
+ # SQL Server dialect has a VARBINARY that is just to support
627
+ # "deprecate_large_types" w/ VARBINARY(max), but also we must
628
+ # handle the usual SQL standard VARBINARY
629
+ VARBINARY: _VARBINARY_pyodbc,
630
+ sqltypes.VARBINARY: _VARBINARY_pyodbc,
631
+ sqltypes.LargeBinary: _VARBINARY_pyodbc,
632
+ sqltypes.String: _String_pyodbc,
633
+ sqltypes.Unicode: _Unicode_pyodbc,
634
+ sqltypes.UnicodeText: _UnicodeText_pyodbc,
635
+ sqltypes.JSON: _JSON_pyodbc,
636
+ sqltypes.JSON.JSONIndexType: _JSONIndexType_pyodbc,
637
+ sqltypes.JSON.JSONPathType: _JSONPathType_pyodbc,
638
+ # this excludes Enum from the string/VARCHAR thing for now
639
+ # it looks like Enum's adaptation doesn't really support the
640
+ # String type itself having a dialect-level impl
641
+ sqltypes.Enum: sqltypes.Enum,
642
+ },
643
+ )
644
+
645
+ def __init__(
646
+ self,
647
+ fast_executemany=False,
648
+ use_setinputsizes=True,
649
+ **params,
650
+ ):
651
+ super().__init__(use_setinputsizes=use_setinputsizes, **params)
652
+ self.use_scope_identity = (
653
+ self.use_scope_identity
654
+ and self.dbapi
655
+ and hasattr(self.dbapi.Cursor, "nextset")
656
+ )
657
+ self._need_decimal_fix = self.dbapi and self._dbapi_version() < (
658
+ 2,
659
+ 1,
660
+ 8,
661
+ )
662
+ self.fast_executemany = fast_executemany
663
+ if fast_executemany:
664
+ self.use_insertmanyvalues_wo_returning = False
665
+
666
+ def _get_server_version_info(self, connection):
667
+ try:
668
+ # "Version of the instance of SQL Server, in the form
669
+ # of 'major.minor.build.revision'"
670
+ raw = connection.exec_driver_sql(
671
+ "SELECT CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR)"
672
+ ).scalar()
673
+ except exc.DBAPIError:
674
+ # SQL Server docs indicate this function isn't present prior to
675
+ # 2008. Before we had the VARCHAR cast above, pyodbc would also
676
+ # fail on this query.
677
+ return super()._get_server_version_info(connection)
678
+ else:
679
+ version = []
680
+ r = re.compile(r"[.\-]")
681
+ for n in r.split(raw):
682
+ try:
683
+ version.append(int(n))
684
+ except ValueError:
685
+ pass
686
+ return tuple(version)
687
+
688
+ def on_connect(self):
689
+ super_ = super().on_connect()
690
+
691
+ def on_connect(conn):
692
+ if super_ is not None:
693
+ super_(conn)
694
+
695
+ self._setup_timestampoffset_type(conn)
696
+
697
+ return on_connect
698
+
699
+ def _setup_timestampoffset_type(self, connection):
700
+ # output converter function for datetimeoffset
701
+ def _handle_datetimeoffset(dto_value):
702
+ tup = struct.unpack("<6hI2h", dto_value)
703
+ return datetime.datetime(
704
+ tup[0],
705
+ tup[1],
706
+ tup[2],
707
+ tup[3],
708
+ tup[4],
709
+ tup[5],
710
+ tup[6] // 1000,
711
+ datetime.timezone(
712
+ datetime.timedelta(hours=tup[7], minutes=tup[8])
713
+ ),
714
+ )
715
+
716
+ odbc_SQL_SS_TIMESTAMPOFFSET = -155 # as defined in SQLNCLI.h
717
+ connection.add_output_converter(
718
+ odbc_SQL_SS_TIMESTAMPOFFSET, _handle_datetimeoffset
719
+ )
720
+
721
+ def do_executemany(self, cursor, statement, parameters, context=None):
722
+ if self.fast_executemany:
723
+ cursor.fast_executemany = True
724
+ super().do_executemany(cursor, statement, parameters, context=context)
725
+
726
+ def is_disconnect(self, e, connection, cursor):
727
+ if isinstance(e, self.dbapi.Error):
728
+ code = e.args[0]
729
+ if code in {
730
+ "08S01",
731
+ "01000",
732
+ "01002",
733
+ "08003",
734
+ "08007",
735
+ "08S02",
736
+ "08001",
737
+ "HYT00",
738
+ "HY010",
739
+ "10054",
740
+ }:
741
+ return True
742
+ return super().is_disconnect(e, connection, cursor)
743
+
744
+
745
+ dialect = MSDialect_pyodbc