SQLAlchemy 2.1.0b2__cp313-cp313t-win_arm64.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 (270) hide show
  1. sqlalchemy/__init__.py +298 -0
  2. sqlalchemy/connectors/__init__.py +18 -0
  3. sqlalchemy/connectors/aioodbc.py +171 -0
  4. sqlalchemy/connectors/asyncio.py +476 -0
  5. sqlalchemy/connectors/pyodbc.py +250 -0
  6. sqlalchemy/dialects/__init__.py +62 -0
  7. sqlalchemy/dialects/_typing.py +30 -0
  8. sqlalchemy/dialects/mssql/__init__.py +89 -0
  9. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  10. sqlalchemy/dialects/mssql/base.py +4166 -0
  11. sqlalchemy/dialects/mssql/information_schema.py +285 -0
  12. sqlalchemy/dialects/mssql/json.py +140 -0
  13. sqlalchemy/dialects/mssql/mssqlpython.py +220 -0
  14. sqlalchemy/dialects/mssql/provision.py +196 -0
  15. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  16. sqlalchemy/dialects/mssql/pyodbc.py +698 -0
  17. sqlalchemy/dialects/mysql/__init__.py +106 -0
  18. sqlalchemy/dialects/mysql/_mariadb_shim.py +312 -0
  19. sqlalchemy/dialects/mysql/aiomysql.py +226 -0
  20. sqlalchemy/dialects/mysql/asyncmy.py +214 -0
  21. sqlalchemy/dialects/mysql/base.py +3877 -0
  22. sqlalchemy/dialects/mysql/cymysql.py +106 -0
  23. sqlalchemy/dialects/mysql/dml.py +279 -0
  24. sqlalchemy/dialects/mysql/enumerated.py +277 -0
  25. sqlalchemy/dialects/mysql/expression.py +146 -0
  26. sqlalchemy/dialects/mysql/json.py +92 -0
  27. sqlalchemy/dialects/mysql/mariadb.py +67 -0
  28. sqlalchemy/dialects/mysql/mariadbconnector.py +330 -0
  29. sqlalchemy/dialects/mysql/mysqlconnector.py +296 -0
  30. sqlalchemy/dialects/mysql/mysqldb.py +312 -0
  31. sqlalchemy/dialects/mysql/provision.py +153 -0
  32. sqlalchemy/dialects/mysql/pymysql.py +157 -0
  33. sqlalchemy/dialects/mysql/pyodbc.py +156 -0
  34. sqlalchemy/dialects/mysql/reflection.py +724 -0
  35. sqlalchemy/dialects/mysql/reserved_words.py +570 -0
  36. sqlalchemy/dialects/mysql/types.py +845 -0
  37. sqlalchemy/dialects/oracle/__init__.py +85 -0
  38. sqlalchemy/dialects/oracle/base.py +3977 -0
  39. sqlalchemy/dialects/oracle/cx_oracle.py +1601 -0
  40. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  41. sqlalchemy/dialects/oracle/json.py +158 -0
  42. sqlalchemy/dialects/oracle/oracledb.py +909 -0
  43. sqlalchemy/dialects/oracle/provision.py +288 -0
  44. sqlalchemy/dialects/oracle/types.py +367 -0
  45. sqlalchemy/dialects/oracle/vector.py +368 -0
  46. sqlalchemy/dialects/postgresql/__init__.py +171 -0
  47. sqlalchemy/dialects/postgresql/_psycopg_common.py +229 -0
  48. sqlalchemy/dialects/postgresql/array.py +534 -0
  49. sqlalchemy/dialects/postgresql/asyncpg.py +1323 -0
  50. sqlalchemy/dialects/postgresql/base.py +5789 -0
  51. sqlalchemy/dialects/postgresql/bitstring.py +327 -0
  52. sqlalchemy/dialects/postgresql/dml.py +360 -0
  53. sqlalchemy/dialects/postgresql/ext.py +593 -0
  54. sqlalchemy/dialects/postgresql/hstore.py +423 -0
  55. sqlalchemy/dialects/postgresql/json.py +408 -0
  56. sqlalchemy/dialects/postgresql/named_types.py +521 -0
  57. sqlalchemy/dialects/postgresql/operators.py +130 -0
  58. sqlalchemy/dialects/postgresql/pg8000.py +670 -0
  59. sqlalchemy/dialects/postgresql/pg_catalog.py +344 -0
  60. sqlalchemy/dialects/postgresql/provision.py +184 -0
  61. sqlalchemy/dialects/postgresql/psycopg.py +799 -0
  62. sqlalchemy/dialects/postgresql/psycopg2.py +860 -0
  63. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  64. sqlalchemy/dialects/postgresql/ranges.py +1002 -0
  65. sqlalchemy/dialects/postgresql/types.py +388 -0
  66. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  67. sqlalchemy/dialects/sqlite/aiosqlite.py +321 -0
  68. sqlalchemy/dialects/sqlite/base.py +3063 -0
  69. sqlalchemy/dialects/sqlite/dml.py +279 -0
  70. sqlalchemy/dialects/sqlite/json.py +100 -0
  71. sqlalchemy/dialects/sqlite/provision.py +229 -0
  72. sqlalchemy/dialects/sqlite/pysqlcipher.py +161 -0
  73. sqlalchemy/dialects/sqlite/pysqlite.py +754 -0
  74. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  75. sqlalchemy/engine/__init__.py +62 -0
  76. sqlalchemy/engine/_processors_cy.cp313t-win_arm64.pyd +0 -0
  77. sqlalchemy/engine/_processors_cy.py +92 -0
  78. sqlalchemy/engine/_result_cy.cp313t-win_arm64.pyd +0 -0
  79. sqlalchemy/engine/_result_cy.py +633 -0
  80. sqlalchemy/engine/_row_cy.cp313t-win_arm64.pyd +0 -0
  81. sqlalchemy/engine/_row_cy.py +232 -0
  82. sqlalchemy/engine/_util_cy.cp313t-win_arm64.pyd +0 -0
  83. sqlalchemy/engine/_util_cy.py +136 -0
  84. sqlalchemy/engine/base.py +3354 -0
  85. sqlalchemy/engine/characteristics.py +155 -0
  86. sqlalchemy/engine/create.py +877 -0
  87. sqlalchemy/engine/cursor.py +2421 -0
  88. sqlalchemy/engine/default.py +2402 -0
  89. sqlalchemy/engine/events.py +965 -0
  90. sqlalchemy/engine/interfaces.py +3495 -0
  91. sqlalchemy/engine/mock.py +134 -0
  92. sqlalchemy/engine/processors.py +82 -0
  93. sqlalchemy/engine/reflection.py +2100 -0
  94. sqlalchemy/engine/result.py +1966 -0
  95. sqlalchemy/engine/row.py +397 -0
  96. sqlalchemy/engine/strategies.py +16 -0
  97. sqlalchemy/engine/url.py +922 -0
  98. sqlalchemy/engine/util.py +156 -0
  99. sqlalchemy/event/__init__.py +26 -0
  100. sqlalchemy/event/api.py +220 -0
  101. sqlalchemy/event/attr.py +674 -0
  102. sqlalchemy/event/base.py +472 -0
  103. sqlalchemy/event/legacy.py +258 -0
  104. sqlalchemy/event/registry.py +390 -0
  105. sqlalchemy/events.py +17 -0
  106. sqlalchemy/exc.py +922 -0
  107. sqlalchemy/ext/__init__.py +11 -0
  108. sqlalchemy/ext/associationproxy.py +2072 -0
  109. sqlalchemy/ext/asyncio/__init__.py +29 -0
  110. sqlalchemy/ext/asyncio/base.py +281 -0
  111. sqlalchemy/ext/asyncio/engine.py +1487 -0
  112. sqlalchemy/ext/asyncio/exc.py +21 -0
  113. sqlalchemy/ext/asyncio/result.py +994 -0
  114. sqlalchemy/ext/asyncio/scoping.py +1679 -0
  115. sqlalchemy/ext/asyncio/session.py +2007 -0
  116. sqlalchemy/ext/automap.py +1701 -0
  117. sqlalchemy/ext/baked.py +559 -0
  118. sqlalchemy/ext/compiler.py +600 -0
  119. sqlalchemy/ext/declarative/__init__.py +65 -0
  120. sqlalchemy/ext/declarative/extensions.py +560 -0
  121. sqlalchemy/ext/horizontal_shard.py +481 -0
  122. sqlalchemy/ext/hybrid.py +1877 -0
  123. sqlalchemy/ext/indexable.py +364 -0
  124. sqlalchemy/ext/instrumentation.py +450 -0
  125. sqlalchemy/ext/mutable.py +1081 -0
  126. sqlalchemy/ext/orderinglist.py +439 -0
  127. sqlalchemy/ext/serializer.py +185 -0
  128. sqlalchemy/future/__init__.py +16 -0
  129. sqlalchemy/future/engine.py +15 -0
  130. sqlalchemy/inspection.py +174 -0
  131. sqlalchemy/log.py +283 -0
  132. sqlalchemy/orm/__init__.py +176 -0
  133. sqlalchemy/orm/_orm_constructors.py +2694 -0
  134. sqlalchemy/orm/_typing.py +179 -0
  135. sqlalchemy/orm/attributes.py +2868 -0
  136. sqlalchemy/orm/base.py +976 -0
  137. sqlalchemy/orm/bulk_persistence.py +2152 -0
  138. sqlalchemy/orm/clsregistry.py +582 -0
  139. sqlalchemy/orm/collections.py +1568 -0
  140. sqlalchemy/orm/context.py +3471 -0
  141. sqlalchemy/orm/decl_api.py +2280 -0
  142. sqlalchemy/orm/decl_base.py +2309 -0
  143. sqlalchemy/orm/dependency.py +1306 -0
  144. sqlalchemy/orm/descriptor_props.py +1183 -0
  145. sqlalchemy/orm/dynamic.py +307 -0
  146. sqlalchemy/orm/evaluator.py +379 -0
  147. sqlalchemy/orm/events.py +3386 -0
  148. sqlalchemy/orm/exc.py +237 -0
  149. sqlalchemy/orm/identity.py +302 -0
  150. sqlalchemy/orm/instrumentation.py +746 -0
  151. sqlalchemy/orm/interfaces.py +1589 -0
  152. sqlalchemy/orm/loading.py +1684 -0
  153. sqlalchemy/orm/mapped_collection.py +557 -0
  154. sqlalchemy/orm/mapper.py +4411 -0
  155. sqlalchemy/orm/path_registry.py +829 -0
  156. sqlalchemy/orm/persistence.py +1789 -0
  157. sqlalchemy/orm/properties.py +973 -0
  158. sqlalchemy/orm/query.py +3528 -0
  159. sqlalchemy/orm/relationships.py +3570 -0
  160. sqlalchemy/orm/scoping.py +2232 -0
  161. sqlalchemy/orm/session.py +5403 -0
  162. sqlalchemy/orm/state.py +1175 -0
  163. sqlalchemy/orm/state_changes.py +196 -0
  164. sqlalchemy/orm/strategies.py +3492 -0
  165. sqlalchemy/orm/strategy_options.py +2562 -0
  166. sqlalchemy/orm/sync.py +164 -0
  167. sqlalchemy/orm/unitofwork.py +798 -0
  168. sqlalchemy/orm/util.py +2438 -0
  169. sqlalchemy/orm/writeonly.py +694 -0
  170. sqlalchemy/pool/__init__.py +41 -0
  171. sqlalchemy/pool/base.py +1522 -0
  172. sqlalchemy/pool/events.py +375 -0
  173. sqlalchemy/pool/impl.py +582 -0
  174. sqlalchemy/py.typed +0 -0
  175. sqlalchemy/schema.py +74 -0
  176. sqlalchemy/sql/__init__.py +156 -0
  177. sqlalchemy/sql/_annotated_cols.py +397 -0
  178. sqlalchemy/sql/_dml_constructors.py +132 -0
  179. sqlalchemy/sql/_elements_constructors.py +2164 -0
  180. sqlalchemy/sql/_orm_types.py +20 -0
  181. sqlalchemy/sql/_selectable_constructors.py +840 -0
  182. sqlalchemy/sql/_typing.py +487 -0
  183. sqlalchemy/sql/_util_cy.cp313t-win_arm64.pyd +0 -0
  184. sqlalchemy/sql/_util_cy.py +127 -0
  185. sqlalchemy/sql/annotation.py +590 -0
  186. sqlalchemy/sql/base.py +2699 -0
  187. sqlalchemy/sql/cache_key.py +1066 -0
  188. sqlalchemy/sql/coercions.py +1373 -0
  189. sqlalchemy/sql/compiler.py +8327 -0
  190. sqlalchemy/sql/crud.py +1815 -0
  191. sqlalchemy/sql/ddl.py +1928 -0
  192. sqlalchemy/sql/default_comparator.py +654 -0
  193. sqlalchemy/sql/dml.py +1977 -0
  194. sqlalchemy/sql/elements.py +6033 -0
  195. sqlalchemy/sql/events.py +458 -0
  196. sqlalchemy/sql/expression.py +172 -0
  197. sqlalchemy/sql/functions.py +2305 -0
  198. sqlalchemy/sql/lambdas.py +1443 -0
  199. sqlalchemy/sql/naming.py +209 -0
  200. sqlalchemy/sql/operators.py +2897 -0
  201. sqlalchemy/sql/roles.py +332 -0
  202. sqlalchemy/sql/schema.py +6703 -0
  203. sqlalchemy/sql/selectable.py +7553 -0
  204. sqlalchemy/sql/sqltypes.py +4093 -0
  205. sqlalchemy/sql/traversals.py +1042 -0
  206. sqlalchemy/sql/type_api.py +2446 -0
  207. sqlalchemy/sql/util.py +1495 -0
  208. sqlalchemy/sql/visitors.py +1157 -0
  209. sqlalchemy/testing/__init__.py +96 -0
  210. sqlalchemy/testing/assertions.py +1007 -0
  211. sqlalchemy/testing/assertsql.py +519 -0
  212. sqlalchemy/testing/asyncio.py +128 -0
  213. sqlalchemy/testing/config.py +440 -0
  214. sqlalchemy/testing/engines.py +483 -0
  215. sqlalchemy/testing/entities.py +117 -0
  216. sqlalchemy/testing/exclusions.py +476 -0
  217. sqlalchemy/testing/fixtures/__init__.py +30 -0
  218. sqlalchemy/testing/fixtures/base.py +384 -0
  219. sqlalchemy/testing/fixtures/mypy.py +247 -0
  220. sqlalchemy/testing/fixtures/orm.py +227 -0
  221. sqlalchemy/testing/fixtures/sql.py +538 -0
  222. sqlalchemy/testing/pickleable.py +155 -0
  223. sqlalchemy/testing/plugin/__init__.py +6 -0
  224. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  225. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  226. sqlalchemy/testing/plugin/pytestplugin.py +892 -0
  227. sqlalchemy/testing/profiling.py +329 -0
  228. sqlalchemy/testing/provision.py +613 -0
  229. sqlalchemy/testing/requirements.py +1978 -0
  230. sqlalchemy/testing/schema.py +198 -0
  231. sqlalchemy/testing/suite/__init__.py +19 -0
  232. sqlalchemy/testing/suite/test_cte.py +237 -0
  233. sqlalchemy/testing/suite/test_ddl.py +420 -0
  234. sqlalchemy/testing/suite/test_dialect.py +776 -0
  235. sqlalchemy/testing/suite/test_insert.py +630 -0
  236. sqlalchemy/testing/suite/test_reflection.py +3557 -0
  237. sqlalchemy/testing/suite/test_results.py +660 -0
  238. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  239. sqlalchemy/testing/suite/test_select.py +2112 -0
  240. sqlalchemy/testing/suite/test_sequence.py +317 -0
  241. sqlalchemy/testing/suite/test_table_via_select.py +686 -0
  242. sqlalchemy/testing/suite/test_types.py +2271 -0
  243. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  244. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  245. sqlalchemy/testing/util.py +535 -0
  246. sqlalchemy/testing/warnings.py +52 -0
  247. sqlalchemy/types.py +76 -0
  248. sqlalchemy/util/__init__.py +158 -0
  249. sqlalchemy/util/_collections.py +688 -0
  250. sqlalchemy/util/_collections_cy.cp313t-win_arm64.pyd +0 -0
  251. sqlalchemy/util/_collections_cy.pxd +8 -0
  252. sqlalchemy/util/_collections_cy.py +516 -0
  253. sqlalchemy/util/_has_cython.py +46 -0
  254. sqlalchemy/util/_immutabledict_cy.cp313t-win_arm64.pyd +0 -0
  255. sqlalchemy/util/_immutabledict_cy.py +240 -0
  256. sqlalchemy/util/compat.py +299 -0
  257. sqlalchemy/util/concurrency.py +322 -0
  258. sqlalchemy/util/cython.py +79 -0
  259. sqlalchemy/util/deprecations.py +401 -0
  260. sqlalchemy/util/langhelpers.py +2320 -0
  261. sqlalchemy/util/preloaded.py +152 -0
  262. sqlalchemy/util/queue.py +304 -0
  263. sqlalchemy/util/tool_support.py +201 -0
  264. sqlalchemy/util/topological.py +120 -0
  265. sqlalchemy/util/typing.py +711 -0
  266. sqlalchemy-2.1.0b2.dist-info/METADATA +269 -0
  267. sqlalchemy-2.1.0b2.dist-info/RECORD +270 -0
  268. sqlalchemy-2.1.0b2.dist-info/WHEEL +5 -0
  269. sqlalchemy-2.1.0b2.dist-info/licenses/LICENSE +19 -0
  270. sqlalchemy-2.1.0b2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,660 @@
1
+ # testing/suite/test_results.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
+ # mypy: ignore-errors
8
+
9
+ import datetime
10
+ import re
11
+
12
+ from .. import engines
13
+ from .. import fixtures
14
+ from ..assertions import eq_
15
+ from ..config import requirements
16
+ from ..schema import Column
17
+ from ..schema import Table
18
+ from ... import DateTime
19
+ from ... import func
20
+ from ... import Integer
21
+ from ... import quoted_name
22
+ from ... import select
23
+ from ... import sql
24
+ from ... import String
25
+ from ... import testing
26
+ from ... import text
27
+
28
+
29
+ class RowFetchTest(fixtures.TablesTest):
30
+ __backend__ = True
31
+
32
+ @classmethod
33
+ def define_tables(cls, metadata):
34
+ Table(
35
+ "plain_pk",
36
+ metadata,
37
+ Column("id", Integer, primary_key=True),
38
+ Column("data", String(50)),
39
+ )
40
+ Table(
41
+ "has_dates",
42
+ metadata,
43
+ Column("id", Integer, primary_key=True),
44
+ Column("today", DateTime),
45
+ )
46
+
47
+ @classmethod
48
+ def insert_data(cls, connection):
49
+ connection.execute(
50
+ cls.tables.plain_pk.insert(),
51
+ [
52
+ {"id": 1, "data": "d1"},
53
+ {"id": 2, "data": "d2"},
54
+ {"id": 3, "data": "d3"},
55
+ ],
56
+ )
57
+
58
+ connection.execute(
59
+ cls.tables.has_dates.insert(),
60
+ [{"id": 1, "today": datetime.datetime(2006, 5, 12, 12, 0, 0)}],
61
+ )
62
+
63
+ def test_via_attr(self, connection):
64
+ row = connection.execute(
65
+ self.tables.plain_pk.select().order_by(self.tables.plain_pk.c.id)
66
+ ).first()
67
+
68
+ eq_(row.id, 1)
69
+ eq_(row.data, "d1")
70
+
71
+ def test_via_string(self, connection):
72
+ row = connection.execute(
73
+ self.tables.plain_pk.select().order_by(self.tables.plain_pk.c.id)
74
+ ).first()
75
+
76
+ eq_(row._mapping["id"], 1)
77
+ eq_(row._mapping["data"], "d1")
78
+
79
+ def test_via_int(self, connection):
80
+ row = connection.execute(
81
+ self.tables.plain_pk.select().order_by(self.tables.plain_pk.c.id)
82
+ ).first()
83
+
84
+ eq_(row[0], 1)
85
+ eq_(row[1], "d1")
86
+
87
+ def test_via_col_object(self, connection):
88
+ row = connection.execute(
89
+ self.tables.plain_pk.select().order_by(self.tables.plain_pk.c.id)
90
+ ).first()
91
+
92
+ eq_(row._mapping[self.tables.plain_pk.c.id], 1)
93
+ eq_(row._mapping[self.tables.plain_pk.c.data], "d1")
94
+
95
+ @requirements.duplicate_names_in_cursor_description
96
+ def test_row_with_dupe_names(self, connection):
97
+ result = connection.execute(
98
+ select(
99
+ self.tables.plain_pk.c.data,
100
+ self.tables.plain_pk.c.data.label("data"),
101
+ ).order_by(self.tables.plain_pk.c.id)
102
+ )
103
+ row = result.first()
104
+ eq_(result.keys(), ["data", "data"])
105
+ eq_(row, ("d1", "d1"))
106
+
107
+ def test_row_w_scalar_select(self, connection):
108
+ """test that a scalar select as a column is returned as such
109
+ and that type conversion works OK.
110
+
111
+ (this is half a SQLAlchemy Core test and half to catch database
112
+ backends that may have unusual behavior with scalar selects.)
113
+
114
+ """
115
+ datetable = self.tables.has_dates
116
+ s = select(datetable.alias("x").c.today).scalar_subquery()
117
+ s2 = select(datetable.c.id, s.label("somelabel"))
118
+ row = connection.execute(s2).first()
119
+
120
+ eq_(row.somelabel, datetime.datetime(2006, 5, 12, 12, 0, 0))
121
+
122
+
123
+ class NameDenormalizeTest(fixtures.TablesTest):
124
+ __backend__ = True
125
+
126
+ @classmethod
127
+ def define_tables(cls, metadata):
128
+ cls.tables.denormalize_table = Table(
129
+ "denormalize_table",
130
+ metadata,
131
+ Column("id", Integer, primary_key=True),
132
+ Column("all_lowercase", Integer),
133
+ Column("ALL_UPPERCASE", Integer),
134
+ Column("MixedCase", Integer),
135
+ Column(quoted_name("all_lowercase_quoted", quote=True), Integer),
136
+ Column(quoted_name("ALL_UPPERCASE_QUOTED", quote=True), Integer),
137
+ )
138
+
139
+ @classmethod
140
+ def insert_data(cls, connection):
141
+ connection.execute(
142
+ cls.tables.denormalize_table.insert(),
143
+ {
144
+ "id": 1,
145
+ "all_lowercase": 5,
146
+ "ALL_UPPERCASE": 6,
147
+ "MixedCase": 7,
148
+ "all_lowercase_quoted": 8,
149
+ "ALL_UPPERCASE_QUOTED": 9,
150
+ },
151
+ )
152
+
153
+ def _assert_row_mapping(self, row, mapping, include_cols=None):
154
+ eq_(row._mapping, mapping)
155
+
156
+ for k in mapping:
157
+ eq_(row._mapping[k], mapping[k])
158
+ eq_(getattr(row, k), mapping[k])
159
+
160
+ for idx, k in enumerate(mapping):
161
+ eq_(row[idx], mapping[k])
162
+
163
+ if include_cols:
164
+ for col, (idx, k) in zip(include_cols, enumerate(mapping)):
165
+ eq_(row._mapping[col], mapping[k])
166
+
167
+ @testing.variation(
168
+ "stmt_type", ["driver_sql", "text_star", "core_select", "text_cols"]
169
+ )
170
+ @testing.variation("use_driver_cols", [True, False])
171
+ def test_cols_driver_cols(self, connection, stmt_type, use_driver_cols):
172
+ if stmt_type.driver_sql or stmt_type.text_star or stmt_type.text_cols:
173
+ stmt = select("*").select_from(self.tables.denormalize_table)
174
+ text_stmt = str(stmt.compile(connection))
175
+
176
+ if stmt_type.text_star or stmt_type.text_cols:
177
+ stmt = text(text_stmt)
178
+
179
+ if stmt_type.text_cols:
180
+ stmt = stmt.columns(*self.tables.denormalize_table.c)
181
+ elif stmt_type.core_select:
182
+ stmt = select(self.tables.denormalize_table)
183
+ else:
184
+ stmt_type.fail()
185
+
186
+ if use_driver_cols:
187
+ execution_options = {"driver_column_names": True}
188
+ else:
189
+ execution_options = {}
190
+
191
+ if stmt_type.driver_sql:
192
+ row = connection.exec_driver_sql(
193
+ text_stmt, execution_options=execution_options
194
+ ).one()
195
+ else:
196
+ row = connection.execute(
197
+ stmt,
198
+ execution_options=execution_options,
199
+ ).one()
200
+
201
+ if (
202
+ stmt_type.core_select and not use_driver_cols
203
+ ) or not testing.requires.denormalized_names.enabled:
204
+ self._assert_row_mapping(
205
+ row,
206
+ {
207
+ "id": 1,
208
+ "all_lowercase": 5,
209
+ "ALL_UPPERCASE": 6,
210
+ "MixedCase": 7,
211
+ "all_lowercase_quoted": 8,
212
+ "ALL_UPPERCASE_QUOTED": 9,
213
+ },
214
+ )
215
+
216
+ if testing.requires.denormalized_names.enabled:
217
+ # with driver column names, raw cursor.description
218
+ # is used. this is clearly not useful for non-quoted names.
219
+ if use_driver_cols:
220
+ self._assert_row_mapping(
221
+ row,
222
+ {
223
+ "ID": 1,
224
+ "ALL_LOWERCASE": 5,
225
+ "ALL_UPPERCASE": 6,
226
+ "MixedCase": 7,
227
+ "all_lowercase_quoted": 8,
228
+ "ALL_UPPERCASE_QUOTED": 9,
229
+ },
230
+ )
231
+ else:
232
+ if stmt_type.core_select or stmt_type.text_cols:
233
+ self._assert_row_mapping(
234
+ row,
235
+ {
236
+ "id": 1,
237
+ "all_lowercase": 5,
238
+ "ALL_UPPERCASE": 6,
239
+ "MixedCase": 7,
240
+ "all_lowercase_quoted": 8,
241
+ "ALL_UPPERCASE_QUOTED": 9,
242
+ },
243
+ include_cols=self.tables.denormalize_table.c,
244
+ )
245
+ else:
246
+ self._assert_row_mapping(
247
+ row,
248
+ {
249
+ "id": 1,
250
+ "all_lowercase": 5,
251
+ "all_uppercase": 6,
252
+ "MixedCase": 7,
253
+ "all_lowercase_quoted": 8,
254
+ "all_uppercase_quoted": 9,
255
+ },
256
+ include_cols=None,
257
+ )
258
+
259
+ else:
260
+ self._assert_row_mapping(
261
+ row,
262
+ {
263
+ "id": 1,
264
+ "all_lowercase": 5,
265
+ "ALL_UPPERCASE": 6,
266
+ "MixedCase": 7,
267
+ "all_lowercase_quoted": 8,
268
+ "ALL_UPPERCASE_QUOTED": 9,
269
+ },
270
+ include_cols=(
271
+ self.tables.denormalize_table.c
272
+ if stmt_type.core_select or stmt_type.text_cols
273
+ else None
274
+ ),
275
+ )
276
+
277
+
278
+ class PercentSchemaNamesTest(fixtures.TablesTest):
279
+ """tests using percent signs, spaces in table and column names.
280
+
281
+ This didn't work for PostgreSQL / MySQL drivers for a long time
282
+ but is now supported.
283
+
284
+ """
285
+
286
+ __requires__ = ("percent_schema_names",)
287
+
288
+ __backend__ = True
289
+
290
+ @classmethod
291
+ def define_tables(cls, metadata):
292
+ cls.tables.percent_table = Table(
293
+ "percent%table",
294
+ metadata,
295
+ Column("percent%", Integer),
296
+ Column("spaces % more spaces", Integer),
297
+ )
298
+ cls.tables.lightweight_percent_table = sql.table(
299
+ "percent%table",
300
+ sql.column("percent%"),
301
+ sql.column("spaces % more spaces"),
302
+ )
303
+
304
+ def test_single_roundtrip(self, connection):
305
+ percent_table = self.tables.percent_table
306
+ for params in [
307
+ {"percent%": 5, "spaces % more spaces": 12},
308
+ {"percent%": 7, "spaces % more spaces": 11},
309
+ {"percent%": 9, "spaces % more spaces": 10},
310
+ {"percent%": 11, "spaces % more spaces": 9},
311
+ ]:
312
+ connection.execute(percent_table.insert(), params)
313
+ self._assert_table(connection)
314
+
315
+ def test_executemany_roundtrip(self, connection):
316
+ percent_table = self.tables.percent_table
317
+ connection.execute(
318
+ percent_table.insert(), {"percent%": 5, "spaces % more spaces": 12}
319
+ )
320
+ connection.execute(
321
+ percent_table.insert(),
322
+ [
323
+ {"percent%": 7, "spaces % more spaces": 11},
324
+ {"percent%": 9, "spaces % more spaces": 10},
325
+ {"percent%": 11, "spaces % more spaces": 9},
326
+ ],
327
+ )
328
+ self._assert_table(connection)
329
+
330
+ @requirements.insert_executemany_returning
331
+ def test_executemany_returning_roundtrip(self, connection):
332
+ percent_table = self.tables.percent_table
333
+ connection.execute(
334
+ percent_table.insert(), {"percent%": 5, "spaces % more spaces": 12}
335
+ )
336
+ result = connection.execute(
337
+ percent_table.insert().returning(
338
+ percent_table.c["percent%"],
339
+ percent_table.c["spaces % more spaces"],
340
+ ),
341
+ [
342
+ {"percent%": 7, "spaces % more spaces": 11},
343
+ {"percent%": 9, "spaces % more spaces": 10},
344
+ {"percent%": 11, "spaces % more spaces": 9},
345
+ ],
346
+ )
347
+ eq_(result.all(), [(7, 11), (9, 10), (11, 9)])
348
+ self._assert_table(connection)
349
+
350
+ def _assert_table(self, conn):
351
+ percent_table = self.tables.percent_table
352
+ lightweight_percent_table = self.tables.lightweight_percent_table
353
+
354
+ for table in (
355
+ percent_table,
356
+ percent_table.alias(),
357
+ lightweight_percent_table,
358
+ lightweight_percent_table.alias(),
359
+ ):
360
+ eq_(
361
+ list(
362
+ conn.execute(table.select().order_by(table.c["percent%"]))
363
+ ),
364
+ [(5, 12), (7, 11), (9, 10), (11, 9)],
365
+ )
366
+
367
+ eq_(
368
+ list(
369
+ conn.execute(
370
+ table.select()
371
+ .where(table.c["spaces % more spaces"].in_([9, 10]))
372
+ .order_by(table.c["percent%"])
373
+ )
374
+ ),
375
+ [(9, 10), (11, 9)],
376
+ )
377
+
378
+ row = conn.execute(
379
+ table.select().order_by(table.c["percent%"])
380
+ ).first()
381
+ eq_(row._mapping["percent%"], 5)
382
+ eq_(row._mapping["spaces % more spaces"], 12)
383
+
384
+ eq_(row._mapping[table.c["percent%"]], 5)
385
+ eq_(row._mapping[table.c["spaces % more spaces"]], 12)
386
+
387
+ conn.execute(
388
+ percent_table.update().values(
389
+ {percent_table.c["spaces % more spaces"]: 15}
390
+ )
391
+ )
392
+
393
+ eq_(
394
+ list(
395
+ conn.execute(
396
+ percent_table.select().order_by(
397
+ percent_table.c["percent%"]
398
+ )
399
+ )
400
+ ),
401
+ [(5, 15), (7, 15), (9, 15), (11, 15)],
402
+ )
403
+
404
+
405
+ class ServerSideCursorsTest(
406
+ fixtures.TestBase, testing.AssertsExecutionResults
407
+ ):
408
+ __requires__ = ("server_side_cursors",)
409
+
410
+ __backend__ = True
411
+
412
+ def _is_server_side(self, cursor):
413
+ # TODO: this is a huge issue as it prevents these tests from being
414
+ # usable by third party dialects.
415
+ if self.engine.dialect.driver == "psycopg2":
416
+ return bool(cursor.name)
417
+ elif self.engine.dialect.driver == "pymysql":
418
+ sscursor = __import__("pymysql.cursors").cursors.SSCursor
419
+ return isinstance(cursor, sscursor)
420
+ elif self.engine.dialect.driver in ("aiomysql", "asyncmy", "aioodbc"):
421
+ return cursor.server_side
422
+ elif self.engine.dialect.driver == "mysqldb":
423
+ sscursor = __import__("MySQLdb.cursors").cursors.SSCursor
424
+ return isinstance(cursor, sscursor)
425
+ elif self.engine.dialect.driver == "mariadbconnector":
426
+ return not cursor.buffered
427
+ elif self.engine.dialect.driver == "mysqlconnector":
428
+ return "buffered" not in type(cursor).__name__.lower()
429
+ elif self.engine.dialect.driver in ("asyncpg", "aiosqlite"):
430
+ return cursor.server_side
431
+ elif self.engine.dialect.driver == "pg8000":
432
+ return getattr(cursor, "server_side", False)
433
+ elif self.engine.dialect.driver == "psycopg":
434
+ return bool(getattr(cursor, "name", False))
435
+ elif self.engine.dialect.driver == "oracledb":
436
+ return getattr(cursor, "server_side", False)
437
+ else:
438
+ return False
439
+
440
+ def _fixture(self, server_side_cursors):
441
+ if server_side_cursors:
442
+ with testing.expect_deprecated(
443
+ "The create_engine.server_side_cursors parameter is "
444
+ "deprecated and will be removed in a future release. "
445
+ "Please use the Connection.execution_options.stream_results "
446
+ "parameter."
447
+ ):
448
+ self.engine = engines.testing_engine(
449
+ options={"server_side_cursors": server_side_cursors}
450
+ )
451
+ else:
452
+ self.engine = engines.testing_engine(
453
+ options={"server_side_cursors": server_side_cursors}
454
+ )
455
+ return self.engine
456
+
457
+ def stringify(self, str_):
458
+ return re.compile(r"SELECT (\d+)", re.I).sub(
459
+ lambda m: str(select(int(m.group(1))).compile(testing.db)), str_
460
+ )
461
+
462
+ @testing.combinations(
463
+ ("global_string", True, lambda stringify: stringify("select 1"), True),
464
+ (
465
+ "global_text",
466
+ True,
467
+ lambda stringify: text(stringify("select 1")),
468
+ True,
469
+ ),
470
+ ("global_expr", True, select(1), True),
471
+ (
472
+ "global_off_explicit",
473
+ False,
474
+ lambda stringify: text(stringify("select 1")),
475
+ False,
476
+ ),
477
+ (
478
+ "stmt_option",
479
+ False,
480
+ select(1).execution_options(stream_results=True),
481
+ True,
482
+ ),
483
+ (
484
+ "stmt_option_disabled",
485
+ True,
486
+ select(1).execution_options(stream_results=False),
487
+ False,
488
+ ),
489
+ ("for_update_expr", True, select(1).with_for_update(), True),
490
+ # TODO: need a real requirement for this, or dont use this test
491
+ (
492
+ "for_update_string",
493
+ True,
494
+ lambda stringify: stringify("SELECT 1 FOR UPDATE"),
495
+ True,
496
+ testing.skip_if(["sqlite", "mssql"]),
497
+ ),
498
+ (
499
+ "text_no_ss",
500
+ False,
501
+ lambda stringify: text(stringify("select 42")),
502
+ False,
503
+ ),
504
+ (
505
+ "text_ss_option",
506
+ False,
507
+ lambda stringify: text(stringify("select 42")).execution_options(
508
+ stream_results=True
509
+ ),
510
+ True,
511
+ ),
512
+ id_="iaaa",
513
+ argnames="engine_ss_arg, statement, cursor_ss_status",
514
+ )
515
+ def test_ss_cursor_status(
516
+ self, engine_ss_arg, statement, cursor_ss_status
517
+ ):
518
+ engine = self._fixture(engine_ss_arg)
519
+ with engine.begin() as conn:
520
+ if callable(statement):
521
+ statement = testing.resolve_lambda(
522
+ statement, stringify=self.stringify
523
+ )
524
+
525
+ if isinstance(statement, str):
526
+ result = conn.exec_driver_sql(statement)
527
+ else:
528
+ result = conn.execute(statement)
529
+ eq_(self._is_server_side(result.cursor), cursor_ss_status)
530
+ result.close()
531
+
532
+ def test_conn_option(self):
533
+ engine = self._fixture(False)
534
+
535
+ with engine.connect() as conn:
536
+ # should be enabled for this one
537
+ result = conn.execution_options(
538
+ stream_results=True
539
+ ).exec_driver_sql(self.stringify("select 1"))
540
+ assert self._is_server_side(result.cursor)
541
+
542
+ # the connection has autobegun, which means at the end of the
543
+ # block, we will roll back, which on MySQL at least will fail
544
+ # with "Commands out of sync" if the result set
545
+ # is not closed, so we close it first.
546
+ #
547
+ # fun fact! why did we not have this result.close() in this test
548
+ # before 2.0? don't we roll back in the connection pool
549
+ # unconditionally? yes! and in fact if you run this test in 1.4
550
+ # with stdout shown, there is in fact "Exception during reset or
551
+ # similar" with "Commands out sync" emitted a warning! 2.0's
552
+ # architecture finds and fixes what was previously an expensive
553
+ # silent error condition.
554
+ result.close()
555
+
556
+ def test_stmt_enabled_conn_option_disabled(self):
557
+ engine = self._fixture(False)
558
+
559
+ s = select(1).execution_options(stream_results=True)
560
+
561
+ with engine.connect() as conn:
562
+ # not this one
563
+ result = conn.execution_options(stream_results=False).execute(s)
564
+ assert not self._is_server_side(result.cursor)
565
+
566
+ def test_aliases_and_ss(self):
567
+ engine = self._fixture(False)
568
+ s1 = (
569
+ select(sql.literal_column("1").label("x"))
570
+ .execution_options(stream_results=True)
571
+ .subquery()
572
+ )
573
+
574
+ # options don't propagate out when subquery is used as a FROM clause
575
+ with engine.begin() as conn:
576
+ result = conn.execute(s1.select())
577
+ assert not self._is_server_side(result.cursor)
578
+ result.close()
579
+
580
+ s2 = select(1).select_from(s1)
581
+ with engine.begin() as conn:
582
+ result = conn.execute(s2)
583
+ assert not self._is_server_side(result.cursor)
584
+ result.close()
585
+
586
+ def test_roundtrip_fetchall(self, metadata):
587
+ md = self.metadata
588
+
589
+ engine = self._fixture(True)
590
+ test_table = Table(
591
+ "test_table",
592
+ md,
593
+ Column(
594
+ "id", Integer, primary_key=True, test_needs_autoincrement=True
595
+ ),
596
+ Column("data", String(50)),
597
+ )
598
+
599
+ with engine.begin() as connection:
600
+ test_table.create(connection, checkfirst=True)
601
+ connection.execute(test_table.insert(), dict(data="data1"))
602
+ connection.execute(test_table.insert(), dict(data="data2"))
603
+ eq_(
604
+ connection.execute(
605
+ test_table.select().order_by(test_table.c.id)
606
+ ).fetchall(),
607
+ [(1, "data1"), (2, "data2")],
608
+ )
609
+ connection.execute(
610
+ test_table.update()
611
+ .where(test_table.c.id == 2)
612
+ .values(data=test_table.c.data + " updated")
613
+ )
614
+ eq_(
615
+ connection.execute(
616
+ test_table.select().order_by(test_table.c.id)
617
+ ).fetchall(),
618
+ [(1, "data1"), (2, "data2 updated")],
619
+ )
620
+ connection.execute(test_table.delete())
621
+ eq_(
622
+ connection.scalar(
623
+ select(func.count("*")).select_from(test_table)
624
+ ),
625
+ 0,
626
+ )
627
+
628
+ def test_roundtrip_fetchmany(self, metadata):
629
+ md = self.metadata
630
+
631
+ engine = self._fixture(True)
632
+ test_table = Table(
633
+ "test_table",
634
+ md,
635
+ Column(
636
+ "id", Integer, primary_key=True, test_needs_autoincrement=True
637
+ ),
638
+ Column("data", String(50)),
639
+ )
640
+
641
+ with engine.begin() as connection:
642
+ test_table.create(connection, checkfirst=True)
643
+ connection.execute(
644
+ test_table.insert(),
645
+ [dict(data="data%d" % i) for i in range(1, 20)],
646
+ )
647
+
648
+ result = connection.execute(
649
+ test_table.select().order_by(test_table.c.id)
650
+ )
651
+
652
+ eq_(
653
+ result.fetchmany(5),
654
+ [(i, "data%d" % i) for i in range(1, 6)],
655
+ )
656
+ eq_(
657
+ result.fetchmany(10),
658
+ [(i, "data%d" % i) for i in range(6, 16)],
659
+ )
660
+ eq_(result.fetchall(), [(i, "data%d" % i) for i in range(16, 20)])