-
Notifications
You must be signed in to change notification settings - Fork 31
FEAT: Adding getInfo #201
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
FEAT: Adding getInfo #201
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.
Added some 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#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]>
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 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.
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.