Skip to content

Commit 12245e8

Browse files
authored
FIX: Execute returning cursor object (#161)
### Work Item / Issue Reference <!-- IMPORTANT: Please follow the PR template guidelines below. For mssql-python maintainers: Insert your ADO Work Item ID below (e.g. AB#37452) For external contributors: Insert Github Issue number below (e.g. #149) Only one reference is required - either GitHub issue OR ADO Work Item. --> <!-- mssql-python maintainers: ADO Work Item --> > AB#3806 ------------------------------------------------------------------- ### Summary This pull request enhances the `Cursor` class in `mssql_python/cursor.py` to support method chaining by modifying the `execute` method to return the cursor itself. It also introduces comprehensive test coverage for method chaining in `tests/test_004_cursor.py`. ### Enhancements to the `Cursor` class: * Modified the `execute` method in `mssql_python/cursor.py` to return the `Cursor` instance, enabling method chaining. (`[[1]] ### Updates to test cases: * Simplified the `test_longwvarchar` test by removing unnecessary loops and assertions, improving readability. * Added new test cases to validate method chaining functionality, including: - Chaining `execute` with `fetchone`, `fetchall`, `fetchmany`, `rowcount`, and `description`. - Testing multiple sequential operations and parameterized queries. - Ensuring chaining works correctly after errors and with statement reuse for performance. --------- Co-authored-by: Jahnvi Thakkar <jathakkar@microsoft.com>
1 parent 365b712 commit 12245e8

File tree

6 files changed

+4344
-45
lines changed

6 files changed

+4344
-45
lines changed

mssql_python/constants.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class ConstantsDDBC(Enum):
9797
SQL_ATTR_ROW_ARRAY_SIZE = 27
9898
SQL_ATTR_ROWS_FETCHED_PTR = 26
9999
SQL_ATTR_ROW_STATUS_PTR = 25
100-
SQL_FETCH_NEXT = 1
101100
SQL_ROW_SUCCESS = 0
102101
SQL_ROW_SUCCESS_WITH_INFO = 1
103102
SQL_ROW_NOROW = 100
@@ -117,6 +116,14 @@ class ConstantsDDBC(Enum):
117116
SQL_NULLABLE = 1
118117
SQL_MAX_NUMERIC_LEN = 16
119118

119+
SQL_FETCH_NEXT = 1
120+
SQL_FETCH_FIRST = 2
121+
SQL_FETCH_LAST = 3
122+
SQL_FETCH_PRIOR = 4
123+
SQL_FETCH_ABSOLUTE = 5
124+
SQL_FETCH_RELATIVE = 6
125+
SQL_FETCH_BOOKMARK = 8
126+
120127
class AuthType(Enum):
121128
"""Constants for authentication types"""
122129
INTERACTIVE = "activedirectoryinteractive"

0 commit comments

Comments
 (0)