SQLAlchemy 2.0.47__cp313-cp313t-win32.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 (274) hide show
  1. sqlalchemy/__init__.py +283 -0
  2. sqlalchemy/connectors/__init__.py +18 -0
  3. sqlalchemy/connectors/aioodbc.py +184 -0
  4. sqlalchemy/connectors/asyncio.py +429 -0
  5. sqlalchemy/connectors/pyodbc.py +250 -0
  6. sqlalchemy/cyextension/__init__.py +6 -0
  7. sqlalchemy/cyextension/collections.cp313t-win32.pyd +0 -0
  8. sqlalchemy/cyextension/collections.pyx +409 -0
  9. sqlalchemy/cyextension/immutabledict.cp313t-win32.pyd +0 -0
  10. sqlalchemy/cyextension/immutabledict.pxd +8 -0
  11. sqlalchemy/cyextension/immutabledict.pyx +133 -0
  12. sqlalchemy/cyextension/processors.cp313t-win32.pyd +0 -0
  13. sqlalchemy/cyextension/processors.pyx +68 -0
  14. sqlalchemy/cyextension/resultproxy.cp313t-win32.pyd +0 -0
  15. sqlalchemy/cyextension/resultproxy.pyx +102 -0
  16. sqlalchemy/cyextension/util.cp313t-win32.pyd +0 -0
  17. sqlalchemy/cyextension/util.pyx +90 -0
  18. sqlalchemy/dialects/__init__.py +62 -0
  19. sqlalchemy/dialects/_typing.py +30 -0
  20. sqlalchemy/dialects/mssql/__init__.py +88 -0
  21. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  22. sqlalchemy/dialects/mssql/base.py +4093 -0
  23. sqlalchemy/dialects/mssql/information_schema.py +285 -0
  24. sqlalchemy/dialects/mssql/json.py +129 -0
  25. sqlalchemy/dialects/mssql/provision.py +185 -0
  26. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  27. sqlalchemy/dialects/mssql/pyodbc.py +760 -0
  28. sqlalchemy/dialects/mysql/__init__.py +104 -0
  29. sqlalchemy/dialects/mysql/aiomysql.py +250 -0
  30. sqlalchemy/dialects/mysql/asyncmy.py +231 -0
  31. sqlalchemy/dialects/mysql/base.py +3949 -0
  32. sqlalchemy/dialects/mysql/cymysql.py +106 -0
  33. sqlalchemy/dialects/mysql/dml.py +225 -0
  34. sqlalchemy/dialects/mysql/enumerated.py +282 -0
  35. sqlalchemy/dialects/mysql/expression.py +146 -0
  36. sqlalchemy/dialects/mysql/json.py +91 -0
  37. sqlalchemy/dialects/mysql/mariadb.py +72 -0
  38. sqlalchemy/dialects/mysql/mariadbconnector.py +322 -0
  39. sqlalchemy/dialects/mysql/mysqlconnector.py +302 -0
  40. sqlalchemy/dialects/mysql/mysqldb.py +314 -0
  41. sqlalchemy/dialects/mysql/provision.py +153 -0
  42. sqlalchemy/dialects/mysql/pymysql.py +158 -0
  43. sqlalchemy/dialects/mysql/pyodbc.py +157 -0
  44. sqlalchemy/dialects/mysql/reflection.py +727 -0
  45. sqlalchemy/dialects/mysql/reserved_words.py +570 -0
  46. sqlalchemy/dialects/mysql/types.py +835 -0
  47. sqlalchemy/dialects/oracle/__init__.py +81 -0
  48. sqlalchemy/dialects/oracle/base.py +3802 -0
  49. sqlalchemy/dialects/oracle/cx_oracle.py +1555 -0
  50. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  51. sqlalchemy/dialects/oracle/oracledb.py +941 -0
  52. sqlalchemy/dialects/oracle/provision.py +297 -0
  53. sqlalchemy/dialects/oracle/types.py +316 -0
  54. sqlalchemy/dialects/oracle/vector.py +365 -0
  55. sqlalchemy/dialects/postgresql/__init__.py +167 -0
  56. sqlalchemy/dialects/postgresql/_psycopg_common.py +189 -0
  57. sqlalchemy/dialects/postgresql/array.py +519 -0
  58. sqlalchemy/dialects/postgresql/asyncpg.py +1284 -0
  59. sqlalchemy/dialects/postgresql/base.py +5378 -0
  60. sqlalchemy/dialects/postgresql/dml.py +339 -0
  61. sqlalchemy/dialects/postgresql/ext.py +540 -0
  62. sqlalchemy/dialects/postgresql/hstore.py +406 -0
  63. sqlalchemy/dialects/postgresql/json.py +404 -0
  64. sqlalchemy/dialects/postgresql/named_types.py +524 -0
  65. sqlalchemy/dialects/postgresql/operators.py +129 -0
  66. sqlalchemy/dialects/postgresql/pg8000.py +669 -0
  67. sqlalchemy/dialects/postgresql/pg_catalog.py +326 -0
  68. sqlalchemy/dialects/postgresql/provision.py +183 -0
  69. sqlalchemy/dialects/postgresql/psycopg.py +862 -0
  70. sqlalchemy/dialects/postgresql/psycopg2.py +892 -0
  71. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  72. sqlalchemy/dialects/postgresql/ranges.py +1031 -0
  73. sqlalchemy/dialects/postgresql/types.py +313 -0
  74. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  75. sqlalchemy/dialects/sqlite/aiosqlite.py +482 -0
  76. sqlalchemy/dialects/sqlite/base.py +3056 -0
  77. sqlalchemy/dialects/sqlite/dml.py +263 -0
  78. sqlalchemy/dialects/sqlite/json.py +92 -0
  79. sqlalchemy/dialects/sqlite/provision.py +229 -0
  80. sqlalchemy/dialects/sqlite/pysqlcipher.py +157 -0
  81. sqlalchemy/dialects/sqlite/pysqlite.py +756 -0
  82. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  83. sqlalchemy/engine/__init__.py +62 -0
  84. sqlalchemy/engine/_py_processors.py +136 -0
  85. sqlalchemy/engine/_py_row.py +128 -0
  86. sqlalchemy/engine/_py_util.py +74 -0
  87. sqlalchemy/engine/base.py +3390 -0
  88. sqlalchemy/engine/characteristics.py +155 -0
  89. sqlalchemy/engine/create.py +893 -0
  90. sqlalchemy/engine/cursor.py +2298 -0
  91. sqlalchemy/engine/default.py +2394 -0
  92. sqlalchemy/engine/events.py +965 -0
  93. sqlalchemy/engine/interfaces.py +3471 -0
  94. sqlalchemy/engine/mock.py +134 -0
  95. sqlalchemy/engine/processors.py +61 -0
  96. sqlalchemy/engine/reflection.py +2102 -0
  97. sqlalchemy/engine/result.py +2399 -0
  98. sqlalchemy/engine/row.py +400 -0
  99. sqlalchemy/engine/strategies.py +16 -0
  100. sqlalchemy/engine/url.py +924 -0
  101. sqlalchemy/engine/util.py +167 -0
  102. sqlalchemy/event/__init__.py +26 -0
  103. sqlalchemy/event/api.py +220 -0
  104. sqlalchemy/event/attr.py +676 -0
  105. sqlalchemy/event/base.py +472 -0
  106. sqlalchemy/event/legacy.py +258 -0
  107. sqlalchemy/event/registry.py +390 -0
  108. sqlalchemy/events.py +17 -0
  109. sqlalchemy/exc.py +832 -0
  110. sqlalchemy/ext/__init__.py +11 -0
  111. sqlalchemy/ext/associationproxy.py +2027 -0
  112. sqlalchemy/ext/asyncio/__init__.py +25 -0
  113. sqlalchemy/ext/asyncio/base.py +281 -0
  114. sqlalchemy/ext/asyncio/engine.py +1471 -0
  115. sqlalchemy/ext/asyncio/exc.py +21 -0
  116. sqlalchemy/ext/asyncio/result.py +965 -0
  117. sqlalchemy/ext/asyncio/scoping.py +1599 -0
  118. sqlalchemy/ext/asyncio/session.py +1947 -0
  119. sqlalchemy/ext/automap.py +1701 -0
  120. sqlalchemy/ext/baked.py +570 -0
  121. sqlalchemy/ext/compiler.py +600 -0
  122. sqlalchemy/ext/declarative/__init__.py +65 -0
  123. sqlalchemy/ext/declarative/extensions.py +564 -0
  124. sqlalchemy/ext/horizontal_shard.py +478 -0
  125. sqlalchemy/ext/hybrid.py +1535 -0
  126. sqlalchemy/ext/indexable.py +364 -0
  127. sqlalchemy/ext/instrumentation.py +450 -0
  128. sqlalchemy/ext/mutable.py +1085 -0
  129. sqlalchemy/ext/mypy/__init__.py +6 -0
  130. sqlalchemy/ext/mypy/apply.py +324 -0
  131. sqlalchemy/ext/mypy/decl_class.py +515 -0
  132. sqlalchemy/ext/mypy/infer.py +590 -0
  133. sqlalchemy/ext/mypy/names.py +335 -0
  134. sqlalchemy/ext/mypy/plugin.py +303 -0
  135. sqlalchemy/ext/mypy/util.py +357 -0
  136. sqlalchemy/ext/orderinglist.py +439 -0
  137. sqlalchemy/ext/serializer.py +185 -0
  138. sqlalchemy/future/__init__.py +16 -0
  139. sqlalchemy/future/engine.py +15 -0
  140. sqlalchemy/inspection.py +174 -0
  141. sqlalchemy/log.py +288 -0
  142. sqlalchemy/orm/__init__.py +171 -0
  143. sqlalchemy/orm/_orm_constructors.py +2661 -0
  144. sqlalchemy/orm/_typing.py +179 -0
  145. sqlalchemy/orm/attributes.py +2845 -0
  146. sqlalchemy/orm/base.py +971 -0
  147. sqlalchemy/orm/bulk_persistence.py +2135 -0
  148. sqlalchemy/orm/clsregistry.py +571 -0
  149. sqlalchemy/orm/collections.py +1627 -0
  150. sqlalchemy/orm/context.py +3334 -0
  151. sqlalchemy/orm/decl_api.py +2004 -0
  152. sqlalchemy/orm/decl_base.py +2192 -0
  153. sqlalchemy/orm/dependency.py +1302 -0
  154. sqlalchemy/orm/descriptor_props.py +1092 -0
  155. sqlalchemy/orm/dynamic.py +300 -0
  156. sqlalchemy/orm/evaluator.py +379 -0
  157. sqlalchemy/orm/events.py +3252 -0
  158. sqlalchemy/orm/exc.py +237 -0
  159. sqlalchemy/orm/identity.py +302 -0
  160. sqlalchemy/orm/instrumentation.py +754 -0
  161. sqlalchemy/orm/interfaces.py +1496 -0
  162. sqlalchemy/orm/loading.py +1686 -0
  163. sqlalchemy/orm/mapped_collection.py +557 -0
  164. sqlalchemy/orm/mapper.py +4444 -0
  165. sqlalchemy/orm/path_registry.py +809 -0
  166. sqlalchemy/orm/persistence.py +1788 -0
  167. sqlalchemy/orm/properties.py +935 -0
  168. sqlalchemy/orm/query.py +3459 -0
  169. sqlalchemy/orm/relationships.py +3508 -0
  170. sqlalchemy/orm/scoping.py +2148 -0
  171. sqlalchemy/orm/session.py +5280 -0
  172. sqlalchemy/orm/state.py +1168 -0
  173. sqlalchemy/orm/state_changes.py +196 -0
  174. sqlalchemy/orm/strategies.py +3470 -0
  175. sqlalchemy/orm/strategy_options.py +2568 -0
  176. sqlalchemy/orm/sync.py +164 -0
  177. sqlalchemy/orm/unitofwork.py +796 -0
  178. sqlalchemy/orm/util.py +2403 -0
  179. sqlalchemy/orm/writeonly.py +674 -0
  180. sqlalchemy/pool/__init__.py +44 -0
  181. sqlalchemy/pool/base.py +1524 -0
  182. sqlalchemy/pool/events.py +375 -0
  183. sqlalchemy/pool/impl.py +588 -0
  184. sqlalchemy/py.typed +0 -0
  185. sqlalchemy/schema.py +69 -0
  186. sqlalchemy/sql/__init__.py +145 -0
  187. sqlalchemy/sql/_dml_constructors.py +132 -0
  188. sqlalchemy/sql/_elements_constructors.py +1872 -0
  189. sqlalchemy/sql/_orm_types.py +20 -0
  190. sqlalchemy/sql/_py_util.py +75 -0
  191. sqlalchemy/sql/_selectable_constructors.py +763 -0
  192. sqlalchemy/sql/_typing.py +482 -0
  193. sqlalchemy/sql/annotation.py +587 -0
  194. sqlalchemy/sql/base.py +2293 -0
  195. sqlalchemy/sql/cache_key.py +1057 -0
  196. sqlalchemy/sql/coercions.py +1404 -0
  197. sqlalchemy/sql/compiler.py +8081 -0
  198. sqlalchemy/sql/crud.py +1752 -0
  199. sqlalchemy/sql/ddl.py +1444 -0
  200. sqlalchemy/sql/default_comparator.py +551 -0
  201. sqlalchemy/sql/dml.py +1850 -0
  202. sqlalchemy/sql/elements.py +5589 -0
  203. sqlalchemy/sql/events.py +458 -0
  204. sqlalchemy/sql/expression.py +159 -0
  205. sqlalchemy/sql/functions.py +2158 -0
  206. sqlalchemy/sql/lambdas.py +1442 -0
  207. sqlalchemy/sql/naming.py +209 -0
  208. sqlalchemy/sql/operators.py +2623 -0
  209. sqlalchemy/sql/roles.py +323 -0
  210. sqlalchemy/sql/schema.py +6222 -0
  211. sqlalchemy/sql/selectable.py +7265 -0
  212. sqlalchemy/sql/sqltypes.py +3930 -0
  213. sqlalchemy/sql/traversals.py +1024 -0
  214. sqlalchemy/sql/type_api.py +2368 -0
  215. sqlalchemy/sql/util.py +1485 -0
  216. sqlalchemy/sql/visitors.py +1164 -0
  217. sqlalchemy/testing/__init__.py +96 -0
  218. sqlalchemy/testing/assertions.py +994 -0
  219. sqlalchemy/testing/assertsql.py +520 -0
  220. sqlalchemy/testing/asyncio.py +135 -0
  221. sqlalchemy/testing/config.py +434 -0
  222. sqlalchemy/testing/engines.py +483 -0
  223. sqlalchemy/testing/entities.py +117 -0
  224. sqlalchemy/testing/exclusions.py +476 -0
  225. sqlalchemy/testing/fixtures/__init__.py +28 -0
  226. sqlalchemy/testing/fixtures/base.py +384 -0
  227. sqlalchemy/testing/fixtures/mypy.py +332 -0
  228. sqlalchemy/testing/fixtures/orm.py +227 -0
  229. sqlalchemy/testing/fixtures/sql.py +482 -0
  230. sqlalchemy/testing/pickleable.py +155 -0
  231. sqlalchemy/testing/plugin/__init__.py +6 -0
  232. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  233. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  234. sqlalchemy/testing/plugin/pytestplugin.py +892 -0
  235. sqlalchemy/testing/profiling.py +329 -0
  236. sqlalchemy/testing/provision.py +603 -0
  237. sqlalchemy/testing/requirements.py +1945 -0
  238. sqlalchemy/testing/schema.py +198 -0
  239. sqlalchemy/testing/suite/__init__.py +19 -0
  240. sqlalchemy/testing/suite/test_cte.py +237 -0
  241. sqlalchemy/testing/suite/test_ddl.py +389 -0
  242. sqlalchemy/testing/suite/test_deprecations.py +153 -0
  243. sqlalchemy/testing/suite/test_dialect.py +776 -0
  244. sqlalchemy/testing/suite/test_insert.py +630 -0
  245. sqlalchemy/testing/suite/test_reflection.py +3557 -0
  246. sqlalchemy/testing/suite/test_results.py +504 -0
  247. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  248. sqlalchemy/testing/suite/test_select.py +2010 -0
  249. sqlalchemy/testing/suite/test_sequence.py +317 -0
  250. sqlalchemy/testing/suite/test_types.py +2147 -0
  251. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  252. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  253. sqlalchemy/testing/util.py +535 -0
  254. sqlalchemy/testing/warnings.py +52 -0
  255. sqlalchemy/types.py +74 -0
  256. sqlalchemy/util/__init__.py +162 -0
  257. sqlalchemy/util/_collections.py +712 -0
  258. sqlalchemy/util/_concurrency_py3k.py +288 -0
  259. sqlalchemy/util/_has_cy.py +40 -0
  260. sqlalchemy/util/_py_collections.py +541 -0
  261. sqlalchemy/util/compat.py +421 -0
  262. sqlalchemy/util/concurrency.py +110 -0
  263. sqlalchemy/util/deprecations.py +401 -0
  264. sqlalchemy/util/langhelpers.py +2203 -0
  265. sqlalchemy/util/preloaded.py +150 -0
  266. sqlalchemy/util/queue.py +322 -0
  267. sqlalchemy/util/tool_support.py +201 -0
  268. sqlalchemy/util/topological.py +120 -0
  269. sqlalchemy/util/typing.py +734 -0
  270. sqlalchemy-2.0.47.dist-info/METADATA +243 -0
  271. sqlalchemy-2.0.47.dist-info/RECORD +274 -0
  272. sqlalchemy-2.0.47.dist-info/WHEEL +5 -0
  273. sqlalchemy-2.0.47.dist-info/licenses/LICENSE +19 -0
  274. sqlalchemy-2.0.47.dist-info/top_level.txt +1 -0
@@ -0,0 +1,756 @@
1
+ # dialects/sqlite/pysqlite.py
2
+ # Copyright (C) 2005-2026 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
+
8
+
9
+ r"""
10
+ .. dialect:: sqlite+pysqlite
11
+ :name: pysqlite
12
+ :dbapi: sqlite3
13
+ :connectstring: sqlite+pysqlite:///file_path
14
+ :url: https://docs.python.org/library/sqlite3.html
15
+
16
+ Note that ``pysqlite`` is the same driver as the ``sqlite3``
17
+ module included with the Python distribution.
18
+
19
+ Driver
20
+ ------
21
+
22
+ The ``sqlite3`` Python DBAPI is standard on all modern Python versions;
23
+ for cPython and Pypy, no additional installation is necessary.
24
+
25
+
26
+ Connect Strings
27
+ ---------------
28
+
29
+ The file specification for the SQLite database is taken as the "database"
30
+ portion of the URL. Note that the format of a SQLAlchemy url is:
31
+
32
+ .. sourcecode:: text
33
+
34
+ driver://user:pass@host/database
35
+
36
+ This means that the actual filename to be used starts with the characters to
37
+ the **right** of the third slash. So connecting to a relative filepath
38
+ looks like::
39
+
40
+ # relative path
41
+ e = create_engine("sqlite:///path/to/database.db")
42
+
43
+ An absolute path, which is denoted by starting with a slash, means you
44
+ need **four** slashes::
45
+
46
+ # absolute path
47
+ e = create_engine("sqlite:////path/to/database.db")
48
+
49
+ To use a Windows path, regular drive specifications and backslashes can be
50
+ used. Double backslashes are probably needed::
51
+
52
+ # absolute path on Windows
53
+ e = create_engine("sqlite:///C:\\path\\to\\database.db")
54
+
55
+ To use sqlite ``:memory:`` database specify it as the filename using
56
+ ``sqlite:///:memory:``. It's also the default if no filepath is
57
+ present, specifying only ``sqlite://`` and nothing else::
58
+
59
+ # in-memory database (note three slashes)
60
+ e = create_engine("sqlite:///:memory:")
61
+ # also in-memory database
62
+ e2 = create_engine("sqlite://")
63
+
64
+ .. _pysqlite_uri_connections:
65
+
66
+ URI Connections
67
+ ^^^^^^^^^^^^^^^
68
+
69
+ Modern versions of SQLite support an alternative system of connecting using a
70
+ `driver level URI <https://www.sqlite.org/uri.html>`_, which has the advantage
71
+ that additional driver-level arguments can be passed including options such as
72
+ "read only". The Python sqlite3 driver supports this mode under modern Python
73
+ 3 versions. The SQLAlchemy pysqlite driver supports this mode of use by
74
+ specifying "uri=true" in the URL query string. The SQLite-level "URI" is kept
75
+ as the "database" portion of the SQLAlchemy url (that is, following a slash)::
76
+
77
+ e = create_engine("sqlite:///file:path/to/database?mode=ro&uri=true")
78
+
79
+ .. note:: The "uri=true" parameter must appear in the **query string**
80
+ of the URL. It will not currently work as expected if it is only
81
+ present in the :paramref:`_sa.create_engine.connect_args`
82
+ parameter dictionary.
83
+
84
+ The logic reconciles the simultaneous presence of SQLAlchemy's query string and
85
+ SQLite's query string by separating out the parameters that belong to the
86
+ Python sqlite3 driver vs. those that belong to the SQLite URI. This is
87
+ achieved through the use of a fixed list of parameters known to be accepted by
88
+ the Python side of the driver. For example, to include a URL that indicates
89
+ the Python sqlite3 "timeout" and "check_same_thread" parameters, along with the
90
+ SQLite "mode" and "nolock" parameters, they can all be passed together on the
91
+ query string::
92
+
93
+ e = create_engine(
94
+ "sqlite:///file:path/to/database?"
95
+ "check_same_thread=true&timeout=10&mode=ro&nolock=1&uri=true"
96
+ )
97
+
98
+ Above, the pysqlite / sqlite3 DBAPI would be passed arguments as::
99
+
100
+ sqlite3.connect(
101
+ "file:path/to/database?mode=ro&nolock=1",
102
+ check_same_thread=True,
103
+ timeout=10,
104
+ uri=True,
105
+ )
106
+
107
+ Regarding future parameters added to either the Python or native drivers. new
108
+ parameter names added to the SQLite URI scheme should be automatically
109
+ accommodated by this scheme. New parameter names added to the Python driver
110
+ side can be accommodated by specifying them in the
111
+ :paramref:`_sa.create_engine.connect_args` dictionary,
112
+ until dialect support is
113
+ added by SQLAlchemy. For the less likely case that the native SQLite driver
114
+ adds a new parameter name that overlaps with one of the existing, known Python
115
+ driver parameters (such as "timeout" perhaps), SQLAlchemy's dialect would
116
+ require adjustment for the URL scheme to continue to support this.
117
+
118
+ As is always the case for all SQLAlchemy dialects, the entire "URL" process
119
+ can be bypassed in :func:`_sa.create_engine` through the use of the
120
+ :paramref:`_sa.create_engine.creator`
121
+ parameter which allows for a custom callable
122
+ that creates a Python sqlite3 driver level connection directly.
123
+
124
+ .. versionadded:: 1.3.9
125
+
126
+ .. seealso::
127
+
128
+ `Uniform Resource Identifiers <https://www.sqlite.org/uri.html>`_ - in
129
+ the SQLite documentation
130
+
131
+ .. _pysqlite_regexp:
132
+
133
+ Regular Expression Support
134
+ ---------------------------
135
+
136
+ .. versionadded:: 1.4
137
+
138
+ Support for the :meth:`_sql.ColumnOperators.regexp_match` operator is provided
139
+ using Python's re.search_ function. SQLite itself does not include a working
140
+ regular expression operator; instead, it includes a non-implemented placeholder
141
+ operator ``REGEXP`` that calls a user-defined function that must be provided.
142
+
143
+ SQLAlchemy's implementation makes use of the pysqlite create_function_ hook
144
+ as follows::
145
+
146
+
147
+ def regexp(a, b):
148
+ return re.search(a, b) is not None
149
+
150
+
151
+ sqlite_connection.create_function(
152
+ "regexp",
153
+ 2,
154
+ regexp,
155
+ )
156
+
157
+ There is currently no support for regular expression flags as a separate
158
+ argument, as these are not supported by SQLite's REGEXP operator, however these
159
+ may be included inline within the regular expression string. See `Python regular expressions`_ for
160
+ details.
161
+
162
+ .. seealso::
163
+
164
+ `Python regular expressions`_: Documentation for Python's regular expression syntax.
165
+
166
+ .. _create_function: https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function
167
+
168
+ .. _re.search: https://docs.python.org/3/library/re.html#re.search
169
+
170
+ .. _Python regular expressions: https://docs.python.org/3/library/re.html#re.search
171
+
172
+
173
+
174
+ Compatibility with sqlite3 "native" date and datetime types
175
+ -----------------------------------------------------------
176
+
177
+ The pysqlite driver includes the sqlite3.PARSE_DECLTYPES and
178
+ sqlite3.PARSE_COLNAMES options, which have the effect of any column
179
+ or expression explicitly cast as "date" or "timestamp" will be converted
180
+ to a Python date or datetime object. The date and datetime types provided
181
+ with the pysqlite dialect are not currently compatible with these options,
182
+ since they render the ISO date/datetime including microseconds, which
183
+ pysqlite's driver does not. Additionally, SQLAlchemy does not at
184
+ this time automatically render the "cast" syntax required for the
185
+ freestanding functions "current_timestamp" and "current_date" to return
186
+ datetime/date types natively. Unfortunately, pysqlite
187
+ does not provide the standard DBAPI types in ``cursor.description``,
188
+ leaving SQLAlchemy with no way to detect these types on the fly
189
+ without expensive per-row type checks.
190
+
191
+ Keeping in mind that pysqlite's parsing option is not recommended,
192
+ nor should be necessary, for use with SQLAlchemy, usage of PARSE_DECLTYPES
193
+ can be forced if one configures "native_datetime=True" on create_engine()::
194
+
195
+ engine = create_engine(
196
+ "sqlite://",
197
+ connect_args={
198
+ "detect_types": sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES
199
+ },
200
+ native_datetime=True,
201
+ )
202
+
203
+ With this flag enabled, the DATE and TIMESTAMP types (but note - not the
204
+ DATETIME or TIME types...confused yet ?) will not perform any bind parameter
205
+ or result processing. Execution of "func.current_date()" will return a string.
206
+ "func.current_timestamp()" is registered as returning a DATETIME type in
207
+ SQLAlchemy, so this function still receives SQLAlchemy-level result
208
+ processing.
209
+
210
+ .. _pysqlite_threading_pooling:
211
+
212
+ Threading/Pooling Behavior
213
+ ---------------------------
214
+
215
+ The ``sqlite3`` DBAPI by default prohibits the use of a particular connection
216
+ in a thread which is not the one in which it was created. As SQLite has
217
+ matured, it's behavior under multiple threads has improved, and even includes
218
+ options for memory only databases to be used in multiple threads.
219
+
220
+ The thread prohibition is known as "check same thread" and may be controlled
221
+ using the ``sqlite3`` parameter ``check_same_thread``, which will disable or
222
+ enable this check. SQLAlchemy's default behavior here is to set
223
+ ``check_same_thread`` to ``False`` automatically whenever a file-based database
224
+ is in use, to establish compatibility with the default pool class
225
+ :class:`.QueuePool`.
226
+
227
+ The SQLAlchemy ``pysqlite`` DBAPI establishes the connection pool differently
228
+ based on the kind of SQLite database that's requested:
229
+
230
+ * When a ``:memory:`` SQLite database is specified, the dialect by default
231
+ will use :class:`.SingletonThreadPool`. This pool maintains a single
232
+ connection per thread, so that all access to the engine within the current
233
+ thread use the same ``:memory:`` database - other threads would access a
234
+ different ``:memory:`` database. The ``check_same_thread`` parameter
235
+ defaults to ``True``.
236
+ * When a file-based database is specified, the dialect will use
237
+ :class:`.QueuePool` as the source of connections. at the same time,
238
+ the ``check_same_thread`` flag is set to False by default unless overridden.
239
+
240
+ .. versionchanged:: 2.0
241
+
242
+ SQLite file database engines now use :class:`.QueuePool` by default.
243
+ Previously, :class:`.NullPool` were used. The :class:`.NullPool` class
244
+ may be used by specifying it via the
245
+ :paramref:`_sa.create_engine.poolclass` parameter.
246
+
247
+ Disabling Connection Pooling for File Databases
248
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
249
+
250
+ Pooling may be disabled for a file based database by specifying the
251
+ :class:`.NullPool` implementation for the :func:`_sa.create_engine.poolclass`
252
+ parameter::
253
+
254
+ from sqlalchemy import NullPool
255
+
256
+ engine = create_engine("sqlite:///myfile.db", poolclass=NullPool)
257
+
258
+ It's been observed that the :class:`.NullPool` implementation incurs an
259
+ extremely small performance overhead for repeated checkouts due to the lack of
260
+ connection reuse implemented by :class:`.QueuePool`. However, it still
261
+ may be beneficial to use this class if the application is experiencing
262
+ issues with files being locked.
263
+
264
+ Using a Memory Database in Multiple Threads
265
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
266
+
267
+ To use a ``:memory:`` database in a multithreaded scenario, the same
268
+ connection object must be shared among threads, since the database exists
269
+ only within the scope of that connection. The
270
+ :class:`.StaticPool` implementation will maintain a single connection
271
+ globally, and the ``check_same_thread`` flag can be passed to Pysqlite
272
+ as ``False``::
273
+
274
+ from sqlalchemy.pool import StaticPool
275
+
276
+ engine = create_engine(
277
+ "sqlite://",
278
+ connect_args={"check_same_thread": False},
279
+ poolclass=StaticPool,
280
+ )
281
+
282
+ Note that using a ``:memory:`` database in multiple threads requires a recent
283
+ version of SQLite.
284
+
285
+ Using Temporary Tables with SQLite
286
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287
+
288
+ Due to the way SQLite deals with temporary tables, if you wish to use a
289
+ temporary table in a file-based SQLite database across multiple checkouts
290
+ from the connection pool, such as when using an ORM :class:`.Session` where
291
+ the temporary table should continue to remain after :meth:`.Session.commit` or
292
+ :meth:`.Session.rollback` is called, a pool which maintains a single
293
+ connection must be used. Use :class:`.SingletonThreadPool` if the scope is
294
+ only needed within the current thread, or :class:`.StaticPool` is scope is
295
+ needed within multiple threads for this case::
296
+
297
+ # maintain the same connection per thread
298
+ from sqlalchemy.pool import SingletonThreadPool
299
+
300
+ engine = create_engine("sqlite:///mydb.db", poolclass=SingletonThreadPool)
301
+
302
+
303
+ # maintain the same connection across all threads
304
+ from sqlalchemy.pool import StaticPool
305
+
306
+ engine = create_engine("sqlite:///mydb.db", poolclass=StaticPool)
307
+
308
+ Note that :class:`.SingletonThreadPool` should be configured for the number
309
+ of threads that are to be used; beyond that number, connections will be
310
+ closed out in a non deterministic way.
311
+
312
+
313
+ Dealing with Mixed String / Binary Columns
314
+ ------------------------------------------------------
315
+
316
+ The SQLite database is weakly typed, and as such it is possible when using
317
+ binary values, which in Python are represented as ``b'some string'``, that a
318
+ particular SQLite database can have data values within different rows where
319
+ some of them will be returned as a ``b''`` value by the Pysqlite driver, and
320
+ others will be returned as Python strings, e.g. ``''`` values. This situation
321
+ is not known to occur if the SQLAlchemy :class:`.LargeBinary` datatype is used
322
+ consistently, however if a particular SQLite database has data that was
323
+ inserted using the Pysqlite driver directly, or when using the SQLAlchemy
324
+ :class:`.String` type which was later changed to :class:`.LargeBinary`, the
325
+ table will not be consistently readable because SQLAlchemy's
326
+ :class:`.LargeBinary` datatype does not handle strings so it has no way of
327
+ "encoding" a value that is in string format.
328
+
329
+ To deal with a SQLite table that has mixed string / binary data in the
330
+ same column, use a custom type that will check each row individually::
331
+
332
+ from sqlalchemy import String
333
+ from sqlalchemy import TypeDecorator
334
+
335
+
336
+ class MixedBinary(TypeDecorator):
337
+ impl = String
338
+ cache_ok = True
339
+
340
+ def process_result_value(self, value, dialect):
341
+ if isinstance(value, str):
342
+ value = bytes(value, "utf-8")
343
+ elif value is not None:
344
+ value = bytes(value)
345
+
346
+ return value
347
+
348
+ Then use the above ``MixedBinary`` datatype in the place where
349
+ :class:`.LargeBinary` would normally be used.
350
+
351
+ .. _pysqlite_serializable:
352
+
353
+ Serializable isolation / Savepoints / Transactional DDL
354
+ -------------------------------------------------------
355
+
356
+ A newly revised version of this important section is now available
357
+ at the top level of the SQLAlchemy SQLite documentation, in the section
358
+ :ref:`sqlite_transactions`.
359
+
360
+
361
+ .. _pysqlite_udfs:
362
+
363
+ User-Defined Functions
364
+ ----------------------
365
+
366
+ pysqlite supports a `create_function() <https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function>`_
367
+ method that allows us to create our own user-defined functions (UDFs) in Python and use them directly in SQLite queries.
368
+ These functions are registered with a specific DBAPI Connection.
369
+
370
+ SQLAlchemy uses connection pooling with file-based SQLite databases, so we need to ensure that the UDF is attached to the
371
+ connection when it is created. That is accomplished with an event listener::
372
+
373
+ from sqlalchemy import create_engine
374
+ from sqlalchemy import event
375
+ from sqlalchemy import text
376
+
377
+
378
+ def udf():
379
+ return "udf-ok"
380
+
381
+
382
+ engine = create_engine("sqlite:///./db_file")
383
+
384
+
385
+ @event.listens_for(engine, "connect")
386
+ def connect(conn, rec):
387
+ conn.create_function("udf", 0, udf)
388
+
389
+
390
+ for i in range(5):
391
+ with engine.connect() as conn:
392
+ print(conn.scalar(text("SELECT UDF()")))
393
+
394
+ """ # noqa
395
+ from __future__ import annotations
396
+
397
+ import math
398
+ import os
399
+ import re
400
+ from typing import Any
401
+ from typing import Callable
402
+ from typing import cast
403
+ from typing import Optional
404
+ from typing import Pattern
405
+ from typing import TYPE_CHECKING
406
+ from typing import TypeVar
407
+ from typing import Union
408
+
409
+ from .base import DATE
410
+ from .base import DATETIME
411
+ from .base import SQLiteDialect
412
+ from ... import exc
413
+ from ... import pool
414
+ from ... import types as sqltypes
415
+ from ... import util
416
+ from ...util.typing import Self
417
+
418
+ if TYPE_CHECKING:
419
+ from ...engine.interfaces import ConnectArgsType
420
+ from ...engine.interfaces import DBAPIConnection
421
+ from ...engine.interfaces import DBAPICursor
422
+ from ...engine.interfaces import DBAPIModule
423
+ from ...engine.interfaces import IsolationLevel
424
+ from ...engine.interfaces import VersionInfoType
425
+ from ...engine.url import URL
426
+ from ...pool.base import PoolProxiedConnection
427
+ from ...sql.type_api import _BindProcessorType
428
+ from ...sql.type_api import _ResultProcessorType
429
+
430
+
431
+ class _SQLite_pysqliteTimeStamp(DATETIME):
432
+ def bind_processor( # type: ignore[override]
433
+ self, dialect: SQLiteDialect
434
+ ) -> Optional[_BindProcessorType[Any]]:
435
+ if dialect.native_datetime:
436
+ return None
437
+ else:
438
+ return DATETIME.bind_processor(self, dialect)
439
+
440
+ def result_processor( # type: ignore[override]
441
+ self, dialect: SQLiteDialect, coltype: object
442
+ ) -> Optional[_ResultProcessorType[Any]]:
443
+ if dialect.native_datetime:
444
+ return None
445
+ else:
446
+ return DATETIME.result_processor(self, dialect, coltype)
447
+
448
+
449
+ class _SQLite_pysqliteDate(DATE):
450
+ def bind_processor( # type: ignore[override]
451
+ self, dialect: SQLiteDialect
452
+ ) -> Optional[_BindProcessorType[Any]]:
453
+ if dialect.native_datetime:
454
+ return None
455
+ else:
456
+ return DATE.bind_processor(self, dialect)
457
+
458
+ def result_processor( # type: ignore[override]
459
+ self, dialect: SQLiteDialect, coltype: object
460
+ ) -> Optional[_ResultProcessorType[Any]]:
461
+ if dialect.native_datetime:
462
+ return None
463
+ else:
464
+ return DATE.result_processor(self, dialect, coltype)
465
+
466
+
467
+ class SQLiteDialect_pysqlite(SQLiteDialect):
468
+ default_paramstyle = "qmark"
469
+ supports_statement_cache = True
470
+ returns_native_bytes = True
471
+
472
+ colspecs = util.update_copy(
473
+ SQLiteDialect.colspecs,
474
+ {
475
+ sqltypes.Date: _SQLite_pysqliteDate,
476
+ sqltypes.TIMESTAMP: _SQLite_pysqliteTimeStamp,
477
+ },
478
+ )
479
+
480
+ description_encoding = None
481
+
482
+ driver = "pysqlite"
483
+
484
+ @classmethod
485
+ def import_dbapi(cls) -> DBAPIModule:
486
+ from sqlite3 import dbapi2 as sqlite
487
+
488
+ return cast("DBAPIModule", sqlite)
489
+
490
+ @classmethod
491
+ def _is_url_file_db(cls, url: URL) -> bool:
492
+ if (url.database and url.database != ":memory:") and (
493
+ url.query.get("mode", None) != "memory"
494
+ ):
495
+ return True
496
+ else:
497
+ return False
498
+
499
+ @classmethod
500
+ def get_pool_class(cls, url: URL) -> type[pool.Pool]:
501
+ if cls._is_url_file_db(url):
502
+ return pool.QueuePool
503
+ else:
504
+ return pool.SingletonThreadPool
505
+
506
+ def _get_server_version_info(self, connection: Any) -> VersionInfoType:
507
+ return self.dbapi.sqlite_version_info # type: ignore
508
+
509
+ _isolation_lookup = SQLiteDialect._isolation_lookup.union(
510
+ {
511
+ "AUTOCOMMIT": None, # type: ignore[dict-item]
512
+ }
513
+ )
514
+
515
+ def set_isolation_level(
516
+ self, dbapi_connection: DBAPIConnection, level: IsolationLevel
517
+ ) -> None:
518
+ if level == "AUTOCOMMIT":
519
+ dbapi_connection.isolation_level = None
520
+ else:
521
+ dbapi_connection.isolation_level = ""
522
+ return super().set_isolation_level(dbapi_connection, level)
523
+
524
+ def detect_autocommit_setting(self, dbapi_conn: DBAPIConnection) -> bool:
525
+ return dbapi_conn.isolation_level is None
526
+
527
+ def on_connect(self) -> Callable[[DBAPIConnection], None]:
528
+ def regexp(a: str, b: Optional[str]) -> Optional[bool]:
529
+ if b is None:
530
+ return None
531
+ return re.search(a, b) is not None
532
+
533
+ if util.py38 and self._get_server_version_info(None) >= (3, 9):
534
+ # sqlite must be greater than 3.8.3 for deterministic=True
535
+ # https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function
536
+ # the check is more conservative since there were still issues
537
+ # with following 3.8 sqlite versions
538
+ create_func_kw = {"deterministic": True}
539
+ else:
540
+ create_func_kw = {}
541
+
542
+ def set_regexp(dbapi_connection: DBAPIConnection) -> None:
543
+ dbapi_connection.create_function(
544
+ "regexp", 2, regexp, **create_func_kw
545
+ )
546
+
547
+ def floor_func(dbapi_connection: DBAPIConnection) -> None:
548
+ # NOTE: floor is optionally present in sqlite 3.35+ , however
549
+ # as it is normally non-present we deliver floor() unconditionally
550
+ # for now.
551
+ # https://www.sqlite.org/lang_mathfunc.html
552
+ dbapi_connection.create_function(
553
+ "floor", 1, math.floor, **create_func_kw
554
+ )
555
+
556
+ fns = [set_regexp, floor_func]
557
+
558
+ def connect(conn: DBAPIConnection) -> None:
559
+ for fn in fns:
560
+ fn(conn)
561
+
562
+ return connect
563
+
564
+ def create_connect_args(self, url: URL) -> ConnectArgsType:
565
+ if url.username or url.password or url.host or url.port:
566
+ raise exc.ArgumentError(
567
+ "Invalid SQLite URL: %s\n"
568
+ "Valid SQLite URL forms are:\n"
569
+ " sqlite:///:memory: (or, sqlite://)\n"
570
+ " sqlite:///relative/path/to/file.db\n"
571
+ " sqlite:////absolute/path/to/file.db" % (url,)
572
+ )
573
+
574
+ # theoretically, this list can be augmented, at least as far as
575
+ # parameter names accepted by sqlite3/pysqlite, using
576
+ # inspect.getfullargspec(). for the moment this seems like overkill
577
+ # as these parameters don't change very often, and as always,
578
+ # parameters passed to connect_args will always go to the
579
+ # sqlite3/pysqlite driver.
580
+ pysqlite_args = [
581
+ ("uri", bool),
582
+ ("timeout", float),
583
+ ("isolation_level", str),
584
+ ("detect_types", int),
585
+ ("check_same_thread", bool),
586
+ ("cached_statements", int),
587
+ ]
588
+ opts = url.query
589
+ pysqlite_opts: dict[str, Any] = {}
590
+ for key, type_ in pysqlite_args:
591
+ util.coerce_kw_type(opts, key, type_, dest=pysqlite_opts)
592
+
593
+ if pysqlite_opts.get("uri", False):
594
+ uri_opts = dict(opts)
595
+ # here, we are actually separating the parameters that go to
596
+ # sqlite3/pysqlite vs. those that go the SQLite URI. What if
597
+ # two names conflict? again, this seems to be not the case right
598
+ # now, and in the case that new names are added to
599
+ # either side which overlap, again the sqlite3/pysqlite parameters
600
+ # can be passed through connect_args instead of in the URL.
601
+ # If SQLite native URIs add a parameter like "timeout" that
602
+ # we already have listed here for the python driver, then we need
603
+ # to adjust for that here.
604
+ for key, type_ in pysqlite_args:
605
+ uri_opts.pop(key, None)
606
+ filename: str = url.database # type: ignore[assignment]
607
+ if uri_opts:
608
+ # sorting of keys is for unit test support
609
+ filename += "?" + (
610
+ "&".join(
611
+ "%s=%s" % (key, uri_opts[key])
612
+ for key in sorted(uri_opts)
613
+ )
614
+ )
615
+ else:
616
+ filename = url.database or ":memory:"
617
+ if filename != ":memory:":
618
+ filename = os.path.abspath(filename)
619
+
620
+ pysqlite_opts.setdefault(
621
+ "check_same_thread", not self._is_url_file_db(url)
622
+ )
623
+
624
+ return ([filename], pysqlite_opts)
625
+
626
+ def is_disconnect(
627
+ self,
628
+ e: DBAPIModule.Error,
629
+ connection: Optional[Union[PoolProxiedConnection, DBAPIConnection]],
630
+ cursor: Optional[DBAPICursor],
631
+ ) -> bool:
632
+ self.dbapi = cast("DBAPIModule", self.dbapi)
633
+ return isinstance(
634
+ e, self.dbapi.ProgrammingError
635
+ ) and "Cannot operate on a closed database." in str(e)
636
+
637
+
638
+ dialect = SQLiteDialect_pysqlite
639
+
640
+
641
+ class _SQLiteDialect_pysqlite_numeric(SQLiteDialect_pysqlite):
642
+ """numeric dialect for testing only
643
+
644
+ internal use only. This dialect is **NOT** supported by SQLAlchemy
645
+ and may change at any time.
646
+
647
+ """
648
+
649
+ supports_statement_cache = True
650
+ default_paramstyle = "numeric"
651
+ driver = "pysqlite_numeric"
652
+
653
+ _first_bind = ":1"
654
+ _not_in_statement_regexp: Optional[Pattern[str]] = None
655
+
656
+ def __init__(self, *arg: Any, **kw: Any) -> None:
657
+ kw.setdefault("paramstyle", "numeric")
658
+ super().__init__(*arg, **kw)
659
+
660
+ def create_connect_args(self, url: URL) -> ConnectArgsType:
661
+ arg, opts = super().create_connect_args(url)
662
+ opts["factory"] = self._fix_sqlite_issue_99953()
663
+ return arg, opts
664
+
665
+ def _fix_sqlite_issue_99953(self) -> Any:
666
+ import sqlite3
667
+
668
+ first_bind = self._first_bind
669
+ if self._not_in_statement_regexp:
670
+ nis = self._not_in_statement_regexp
671
+
672
+ def _test_sql(sql: str) -> None:
673
+ m = nis.search(sql)
674
+ assert not m, f"Found {nis.pattern!r} in {sql!r}"
675
+
676
+ else:
677
+
678
+ def _test_sql(sql: str) -> None:
679
+ pass
680
+
681
+ def _numeric_param_as_dict(
682
+ parameters: Any,
683
+ ) -> Union[dict[str, Any], tuple[Any, ...]]:
684
+ if parameters:
685
+ assert isinstance(parameters, tuple)
686
+ return {
687
+ str(idx): value for idx, value in enumerate(parameters, 1)
688
+ }
689
+ else:
690
+ return ()
691
+
692
+ class SQLiteFix99953Cursor(sqlite3.Cursor):
693
+ def execute(self, sql: str, parameters: Any = ()) -> Self:
694
+ _test_sql(sql)
695
+ if first_bind in sql:
696
+ parameters = _numeric_param_as_dict(parameters)
697
+ return super().execute(sql, parameters)
698
+
699
+ def executemany(self, sql: str, parameters: Any) -> Self:
700
+ _test_sql(sql)
701
+ if first_bind in sql:
702
+ parameters = [
703
+ _numeric_param_as_dict(p) for p in parameters
704
+ ]
705
+ return super().executemany(sql, parameters)
706
+
707
+ class SQLiteFix99953Connection(sqlite3.Connection):
708
+ _CursorT = TypeVar("_CursorT", bound=sqlite3.Cursor)
709
+
710
+ def cursor(
711
+ self,
712
+ factory: Optional[
713
+ Callable[[sqlite3.Connection], _CursorT]
714
+ ] = None,
715
+ ) -> _CursorT:
716
+ if factory is None:
717
+ factory = SQLiteFix99953Cursor # type: ignore[assignment]
718
+ return super().cursor(factory=factory) # type: ignore[return-value] # noqa[E501]
719
+
720
+ def execute(
721
+ self, sql: str, parameters: Any = ()
722
+ ) -> sqlite3.Cursor:
723
+ _test_sql(sql)
724
+ if first_bind in sql:
725
+ parameters = _numeric_param_as_dict(parameters)
726
+ return super().execute(sql, parameters)
727
+
728
+ def executemany(self, sql: str, parameters: Any) -> sqlite3.Cursor:
729
+ _test_sql(sql)
730
+ if first_bind in sql:
731
+ parameters = [
732
+ _numeric_param_as_dict(p) for p in parameters
733
+ ]
734
+ return super().executemany(sql, parameters)
735
+
736
+ return SQLiteFix99953Connection
737
+
738
+
739
+ class _SQLiteDialect_pysqlite_dollar(_SQLiteDialect_pysqlite_numeric):
740
+ """numeric dialect that uses $ for testing only
741
+
742
+ internal use only. This dialect is **NOT** supported by SQLAlchemy
743
+ and may change at any time.
744
+
745
+ """
746
+
747
+ supports_statement_cache = True
748
+ default_paramstyle = "numeric_dollar"
749
+ driver = "pysqlite_dollar"
750
+
751
+ _first_bind = "$1"
752
+ _not_in_statement_regexp = re.compile(r"[^\d]:\d+")
753
+
754
+ def __init__(self, *arg: Any, **kw: Any) -> None:
755
+ kw.setdefault("paramstyle", "numeric_dollar")
756
+ super().__init__(*arg, **kw)