Conversation
sumitmsft
previously approved these changes
Sep 17, 2025
### 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]>
Contributor
There was a problem hiding this comment.
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
getinfomethod 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.
sumitmsft
approved these changes
Sep 19, 2025
bewithgaurav
approved these changes
Sep 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work Item / Issue Reference
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
getinfomethod 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
getinfomethod to the PythonConnectionclass, 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::getInfoandConnectionHandle::getInfoto call ODBC'sSQLGetInfo, manage buffer sizing, and convert results to appropriate Python types (string, integer, etc.).Registered the ODBC
SQLGetInfofunction pointer in the driver bindings and ensured it is loaded and validated at runtime.ODBC Constants and Usage
Added a new
GetInfoConstantsenum tomssql_python/constants.py, providing a comprehensive set of ODBC info type constants for use with thegetinfomethod and other driver interactions.Updated Python and test code to import and use the new
GetInfoConstantsenum for driver information queries.Connection Properties
searchescapeproperty on the PythonConnectionclass to retrieve the ODBC search pattern escape character using the newgetinfomethod, with robust error handling and fallback behavior.Miscellaneous
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.