Skip to content

Commit 997ded6

Browse files
authored
FEAT: Adding getTypeInfo (#193)
### 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#34934](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34934) ------------------------------------------------------------------- ### Summary This pull request adds support for retrieving ODBC data type information via a new `getTypeInfo` method on the `cursor` object, exposing the underlying `SQLGetTypeInfo` API. It includes the necessary C++/Python bindings, error handling, and comprehensive test coverage to ensure correct behavior for different data types and usage scenarios. ### Feature: Data type information retrieval * Added a new `getTypeInfo` method to the `cursor` class in `mssql_python/cursor.py`, allowing users to retrieve metadata about supported SQL data types via the ODBC `SQLGetTypeInfo` API. The method supports querying all types or a specific type and returns results as a list of `Row` objects with a well-defined column map. ### Bindings and driver integration * Introduced a new function pointer type for `SQLGetTypeInfo` (`SQLGetTypeInfoFunc`) and integrated it into the driver loading and verification process in `mssql_python/pybind/ddbc_bindings.h` and `mssql_python/pybind/ddbc_bindings.cpp`. This ensures the function pointer is loaded and checked along with other ODBC APIs. * Added a wrapper function and Python binding for `SQLGetTypeInfo`, exposing it as `DDBCSQLGetTypeInfo` in the Python module. ### Testing * Added a comprehensive suite of tests in `tests/test_004_cursor.py` to validate the new `getTypeInfo` method. Tests cover retrieving all types, specific types, result structure, numeric and datetime types, binary types, multiple successive calls, and repeated identical queries for consistency and efficiency. --------- Co-authored-by: Jahnvi Thakkar <jathakkar@microsoft.com>
1 parent e4f56c7 commit 997ded6

5 files changed

Lines changed: 3327 additions & 2 deletions

File tree

mssql_python/constants.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ class ConstantsDDBC(Enum):
117117
SQL_NULLABLE = 1
118118
SQL_MAX_NUMERIC_LEN = 16
119119
SQL_ATTR_QUERY_TIMEOUT = 0
120+
SQL_SCOPE_CURROW = 0
121+
SQL_BEST_ROWID = 1
122+
SQL_ROWVER = 2
123+
SQL_NO_NULLS = 0
124+
SQL_NULLABLE_UNKNOWN = 2
125+
SQL_INDEX_UNIQUE = 0
126+
SQL_INDEX_ALL = 1
127+
SQL_QUICK = 0
128+
SQL_ENSURE = 1
120129

121130
class AuthType(Enum):
122131
"""Constants for authentication types"""

0 commit comments

Comments
 (0)