Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 22, 2025

Work Item / Issue Reference

AB#34911


Summary

This pull request adds new functionality for retrieving ODBC driver and data source information and improves the handling of ODBC constants throughout the codebase. The main changes include implementing a Python-accessible getinfo method for connections, introducing a comprehensive set of ODBC info constants, and wiring up the underlying C++ bindings to support these features.

ODBC Driver and Data Source Information Retrieval

  • Added a getinfo method to the Python Connection class, allowing users to query driver/data source information using ODBC info types. This method is exposed via the C++ bindings and handles type conversion for returned values.

  • Implemented the underlying C++ logic in Connection::getInfo and ConnectionHandle::getInfo to call ODBC's SQLGetInfo, manage buffer sizing, and convert results to appropriate Python types (string, integer, etc.).

  • Registered the ODBC SQLGetInfo function pointer in the driver bindings and ensured it is loaded and validated at runtime.

ODBC Constants and Usage

  • Added a new GetInfoConstants enum to mssql_python/constants.py, providing a comprehensive set of ODBC info type constants for use with the getinfo method and other driver interactions.

  • Updated Python and test code to import and use the new GetInfoConstants enum for driver information queries.

Connection Properties

  • Introduced a new searchescape property on the Python Connection class to retrieve the ODBC search pattern escape character using the new getinfo method, with robust error handling and fallback behavior.

Miscellaneous

  • Minor C++ macro addition for SQLSMALLINT maximum value, used in buffer sizing for ODBC calls.

These changes collectively enable advanced introspection of the ODBC driver and data source capabilities, improve code maintainability through centralized constants, and enhance error handling and type safety in driver interactions.

@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 22, 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.

Added some comments

@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: medium Moderate update size labels Sep 16, 2025
sumitmsft
sumitmsft previously approved these changes Sep 17, 2025
@jahnvi480 jahnvi480 changed the base branch from jahnvi/global_decimalseperator to main September 18, 2025 08:32
@jahnvi480 jahnvi480 dismissed sumitmsft’s stale review September 18, 2025 08:32

The base branch was changed.

### 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#34909](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34909)

-------------------------------------------------------------------
### Summary   
This pull request adds a new `searchescape` property to the `Connection`
class in `mssql_python`, which exposes the ODBC search pattern escape
character used for escaping special characters in SQL LIKE clauses. It
also introduces comprehensive tests to ensure correct and consistent
behavior of this property, including its use in various SQL queries and
its caching mechanism.

Enhancements to connection escape character handling:

* Added a `searchescape` property to the `Connection` class in
`connection.py`, which retrieves and caches the ODBC search pattern
escape character using `SQLGetInfo`, with sensible defaults and error
handling.
* Imported `GetInfoConstants` in `connection.py` to support the new
property.

Testing improvements:

* Added multiple tests in `test_003_connection.py` to verify the
`searchescape` property's basic functionality, its use in SQL LIKE
queries (with `%`, `_`, and bracket wildcards), multiple escape
scenarios, and property consistency and caching.

---------

Co-authored-by: Jahnvi Thakkar <[email protected]>
Copilot AI review requested due to automatic review settings September 18, 2025 13:22
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 pull request adds comprehensive support for retrieving ODBC driver and data source information through a new getinfo method on the Connection class. It implements the ODBC SQLGetInfo functionality with complete C++ bindings and provides extensive test coverage for various information types and data formats.

  • Added getinfo method to Connection class with comprehensive ODBC information retrieval capabilities
  • Implemented C++ backend with SQLGetInfo bindings and appropriate type handling for strings and integers
  • Enhanced testing with decimal separator functionality, lowercase column handling, and search pattern escape character support

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/test_004_cursor.py Added comprehensive tests for lowercase attribute and decimal separator functionality
tests/test_003_connection.py Added extensive getinfo tests covering driver info, SQL support, limits, and search escape functionality
tests/test_001_globals.py Added tests for lowercase and decimal separator global settings
mssql_python/row.py Enhanced Row class with decimal separator support and lowercase column name handling
mssql_python/pybind/ddbc_bindings.h Added SQLGetInfo function pointer typedef and decimal separator declarations
mssql_python/pybind/ddbc_bindings.cpp Implemented SQLGetInfo loading, decimal separator handling, and getinfo C++ method binding
mssql_python/pybind/connection/connection.h Added getInfo method declarations to Connection and ConnectionHandle classes
mssql_python/pybind/connection/connection.cpp Implemented comprehensive getInfo method with proper type handling and buffer management
mssql_python/cursor.py Updated cursor to support lowercase column names and improved Row object creation
mssql_python/constants.py Added comprehensive GetInfoConstants enum with 130+ ODBC information type constants
mssql_python/connection.py Added getinfo method and searchescape property to Connection class
mssql_python/init.py Added global settings, decimal separator functions, and lowercase attribute support

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
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
@bewithgaurav bewithgaurav merged commit bd5b323 into main Sep 19, 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