Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 20, 2025

Work Item / Issue Reference

AB#34905


Summary

This pull request introduces a new global lowercase flag to the mssql_python package, allowing users to control whether column names in query results are automatically converted to lowercase. The changes include updates to the global settings infrastructure, the Cursor and Row classes to support case-insensitive access, and comprehensive tests to ensure correct behavior.

Global lowercase flag and settings:

  • Added a global lowercase flag and supporting infrastructure to mssql_python/__init__.py, including a Settings class and a get_settings() accessor. The default value is False.
  • Exported the lowercase flag for external use and updated tests to check its default value.

Cursor and Row class enhancements:

  • Modified the Cursor class to read the global lowercase setting and pass it to Row objects. The _initialize_description method now lowercases column names in the description if the flag is set.
  • Updated the Row class to support attribute access by column name, respecting the lowercase flag for case-insensitive lookup.
  • Adjusted cursor fetch methods to pass the Cursor instance to Row objects for correct lowercase handling.

Testing improvements:

  • Added a comprehensive test for the lowercase flag in tests/test_004_cursor.py, verifying that column names in the cursor description and row attribute access are correctly lowercased when the flag is enabled.
  • Ensured proper cleanup and restoration of global state in the new test.

Copilot AI review requested due to automatic review settings August 20, 2025 09:15
@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 20, 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 introduces a global lowercase flag to the mssql_python package, allowing users to control whether column names in query results are automatically converted to lowercase. The feature includes updates to the global settings infrastructure, cursor and row classes to support the lowercase functionality, and comprehensive tests.

  • Added global lowercase flag with supporting Settings class and accessor functions
  • Modified Cursor and Row classes to respect the lowercase setting for column name handling
  • Updated Row class to support case-insensitive attribute access when lowercase mode is enabled

Reviewed Changes

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

Show a summary per file
File Description
mssql_python/init.py Introduces Settings class, global lowercase flag, and get_settings() accessor
mssql_python/cursor.py Updates cursor to read global lowercase setting and apply it to column descriptions
mssql_python/row.py Modifies Row class to support case-insensitive attribute access and updated constructor
tests/test_001_globals.py Adds test to verify default value of lowercase flag
tests/test_004_cursor.py Adds comprehensive test for lowercase functionality with proper cleanup

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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.

Added a comment.. Please resolve. Rest all looks good

@sumitmsft
Copy link
Contributor

sumitmsft commented Aug 24, 2025

  • Document the new lowercase global in the package docs/readme.

Documentation Enhancement Needed:

The new lowercase global variable should be documented in the package documentation to help users understand its behavior and impact.

Recommendation:

Add documentation for the lowercase global to the main package README. This should include:

Purpose: Explain that lowercase controls column name case sensitivity in Row attribute access

Default behavior: lowercase=False (case-sensitive, preserves original column names)

When enabled: lowercase=True enables case-insensitive attribute access by converting all column names to lowercase

Performance note: When enabled, adds slight overhead during cursor description initialization for column name processing

Usage Example:

`
import mssql_python

Enable case-insensitive column access
mssql_python.lowercase = True

Now all these work regardless of actual column casing:
row.column_name # Works
row.COLUMN_NAME # Works
row.Column_Name # Works
`

Add a new "Configuration Options" section to the main package README, or include it in an existing "Usage" section if one exists.

This documentation will help users understand when and why they might want to enable this feature, especially those migrating from other database libraries that have different case sensitivity behaviors.

@jahnvi480 jahnvi480 requested a review from sumitmsft September 17, 2025 06:13
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: medium Moderate update size labels Sep 17, 2025
@jahnvi480 jahnvi480 merged commit 5fe06f5 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