-
Notifications
You must be signed in to change notification settings - Fork 31
FEAT: Adding procedures API #194
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
Merged
jahnvi480
merged 4 commits into
jahnvi/cursor_gettypeinfo
from
jahnvi/cursor_procedures
Sep 15, 2025
Merged
FEAT: Adding procedures API #194
jahnvi480
merged 4 commits into
jahnvi/cursor_gettypeinfo
from
jahnvi/cursor_procedures
Sep 15, 2025
Conversation
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
sumitmsft
requested changes
Sep 11, 2025
Contributor
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 few comments
sumitmsft
approved these changes
Sep 12, 2025
bewithgaurav
approved these changes
Sep 15, 2025
bewithgaurav
approved these changes
Sep 15, 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#34932](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34932) ------------------------------------------------------------------- ### Summary This pull request adds support for retrieving foreign key metadata from SQL Server via ODBC by implementing the `foreignKeys` method in the `Cursor` class and wiring up the necessary C++ bindings for the ODBC `SQLForeignKeys` API. The changes ensure that Python users can now fetch foreign key relationships in a way similar to other database drivers. **Python interface enhancements:** * Added a new `foreignKeys` method to the `Cursor` class in `cursor.py`, allowing users to retrieve foreign key metadata for a specified table or referenced table. The method performs input validation, calls the new C++ binding, and returns results as `Row` objects with appropriate metadata. * Updated imports in `cursor.py` to include the `ProgrammingError` exception, used for input validation in the new method. **C++ DDBC bindings:** * Added a new function pointer type (`SQLForeignKeysFunc`) and corresponding global pointer (`SQLForeignKeys_ptr`) for the ODBC `SQLForeignKeys` API in `ddbc_bindings.h` and initialized it in `ddbc_bindings.cpp`. * Implemented the `SQLForeignKeys_wrap` function in `ddbc_bindings.cpp` to wrap the ODBC call, handling both Windows and Unix platforms, and exposed it to Python as `DDBCSQLForeignKeys`. * Updated the driver loading logic to require `SQLForeignKeys` and fail if it is not present, ensuring the new functionality is always available. --------- Co-authored-by: Jahnvi Thakkar <[email protected]>
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 support for retrieving metadata about stored procedures in SQL Server via the Python driver, including both temporary and permanent procedures. It introduces a new
procedures()method on thecursorobject, updates the C++ pybind layer to expose the ODBCSQLProceduresAPI, and includes a comprehensive suite of tests to ensure correct behavior across various scenarios.New feature: Procedures metadata retrieval
procedures()method to thecursorclass inmssql_python/cursor.pyto fetch information about stored procedures, handling both temporary (using direct queries) and permanent procedures (using the ODBC API). The method supports filtering by procedure name, catalog, and schema, and returns detailed metadata for each procedure.ODBC bindings and pybind integration
SQLProceduresFuncand related extern variable to the ODBC bindings header and implementation files (mssql_python/pybind/ddbc_bindings.h,mssql_python/pybind/ddbc_bindings.cpp).SQLProceduresWfunction pointer during driver initialization and included it in the required function check.SQLProcedures_wrapand exposed it to Python asDDBCSQLProceduresfor cross-platform use.Testing and validation
tests/test_004_cursor.pyto verify the newprocedures()functionality, including filtering by name, schema, and catalog, handling of input/output parameters, result set reporting, and correct behavior with non-existent procedures.