test_dialect.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. # testing/suite/test_dialect.py
  2. # Copyright (C) 2005-2025 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. import importlib
  9. from . import testing
  10. from .. import assert_raises
  11. from .. import config
  12. from .. import engines
  13. from .. import eq_
  14. from .. import fixtures
  15. from .. import is_not_none
  16. from .. import is_true
  17. from .. import mock
  18. from .. import ne_
  19. from .. import provide_metadata
  20. from ..assertions import expect_raises
  21. from ..assertions import expect_raises_message
  22. from ..config import requirements
  23. from ..provision import set_default_schema_on_connection
  24. from ..schema import Column
  25. from ..schema import Table
  26. from ... import bindparam
  27. from ... import dialects
  28. from ... import event
  29. from ... import exc
  30. from ... import Integer
  31. from ... import literal_column
  32. from ... import select
  33. from ... import String
  34. from ...sql.compiler import Compiled
  35. from ...util import inspect_getfullargspec
  36. class PingTest(fixtures.TestBase):
  37. __backend__ = True
  38. def test_do_ping(self):
  39. with testing.db.connect() as conn:
  40. is_true(
  41. testing.db.dialect.do_ping(conn.connection.dbapi_connection)
  42. )
  43. class ArgSignatureTest(fixtures.TestBase):
  44. """test that all visit_XYZ() in :class:`_sql.Compiler` subclasses have
  45. ``**kw``, for #8988.
  46. This test uses runtime code inspection. Does not need to be a
  47. ``__backend__`` test as it only needs to run once provided all target
  48. dialects have been imported.
  49. For third party dialects, the suite would be run with that third
  50. party as a "--dburi", which means its compiler classes will have been
  51. imported by the time this test runs.
  52. """
  53. def _all_subclasses(): # type: ignore # noqa
  54. for d in dialects.__all__:
  55. if not d.startswith("_"):
  56. importlib.import_module("sqlalchemy.dialects.%s" % d)
  57. stack = [Compiled]
  58. while stack:
  59. cls = stack.pop(0)
  60. stack.extend(cls.__subclasses__())
  61. yield cls
  62. @testing.fixture(params=list(_all_subclasses()))
  63. def all_subclasses(self, request):
  64. yield request.param
  65. def test_all_visit_methods_accept_kw(self, all_subclasses):
  66. cls = all_subclasses
  67. for k in cls.__dict__:
  68. if k.startswith("visit_"):
  69. meth = getattr(cls, k)
  70. insp = inspect_getfullargspec(meth)
  71. is_not_none(
  72. insp.varkw,
  73. f"Compiler visit method {cls.__name__}.{k}() does "
  74. "not accommodate for **kw in its argument signature",
  75. )
  76. class ExceptionTest(fixtures.TablesTest):
  77. """Test basic exception wrapping.
  78. DBAPIs vary a lot in exception behavior so to actually anticipate
  79. specific exceptions from real round trips, we need to be conservative.
  80. """
  81. run_deletes = "each"
  82. __backend__ = True
  83. @classmethod
  84. def define_tables(cls, metadata):
  85. Table(
  86. "manual_pk",
  87. metadata,
  88. Column("id", Integer, primary_key=True, autoincrement=False),
  89. Column("data", String(50)),
  90. )
  91. @requirements.duplicate_key_raises_integrity_error
  92. def test_integrity_error(self):
  93. with config.db.connect() as conn:
  94. trans = conn.begin()
  95. conn.execute(
  96. self.tables.manual_pk.insert(), {"id": 1, "data": "d1"}
  97. )
  98. assert_raises(
  99. exc.IntegrityError,
  100. conn.execute,
  101. self.tables.manual_pk.insert(),
  102. {"id": 1, "data": "d1"},
  103. )
  104. trans.rollback()
  105. def test_exception_with_non_ascii(self):
  106. with config.db.connect() as conn:
  107. try:
  108. # try to create an error message that likely has non-ascii
  109. # characters in the DBAPI's message string. unfortunately
  110. # there's no way to make this happen with some drivers like
  111. # mysqlclient, pymysql. this at least does produce a non-
  112. # ascii error message for cx_oracle, psycopg2
  113. conn.execute(select(literal_column("méil")))
  114. assert False
  115. except exc.DBAPIError as err:
  116. err_str = str(err)
  117. assert str(err.orig) in str(err)
  118. assert isinstance(err_str, str)
  119. class IsolationLevelTest(fixtures.TestBase):
  120. __backend__ = True
  121. __requires__ = ("isolation_level",)
  122. def _get_non_default_isolation_level(self):
  123. levels = requirements.get_isolation_levels(config)
  124. default = levels["default"]
  125. supported = levels["supported"]
  126. s = set(supported).difference(["AUTOCOMMIT", default])
  127. if s:
  128. return s.pop()
  129. else:
  130. config.skip_test("no non-default isolation level available")
  131. def test_default_isolation_level(self):
  132. eq_(
  133. config.db.dialect.default_isolation_level,
  134. requirements.get_isolation_levels(config)["default"],
  135. )
  136. def test_non_default_isolation_level(self):
  137. non_default = self._get_non_default_isolation_level()
  138. with config.db.connect() as conn:
  139. existing = conn.get_isolation_level()
  140. ne_(existing, non_default)
  141. conn.execution_options(isolation_level=non_default)
  142. eq_(conn.get_isolation_level(), non_default)
  143. conn.dialect.reset_isolation_level(
  144. conn.connection.dbapi_connection
  145. )
  146. eq_(conn.get_isolation_level(), existing)
  147. def test_all_levels(self):
  148. levels = requirements.get_isolation_levels(config)
  149. all_levels = levels["supported"]
  150. for level in set(all_levels).difference(["AUTOCOMMIT"]):
  151. with config.db.connect() as conn:
  152. conn.execution_options(isolation_level=level)
  153. eq_(conn.get_isolation_level(), level)
  154. trans = conn.begin()
  155. trans.rollback()
  156. eq_(conn.get_isolation_level(), level)
  157. with config.db.connect() as conn:
  158. eq_(
  159. conn.get_isolation_level(),
  160. levels["default"],
  161. )
  162. @testing.requires.get_isolation_level_values
  163. def test_invalid_level_execution_option(self, connection_no_trans):
  164. """test for the new get_isolation_level_values() method"""
  165. connection = connection_no_trans
  166. with expect_raises_message(
  167. exc.ArgumentError,
  168. "Invalid value '%s' for isolation_level. "
  169. "Valid isolation levels for '%s' are %s"
  170. % (
  171. "FOO",
  172. connection.dialect.name,
  173. ", ".join(
  174. requirements.get_isolation_levels(config)["supported"]
  175. ),
  176. ),
  177. ):
  178. connection.execution_options(isolation_level="FOO")
  179. @testing.requires.get_isolation_level_values
  180. @testing.requires.dialect_level_isolation_level_param
  181. def test_invalid_level_engine_param(self, testing_engine):
  182. """test for the new get_isolation_level_values() method
  183. and support for the dialect-level 'isolation_level' parameter.
  184. """
  185. eng = testing_engine(options=dict(isolation_level="FOO"))
  186. with expect_raises_message(
  187. exc.ArgumentError,
  188. "Invalid value '%s' for isolation_level. "
  189. "Valid isolation levels for '%s' are %s"
  190. % (
  191. "FOO",
  192. eng.dialect.name,
  193. ", ".join(
  194. requirements.get_isolation_levels(config)["supported"]
  195. ),
  196. ),
  197. ):
  198. eng.connect()
  199. @testing.requires.independent_readonly_connections
  200. def test_dialect_user_setting_is_restored(self, testing_engine):
  201. levels = requirements.get_isolation_levels(config)
  202. default = levels["default"]
  203. supported = (
  204. sorted(
  205. set(levels["supported"]).difference([default, "AUTOCOMMIT"])
  206. )
  207. )[0]
  208. e = testing_engine(options={"isolation_level": supported})
  209. with e.connect() as conn:
  210. eq_(conn.get_isolation_level(), supported)
  211. with e.connect() as conn:
  212. conn.execution_options(isolation_level=default)
  213. eq_(conn.get_isolation_level(), default)
  214. with e.connect() as conn:
  215. eq_(conn.get_isolation_level(), supported)
  216. class AutocommitIsolationTest(fixtures.TablesTest):
  217. run_deletes = "each"
  218. __requires__ = ("autocommit",)
  219. __backend__ = True
  220. @classmethod
  221. def define_tables(cls, metadata):
  222. Table(
  223. "some_table",
  224. metadata,
  225. Column("id", Integer, primary_key=True, autoincrement=False),
  226. Column("data", String(50)),
  227. test_needs_acid=True,
  228. )
  229. def _test_conn_autocommits(self, conn, autocommit, ensure_table=False):
  230. if ensure_table:
  231. self.tables.some_table.create(conn, checkfirst=True)
  232. conn.commit()
  233. trans = conn.begin()
  234. conn.execute(
  235. self.tables.some_table.insert(), {"id": 1, "data": "some data"}
  236. )
  237. trans.rollback()
  238. eq_(
  239. conn.scalar(select(self.tables.some_table.c.id)),
  240. 1 if autocommit else None,
  241. )
  242. conn.rollback()
  243. with conn.begin():
  244. conn.execute(self.tables.some_table.delete())
  245. def test_autocommit_on(self, connection_no_trans):
  246. conn = connection_no_trans
  247. c2 = conn.execution_options(isolation_level="AUTOCOMMIT")
  248. self._test_conn_autocommits(c2, True)
  249. c2.dialect.reset_isolation_level(c2.connection.dbapi_connection)
  250. self._test_conn_autocommits(conn, False)
  251. def test_autocommit_off(self, connection_no_trans):
  252. conn = connection_no_trans
  253. self._test_conn_autocommits(conn, False)
  254. def test_turn_autocommit_off_via_default_iso_level(
  255. self, connection_no_trans
  256. ):
  257. conn = connection_no_trans
  258. conn = conn.execution_options(isolation_level="AUTOCOMMIT")
  259. self._test_conn_autocommits(conn, True)
  260. conn.execution_options(
  261. isolation_level=requirements.get_isolation_levels(config)[
  262. "default"
  263. ]
  264. )
  265. self._test_conn_autocommits(conn, False)
  266. @testing.requires.skip_autocommit_rollback
  267. @testing.variation("autocommit_setting", ["false", "engine", "option"])
  268. @testing.variation("block_rollback", [True, False])
  269. def test_autocommit_block(
  270. self, testing_engine, autocommit_setting, block_rollback
  271. ):
  272. kw = {}
  273. if bool(block_rollback):
  274. kw["skip_autocommit_rollback"] = True
  275. if autocommit_setting.engine:
  276. kw["isolation_level"] = "AUTOCOMMIT"
  277. engine = testing_engine(options=kw)
  278. conn = engine.connect()
  279. if autocommit_setting.option:
  280. conn.execution_options(isolation_level="AUTOCOMMIT")
  281. self._test_conn_autocommits(
  282. conn,
  283. autocommit_setting.engine or autocommit_setting.option,
  284. ensure_table=True,
  285. )
  286. with mock.patch.object(
  287. conn.connection, "rollback", wraps=conn.connection.rollback
  288. ) as check_rollback:
  289. conn.close()
  290. if autocommit_setting.false or not block_rollback:
  291. eq_(check_rollback.mock_calls, [mock.call()])
  292. else:
  293. eq_(check_rollback.mock_calls, [])
  294. @testing.requires.independent_readonly_connections
  295. @testing.variation("use_dialect_setting", [True, False])
  296. def test_dialect_autocommit_is_restored(
  297. self, testing_engine, use_dialect_setting
  298. ):
  299. """test #10147"""
  300. if use_dialect_setting:
  301. e = testing_engine(options={"isolation_level": "AUTOCOMMIT"})
  302. else:
  303. e = testing_engine().execution_options(
  304. isolation_level="AUTOCOMMIT"
  305. )
  306. levels = requirements.get_isolation_levels(config)
  307. default = levels["default"]
  308. with e.connect() as conn:
  309. self._test_conn_autocommits(conn, True)
  310. with e.connect() as conn:
  311. conn.execution_options(isolation_level=default)
  312. self._test_conn_autocommits(conn, False)
  313. with e.connect() as conn:
  314. self._test_conn_autocommits(conn, True)
  315. class EscapingTest(fixtures.TestBase):
  316. @provide_metadata
  317. def test_percent_sign_round_trip(self):
  318. """test that the DBAPI accommodates for escaped / nonescaped
  319. percent signs in a way that matches the compiler
  320. """
  321. m = self.metadata
  322. t = Table("t", m, Column("data", String(50)))
  323. t.create(config.db)
  324. with config.db.begin() as conn:
  325. conn.execute(t.insert(), dict(data="some % value"))
  326. conn.execute(t.insert(), dict(data="some %% other value"))
  327. eq_(
  328. conn.scalar(
  329. select(t.c.data).where(
  330. t.c.data == literal_column("'some % value'")
  331. )
  332. ),
  333. "some % value",
  334. )
  335. eq_(
  336. conn.scalar(
  337. select(t.c.data).where(
  338. t.c.data == literal_column("'some %% other value'")
  339. )
  340. ),
  341. "some %% other value",
  342. )
  343. class WeCanSetDefaultSchemaWEventsTest(fixtures.TestBase):
  344. __backend__ = True
  345. __requires__ = ("default_schema_name_switch",)
  346. def test_control_case(self):
  347. default_schema_name = config.db.dialect.default_schema_name
  348. eng = engines.testing_engine()
  349. with eng.connect():
  350. pass
  351. eq_(eng.dialect.default_schema_name, default_schema_name)
  352. def test_wont_work_wo_insert(self):
  353. default_schema_name = config.db.dialect.default_schema_name
  354. eng = engines.testing_engine()
  355. @event.listens_for(eng, "connect")
  356. def on_connect(dbapi_connection, connection_record):
  357. set_default_schema_on_connection(
  358. config, dbapi_connection, config.test_schema
  359. )
  360. with eng.connect() as conn:
  361. what_it_should_be = eng.dialect._get_default_schema_name(conn)
  362. eq_(what_it_should_be, config.test_schema)
  363. eq_(eng.dialect.default_schema_name, default_schema_name)
  364. def test_schema_change_on_connect(self):
  365. eng = engines.testing_engine()
  366. @event.listens_for(eng, "connect", insert=True)
  367. def on_connect(dbapi_connection, connection_record):
  368. set_default_schema_on_connection(
  369. config, dbapi_connection, config.test_schema
  370. )
  371. with eng.connect() as conn:
  372. what_it_should_be = eng.dialect._get_default_schema_name(conn)
  373. eq_(what_it_should_be, config.test_schema)
  374. eq_(eng.dialect.default_schema_name, config.test_schema)
  375. def test_schema_change_works_w_transactions(self):
  376. eng = engines.testing_engine()
  377. @event.listens_for(eng, "connect", insert=True)
  378. def on_connect(dbapi_connection, *arg):
  379. set_default_schema_on_connection(
  380. config, dbapi_connection, config.test_schema
  381. )
  382. with eng.connect() as conn:
  383. trans = conn.begin()
  384. what_it_should_be = eng.dialect._get_default_schema_name(conn)
  385. eq_(what_it_should_be, config.test_schema)
  386. trans.rollback()
  387. what_it_should_be = eng.dialect._get_default_schema_name(conn)
  388. eq_(what_it_should_be, config.test_schema)
  389. eq_(eng.dialect.default_schema_name, config.test_schema)
  390. class FutureWeCanSetDefaultSchemaWEventsTest(
  391. fixtures.FutureEngineMixin, WeCanSetDefaultSchemaWEventsTest
  392. ):
  393. pass
  394. class DifficultParametersTest(fixtures.TestBase):
  395. __backend__ = True
  396. tough_parameters = testing.combinations(
  397. ("boring",),
  398. ("per cent",),
  399. ("per % cent",),
  400. ("%percent",),
  401. ("par(ens)",),
  402. ("percent%(ens)yah",),
  403. ("col:ons",),
  404. ("_starts_with_underscore",),
  405. ("dot.s",),
  406. ("more :: %colons%",),
  407. ("_name",),
  408. ("___name",),
  409. ("[BracketsAndCase]",),
  410. ("42numbers",),
  411. ("percent%signs",),
  412. ("has spaces",),
  413. ("/slashes/",),
  414. ("more/slashes",),
  415. ("q?marks",),
  416. ("1param",),
  417. ("1col:on",),
  418. argnames="paramname",
  419. )
  420. @tough_parameters
  421. @config.requirements.unusual_column_name_characters
  422. def test_round_trip_same_named_column(
  423. self, paramname, connection, metadata
  424. ):
  425. name = paramname
  426. t = Table(
  427. "t",
  428. metadata,
  429. Column("id", Integer, primary_key=True),
  430. Column(name, String(50), nullable=False),
  431. )
  432. # table is created
  433. t.create(connection)
  434. # automatic param generated by insert
  435. connection.execute(t.insert().values({"id": 1, name: "some name"}))
  436. # automatic param generated by criteria, plus selecting the column
  437. stmt = select(t.c[name]).where(t.c[name] == "some name")
  438. eq_(connection.scalar(stmt), "some name")
  439. # use the name in a param explicitly
  440. stmt = select(t.c[name]).where(t.c[name] == bindparam(name))
  441. row = connection.execute(stmt, {name: "some name"}).first()
  442. # name works as the key from cursor.description
  443. eq_(row._mapping[name], "some name")
  444. # use expanding IN
  445. stmt = select(t.c[name]).where(
  446. t.c[name].in_(["some name", "some other_name"])
  447. )
  448. connection.execute(stmt).first()
  449. @testing.fixture
  450. def multirow_fixture(self, metadata, connection):
  451. mytable = Table(
  452. "mytable",
  453. metadata,
  454. Column("myid", Integer),
  455. Column("name", String(50)),
  456. Column("desc", String(50)),
  457. )
  458. mytable.create(connection)
  459. connection.execute(
  460. mytable.insert(),
  461. [
  462. {"myid": 1, "name": "a", "desc": "a_desc"},
  463. {"myid": 2, "name": "b", "desc": "b_desc"},
  464. {"myid": 3, "name": "c", "desc": "c_desc"},
  465. {"myid": 4, "name": "d", "desc": "d_desc"},
  466. ],
  467. )
  468. yield mytable
  469. @tough_parameters
  470. def test_standalone_bindparam_escape(
  471. self, paramname, connection, multirow_fixture
  472. ):
  473. tbl1 = multirow_fixture
  474. stmt = select(tbl1.c.myid).where(
  475. tbl1.c.name == bindparam(paramname, value="x")
  476. )
  477. res = connection.scalar(stmt, {paramname: "c"})
  478. eq_(res, 3)
  479. @tough_parameters
  480. def test_standalone_bindparam_escape_expanding(
  481. self, paramname, connection, multirow_fixture
  482. ):
  483. tbl1 = multirow_fixture
  484. stmt = (
  485. select(tbl1.c.myid)
  486. .where(tbl1.c.name.in_(bindparam(paramname, value=["a", "b"])))
  487. .order_by(tbl1.c.myid)
  488. )
  489. res = connection.scalars(stmt, {paramname: ["d", "a"]}).all()
  490. eq_(res, [1, 4])
  491. class ReturningGuardsTest(fixtures.TablesTest):
  492. """test that the various 'returning' flags are set appropriately"""
  493. __backend__ = True
  494. @classmethod
  495. def define_tables(cls, metadata):
  496. Table(
  497. "t",
  498. metadata,
  499. Column("id", Integer, primary_key=True, autoincrement=False),
  500. Column("data", String(50)),
  501. )
  502. @testing.fixture
  503. def run_stmt(self, connection):
  504. t = self.tables.t
  505. def go(stmt, executemany, id_param_name, expect_success):
  506. stmt = stmt.returning(t.c.id)
  507. if executemany:
  508. if not expect_success:
  509. # for RETURNING executemany(), we raise our own
  510. # error as this is independent of general RETURNING
  511. # support
  512. with expect_raises_message(
  513. exc.StatementError,
  514. rf"Dialect {connection.dialect.name}\+"
  515. f"{connection.dialect.driver} with "
  516. f"current server capabilities does not support "
  517. f".*RETURNING when executemany is used",
  518. ):
  519. connection.execute(
  520. stmt,
  521. [
  522. {id_param_name: 1, "data": "d1"},
  523. {id_param_name: 2, "data": "d2"},
  524. {id_param_name: 3, "data": "d3"},
  525. ],
  526. )
  527. else:
  528. result = connection.execute(
  529. stmt,
  530. [
  531. {id_param_name: 1, "data": "d1"},
  532. {id_param_name: 2, "data": "d2"},
  533. {id_param_name: 3, "data": "d3"},
  534. ],
  535. )
  536. eq_(result.all(), [(1,), (2,), (3,)])
  537. else:
  538. if not expect_success:
  539. # for RETURNING execute(), we pass all the way to the DB
  540. # and let it fail
  541. with expect_raises(exc.DBAPIError):
  542. connection.execute(
  543. stmt, {id_param_name: 1, "data": "d1"}
  544. )
  545. else:
  546. result = connection.execute(
  547. stmt, {id_param_name: 1, "data": "d1"}
  548. )
  549. eq_(result.all(), [(1,)])
  550. return go
  551. def test_insert_single(self, connection, run_stmt):
  552. t = self.tables.t
  553. stmt = t.insert()
  554. run_stmt(stmt, False, "id", connection.dialect.insert_returning)
  555. def test_insert_many(self, connection, run_stmt):
  556. t = self.tables.t
  557. stmt = t.insert()
  558. run_stmt(
  559. stmt, True, "id", connection.dialect.insert_executemany_returning
  560. )
  561. def test_update_single(self, connection, run_stmt):
  562. t = self.tables.t
  563. connection.execute(
  564. t.insert(),
  565. [
  566. {"id": 1, "data": "d1"},
  567. {"id": 2, "data": "d2"},
  568. {"id": 3, "data": "d3"},
  569. ],
  570. )
  571. stmt = t.update().where(t.c.id == bindparam("b_id"))
  572. run_stmt(stmt, False, "b_id", connection.dialect.update_returning)
  573. def test_update_many(self, connection, run_stmt):
  574. t = self.tables.t
  575. connection.execute(
  576. t.insert(),
  577. [
  578. {"id": 1, "data": "d1"},
  579. {"id": 2, "data": "d2"},
  580. {"id": 3, "data": "d3"},
  581. ],
  582. )
  583. stmt = t.update().where(t.c.id == bindparam("b_id"))
  584. run_stmt(
  585. stmt, True, "b_id", connection.dialect.update_executemany_returning
  586. )
  587. def test_delete_single(self, connection, run_stmt):
  588. t = self.tables.t
  589. connection.execute(
  590. t.insert(),
  591. [
  592. {"id": 1, "data": "d1"},
  593. {"id": 2, "data": "d2"},
  594. {"id": 3, "data": "d3"},
  595. ],
  596. )
  597. stmt = t.delete().where(t.c.id == bindparam("b_id"))
  598. run_stmt(stmt, False, "b_id", connection.dialect.delete_returning)
  599. def test_delete_many(self, connection, run_stmt):
  600. t = self.tables.t
  601. connection.execute(
  602. t.insert(),
  603. [
  604. {"id": 1, "data": "d1"},
  605. {"id": 2, "data": "d2"},
  606. {"id": 3, "data": "d3"},
  607. ],
  608. )
  609. stmt = t.delete().where(t.c.id == bindparam("b_id"))
  610. run_stmt(
  611. stmt, True, "b_id", connection.dialect.delete_executemany_returning
  612. )