@@ -10561,6 +10561,99 @@ def test_decimal_separator_calculations(cursor, db_connection):
1056110561 # Cleanup
1056210562 cursor .execute ("DROP TABLE IF EXISTS #pytest_decimal_calc_test" )
1056310563
10564+ def test_nvarcharmax_executemany_streaming (cursor , db_connection ):
10565+ """Streaming insert + fetch > 4k NVARCHAR(MAX) using executemany with all fetch modes."""
10566+ try :
10567+ values = ["Ω" * 4100 , "漢" * 5000 ]
10568+ cursor .execute ("CREATE TABLE #pytest_nvarcharmax (col NVARCHAR(MAX))" )
10569+ db_connection .commit ()
10570+
10571+ # --- executemany insert ---
10572+ cursor .executemany ("INSERT INTO #pytest_nvarcharmax VALUES (?)" , [(v ,) for v in values ])
10573+ db_connection .commit ()
10574+
10575+ # --- fetchall ---
10576+ cursor .execute ("SELECT col FROM #pytest_nvarcharmax ORDER BY LEN(col)" )
10577+ rows = [r [0 ] for r in cursor .fetchall ()]
10578+ assert rows == sorted (values , key = len )
10579+
10580+ # --- fetchone ---
10581+ cursor .execute ("SELECT col FROM #pytest_nvarcharmax ORDER BY LEN(col)" )
10582+ r1 = cursor .fetchone ()[0 ]
10583+ r2 = cursor .fetchone ()[0 ]
10584+ assert {r1 , r2 } == set (values )
10585+ assert cursor .fetchone () is None
10586+
10587+ # --- fetchmany ---
10588+ cursor .execute ("SELECT col FROM #pytest_nvarcharmax ORDER BY LEN(col)" )
10589+ batch = [r [0 ] for r in cursor .fetchmany (1 )]
10590+ assert batch [0 ] in values
10591+ finally :
10592+ cursor .execute ("DROP TABLE #pytest_nvarcharmax" )
10593+ db_connection .commit ()
10594+
10595+ def test_varcharmax_executemany_streaming (cursor , db_connection ):
10596+ """Streaming insert + fetch > 4k VARCHAR(MAX) using executemany with all fetch modes."""
10597+ try :
10598+ values = ["A" * 4100 , "B" * 5000 ]
10599+ cursor .execute ("CREATE TABLE #pytest_varcharmax (col VARCHAR(MAX))" )
10600+ db_connection .commit ()
10601+
10602+ # --- executemany insert ---
10603+ cursor .executemany ("INSERT INTO #pytest_varcharmax VALUES (?)" , [(v ,) for v in values ])
10604+ db_connection .commit ()
10605+
10606+ # --- fetchall ---
10607+ cursor .execute ("SELECT col FROM #pytest_varcharmax ORDER BY LEN(col)" )
10608+ rows = [r [0 ] for r in cursor .fetchall ()]
10609+ assert rows == sorted (values , key = len )
10610+
10611+ # --- fetchone ---
10612+ cursor .execute ("SELECT col FROM #pytest_varcharmax ORDER BY LEN(col)" )
10613+ r1 = cursor .fetchone ()[0 ]
10614+ r2 = cursor .fetchone ()[0 ]
10615+ assert {r1 , r2 } == set (values )
10616+ assert cursor .fetchone () is None
10617+
10618+ # --- fetchmany ---
10619+ cursor .execute ("SELECT col FROM #pytest_varcharmax ORDER BY LEN(col)" )
10620+ batch = [r [0 ] for r in cursor .fetchmany (1 )]
10621+ assert batch [0 ] in values
10622+ finally :
10623+ cursor .execute ("DROP TABLE #pytest_varcharmax" )
10624+ db_connection .commit ()
10625+
10626+ def test_varbinarymax_executemany_streaming (cursor , db_connection ):
10627+ """Streaming insert + fetch > 4k VARBINARY(MAX) using executemany with all fetch modes."""
10628+ try :
10629+ values = [b"\x01 " * 4100 , b"\x02 " * 5000 ]
10630+ cursor .execute ("CREATE TABLE #pytest_varbinarymax (col VARBINARY(MAX))" )
10631+ db_connection .commit ()
10632+
10633+ # --- executemany insert ---
10634+ cursor .executemany ("INSERT INTO #pytest_varbinarymax VALUES (?)" , [(v ,) for v in values ])
10635+ db_connection .commit ()
10636+
10637+ # --- fetchall ---
10638+ cursor .execute ("SELECT col FROM #pytest_varbinarymax ORDER BY DATALENGTH(col)" )
10639+ rows = [r [0 ] for r in cursor .fetchall ()]
10640+ assert rows == sorted (values , key = len )
10641+
10642+ # --- fetchone ---
10643+ cursor .execute ("SELECT col FROM #pytest_varbinarymax ORDER BY DATALENGTH(col)" )
10644+ r1 = cursor .fetchone ()[0 ]
10645+ r2 = cursor .fetchone ()[0 ]
10646+ assert {r1 , r2 } == set (values )
10647+ assert cursor .fetchone () is None
10648+
10649+ # --- fetchmany ---
10650+ cursor .execute ("SELECT col FROM #pytest_varbinarymax ORDER BY DATALENGTH(col)" )
10651+ batch = [r [0 ] for r in cursor .fetchmany (1 )]
10652+ assert batch [0 ] in values
10653+ finally :
10654+ cursor .execute ("DROP TABLE #pytest_varbinarymax" )
10655+ db_connection .commit ()
10656+
1056410657def test_close (db_connection ):
1056510658 """Test closing the cursor"""
1056610659 try :
0 commit comments