Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 21, 2025

Work Item / Issue Reference

AB#32890


Summary

This pull request adds comprehensive support for advanced SQL metadata and catalog functions to the MSSQL Python bindings, making it easier to interact with database schema information and supported data types from Python. The changes include new wrapper functions and Python bindings for several ODBC catalog APIs, the addition of SQL type constants, and enhancements to the constants module for easier type validation and categorization.

SQL Catalog & Metadata API Support

  • Added wrapper functions and Python bindings for ODBC catalog APIs: SQLGetTypeInfo, SQLProcedures, SQLForeignKeys, SQLPrimaryKeys, SQLSpecialColumns, SQLStatistics, and SQLColumns in ddbc_bindings.cpp. These allow Python code to directly query metadata about tables, columns, keys, procedures, and supported types.

Constants and Type Handling

  • Exported SQL type constants (e.g., SQL_CHAR, SQL_INTEGER, etc.) at the module level in __init__.py for easier use in Python code.
  • Added new constants to ConstantsDDBC for catalog API parameters such as SQL_SCOPE_CURROW, SQL_BEST_ROWID, SQL_ROWVER, and others.
  • Introduced the SQLTypes class in constants.py, providing methods to retrieve sets of valid SQL types and categorize them (e.g., string types, numeric types), which can help with input validation and type checking in Python.

These changes significantly improve the ability of Python applications to introspect and work with database schema and type information, making your code more robust and flexible when dealing with SQL Server databases.

@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 21, 2025
Copy link
Contributor

@sumitmsft sumitmsft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments...

### 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 <[email protected]>
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: medium Moderate update size labels Sep 15, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 15, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 15, 2025
sumitmsft
sumitmsft previously approved these changes Sep 16, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 17, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 17, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 17, 2025
@jahnvi480 jahnvi480 changed the base branch from jahnvi/connection_timeout to main September 18, 2025 11:40
@jahnvi480 jahnvi480 dismissed sumitmsft’s stale review September 18, 2025 11:40

The base branch was changed.

Copilot AI review requested due to automatic review settings September 18, 2025 16:52
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive support for advanced SQL metadata and catalog functions to the MSSQL Python bindings, implementing setinputsizes functionality and various ODBC catalog APIs for database introspection.

  • Addition of setinputsizes method for explicit SQL parameter type specification
  • Implementation of ODBC catalog APIs (SQLGetTypeInfo, SQLProcedures, SQLForeignKeys, etc.)
  • Addition of SQL type constants at module level and enhanced constants management

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/test_003_connection.py Adds comprehensive test suite for connection methods, output converters, and timeout functionality with some duplicate code removal
tests/test_001_globals.py Adds tests for decimal separator functionality with some duplicate test definitions
mssql_python/pybind/ddbc_bindings.h Defines new ODBC catalog function type definitions and external declarations
mssql_python/pybind/ddbc_bindings.cpp Implements wrapper functions for catalog APIs and adds Python bindings
mssql_python/cursor.py Implements setinputsizes method and adds catalog API methods (getTypeInfo, procedures, etc.)
mssql_python/constants.py Adds new constants for catalog APIs and SQLTypes utility class
mssql_python/init.py Exports SQL type constants at module level for easier access

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
@jahnvi480 jahnvi480 merged commit c14cc42 into main Sep 18, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: large Substantial code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants