Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 0af46b5

Browse files
committed
Second test case for #102 that works with MySQL but not SQLite
1 parent 66cc9aa commit 0af46b5

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

tests/test_databases.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,18 @@ async def test_database_url_interface(database_url):
703703

704704
@pytest.mark.parametrize("database_url", DATABASE_URLS)
705705
@async_adapter
706-
async def test_iterate_outside_transaction(database_url):
706+
async def test_iterate_outside_transaction_with_values(database_url):
707707
"""
708708
Ensure `iterate()` works even without a transaction on all drivers.
709-
710709
The asyncpg driver relies on server-side cursors without hold
711710
for iteration, which requires a transaction to be created.
712711
This is mentionned in both their documentation and their test suite.
713712
"""
713+
714+
database_url = DatabaseURL(database_url)
715+
if database_url.dialect == "mysql":
716+
pytest.skip("MySQL does not support `FROM (VALUES ...)` (F641)")
717+
714718
async with Database(database_url) as database:
715719
query = "SELECT * FROM (VALUES (1), (2), (3), (4), (5)) as t"
716720
iterate_results = []
@@ -720,3 +724,32 @@ async def test_iterate_outside_transaction(database_url):
720724

721725
assert len(iterate_results) == 5
722726
assert iterate_results == [(1,), (2,), (3,), (4,), (5,)]
727+
728+
729+
@pytest.mark.parametrize("database_url", DATABASE_URLS)
730+
@async_adapter
731+
async def test_iterate_outside_transaction_with_temp_table(database_url):
732+
"""
733+
Same as test_iterate_outside_transaction_with_values but uses a
734+
temporary table instead of a list of values.
735+
"""
736+
737+
database_url = DatabaseURL(database_url)
738+
if database_url.dialect == "sqlite":
739+
pytest.skip("SQLite interface does not work with temporary tables.")
740+
741+
async with Database(database_url) as database:
742+
query = "CREATE TEMPORARY TABLE no_transac(num INTEGER)"
743+
await database.execute(query)
744+
745+
query = "INSERT INTO no_transac(num) VALUES (1), (2), (3), (4), (5)"
746+
await database.execute(query)
747+
748+
query = "SELECT * FROM no_transac"
749+
iterate_results = []
750+
751+
async for result in database.iterate(query=query):
752+
iterate_results.append(result)
753+
754+
assert len(iterate_results) == 5
755+
assert iterate_results == [(1,), (2,), (3,), (4,), (5,)]

0 commit comments

Comments
 (0)