-
Notifications
You must be signed in to change notification settings - Fork 31
FEAT: Adding setinputsizes #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
sumitmsft
left a comment
There was a problem hiding this 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]>
…osoft/mssql-python into jahnvi/cursor_setinputsizes
There was a problem hiding this 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
setinputsizesmethod 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.
Work Item / Issue Reference
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
SQLGetTypeInfo,SQLProcedures,SQLForeignKeys,SQLPrimaryKeys,SQLSpecialColumns,SQLStatistics, andSQLColumnsinddbc_bindings.cpp. These allow Python code to directly query metadata about tables, columns, keys, procedures, and supported types.Constants and Type Handling
SQL_CHAR,SQL_INTEGER, etc.) at the module level in__init__.pyfor easier use in Python code.ConstantsDDBCfor catalog API parameters such asSQL_SCOPE_CURROW,SQL_BEST_ROWID,SQL_ROWVER, and others.SQLTypesclass inconstants.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.