Skip to content

Commit 06e75ad

Browse files
jahnvi480Sumit Sarabhai
authored andcommitted
Merged PR 5300: Adding arraysize property
Adding arraysize property ---- #### AI description (iteration 1) #### PR Classification New feature #### PR Summary This pull request introduces the `arraysize` property to the cursor functionality. - `mssql_python/cursor.py`: Set default fetch size to `arraysize` if not specified. - `tests/test_cursor.py`: Added tests to verify the `arraysize` property and its behavior when changed. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #32884
1 parent 19bd82a commit 06e75ad

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

mssql_python/cursor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, connection) -> None:
5454
self._initialize_cursor()
5555
self.description = None
5656
self.rowcount = -1
57-
self.arraysize = 1
57+
self.arraysize = 1 # Default number of rows to fetch at a time is 1, user can change it
5858
self.buffer_length = 1024 # Default buffer length for string data
5959
self.closed = False # Flag to indicate if the cursor is closed
6060
self.last_executed_stmt = "" # Stores the last statement executed by this cursor
@@ -607,7 +607,7 @@ def fetchmany(self, size: int = None) -> List[tuple]:
607607
self._check_closed() # Check if the cursor is closed
608608

609609
if size is None:
610-
size = 1
610+
size = self.arraysize
611611

612612
try:
613613
# Fetch the next set of rows

tests/test_cursor.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,13 @@ def test_fetchmany(cursor):
402402
assert isinstance(rows, list), "fetchmany should return a list"
403403
assert len(rows) == 2, "Incorrect number of rows returned"
404404

405+
def test_fetchmany_with_arraysize(cursor, db_connection):
406+
"""Test fetchmany with arraysize"""
407+
cursor.arraysize = 3
408+
cursor.execute("SELECT * FROM all_data_types")
409+
rows = cursor.fetchmany()
410+
assert len(rows) == 3, "fetchmany with arraysize returned incorrect number of rows"
411+
405412
def test_fetchall(cursor):
406413
"""Test fetching all rows"""
407414
cursor.execute("SELECT * FROM all_data_types")
@@ -433,10 +440,14 @@ def test_execute_invalid_query(cursor):
433440
# assert row[10] == TEST_DATA[10], "Date mismatch"
434441
# assert round(row[11], 5) == round(TEST_DATA[11], 5), "Real mismatch"
435442

436-
# def test_arraysize(cursor):
437-
# """Test arraysize"""
438-
# cursor.arraysize = 10
439-
# assert cursor.arraysize == 10, "Arraysize mismatch"
443+
def test_arraysize(cursor):
444+
"""Test arraysize"""
445+
cursor.arraysize = 10
446+
assert cursor.arraysize == 10, "Arraysize mismatch"
447+
cursor.arraysize = 5
448+
assert cursor.arraysize == 5, "Arraysize mismatch after change"
449+
450+
440451

441452
# def test_description(cursor):
442453
# """Test description"""

0 commit comments

Comments
 (0)