Commit 0bc1b5b
authored
FEAT: Connection.closed property (microsoft#398)
### 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. microsoft#149)
Only one reference is required - either GitHub issue OR ADO Work Item.
-->
<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#41491](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/41491)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: microsoft#394
-------------------------------------------------------------------
### Summary
This pull request introduces a new `closed` property to the connection
class in `mssql_python/connection.py`, providing a clear and explicit
way to check if a connection has been closed. Comprehensive tests have
been added to ensure correct behavior of this property under various
scenarios, improving reliability and clarity for users of the connection
API.
**Connection class enhancements:**
* Added a `closed` property to the connection class, which returns
`True` if `close()` was called, and `False` otherwise. This property
does not indicate connection health, only whether `close()` was
explicitly invoked.
**Test coverage improvements:**
* Added tests to verify the `closed` property reflects the connection
state before and after calling `close()`.
* Added tests to confirm that calling `close()` multiple times is safe
and the `closed` property remains `True` (idempotency).
* Added tests to check the `closed` property when using the connection
as a context manager, ensuring it is `True` after exiting the block.
* Added tests to verify that operations on a closed connection raise
appropriate exceptions, and the `closed` property accurately reflects
the closed state.1 parent 9a30068 commit 0bc1b5b
2 files changed
Lines changed: 81 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
448 | 464 | | |
449 | 465 | | |
450 | 466 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
365 | 430 | | |
366 | 431 | | |
367 | 432 | | |
| |||
0 commit comments