Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 21, 2025

Work Item / Issue Reference

AB#34910


Summary

This pull request adds support for per-connection query timeouts to the MSSQL Python driver. Now, you can set a timeout value on a connection, either at creation or later, and all cursors created from that connection will enforce this timeout for query execution. The changes include updates to the connection and cursor classes, integration with the underlying driver, and comprehensive tests for the new functionality.

Query Timeout Support

  • Added a timeout parameter to the Connection class and the connect function, allowing users to specify a query timeout (in seconds) when establishing a database connection. The timeout can also be set or updated via a property on the Connection object.
  • Implemented getter and setter for the timeout property in the Connection class, including input validation and documentation. Setting the timeout updates all subsequently created cursors.
  • Modified the cursor method in Connection to pass the current timeout value to each new Cursor instance.
  • Updated the Cursor class to accept a timeout parameter and, if set, apply it to each query execution using the underlying driver’s statement attribute API.
  • Exposed the SQL_ATTR_QUERY_TIMEOUT constant and the DDBCSQLSetStmtAttr function in the C++ driver bindings to support setting the timeout at the driver level.

Testing and Validation

  • Added comprehensive tests to verify default timeout behavior, setting and getting the timeout property, passing timeout via the constructor, enforcing timeout on long-running queries, and ensuring that updating the connection timeout affects all new cursors.

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

Left a comment. Rest all looks good

@jahnvi480 jahnvi480 requested a review from sumitmsft September 15, 2025 07:31
sumitmsft
sumitmsft previously approved these changes Sep 16, 2025
@jahnvi480 jahnvi480 changed the base branch from jahnvi/connection_outputconverter to main September 18, 2025 09:47
@jahnvi480 jahnvi480 dismissed sumitmsft’s stale review September 18, 2025 09:47

The base branch was changed.

Copilot AI review requested due to automatic review settings September 18, 2025 11:05
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 18, 2025
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 query timeout functionality to the MSSQL Python driver, allowing users to set timeout values at the connection level that apply to all cursors created from that connection.

  • Added timeout parameter to Connection class and connect function with proper validation
  • Implemented timeout enforcement in cursor execute/executemany methods using SQL_ATTR_QUERY_TIMEOUT
  • Exposed necessary C++ driver bindings for setting statement attributes

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
mssql_python/db_connection.py Added timeout parameter to connect function
mssql_python/connection.py Added timeout property with getter/setter and passed to cursor creation
mssql_python/cursor.py Added timeout support in execute/executemany methods
mssql_python/constants.py Added SQL_ATTR_QUERY_TIMEOUT constant
mssql_python/pybind/ddbc_bindings.cpp Exposed DDBCSQLSetStmtAttr function for setting statement attributes
tests/test_003_connection.py Added test imports and cleanup fixture
tests/test_004_cursor.py Added comprehensive tests for decimal separator functionality

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: medium Moderate update size labels Sep 18, 2025
@jahnvi480 jahnvi480 merged commit d521601 into main Sep 18, 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