Commit d6ddedb
authored
FEAT: Row string-key indexing (#589)
### Work Item / Issue Reference
<!--
IMPORTANT: Please follow the PR template guidelines below.
For mssql-python maintainers: Insert your ADO Work Item ID below
For external contributors: Insert Github Issue number below
Only one reference is required - either GitHub issue OR ADO Work Item.
-->
<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#45119](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/45119)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #582
-------------------------------------------------------------------
### Summary
This pull request enhances the usability of the `Row` class by allowing
access to row values using column names as string keys (e.g.,
`row["col"]`), in addition to existing integer index and attribute
access. It also introduces case-insensitive string-key access when the
cursor's `lowercase` attribute is enabled. Comprehensive tests have been
added to ensure correct behavior for these new access patterns.
### Enhancements to Row Access Patterns
* Updated the `Row.__getitem__` method in `mssql_python/row.py` to
support accessing values by column name as a string key, including
case-insensitive lookup when the cursor's `lowercase` attribute is set.
### Testing Additions
* Added `test_row_string_key_indexing` and
`test_row_string_key_case_insensitive_with_lowercase` to
`tests/test_001_globals.py` to verify string-key and case-insensitive
access, as well as backward compatibility with integer and slice access.
* Added `test_row_string_key_indexing` to `tests/test_004_cursor.py` to
test string-key access on real query results, ensuring consistency with
index and attribute access and correct error handling for missing keys.1 parent bef3d31 commit d6ddedb
4 files changed
Lines changed: 165 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1124 | 1124 | | |
1125 | 1125 | | |
1126 | 1126 | | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
1127 | 1130 | | |
1128 | 1131 | | |
1129 | 1132 | | |
1130 | 1133 | | |
1131 | 1134 | | |
1132 | 1135 | | |
1133 | 1136 | | |
1134 | | - | |
| 1137 | + | |
1135 | 1138 | | |
1136 | 1139 | | |
1137 | 1140 | | |
| |||
1547 | 1550 | | |
1548 | 1551 | | |
1549 | 1552 | | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
1550 | 1558 | | |
1551 | 1559 | | |
1552 | 1560 | | |
1553 | 1561 | | |
1554 | 1562 | | |
1555 | 1563 | | |
| 1564 | + | |
1556 | 1565 | | |
1557 | 1566 | | |
1558 | 1567 | | |
| |||
2451 | 2460 | | |
2452 | 2461 | | |
2453 | 2462 | | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
2454 | 2468 | | |
2455 | 2469 | | |
2456 | 2470 | | |
2457 | 2471 | | |
2458 | 2472 | | |
2459 | 2473 | | |
| 2474 | + | |
2460 | 2475 | | |
2461 | 2476 | | |
2462 | 2477 | | |
| |||
2506 | 2521 | | |
2507 | 2522 | | |
2508 | 2523 | | |
2509 | | - | |
| 2524 | + | |
2510 | 2525 | | |
2511 | 2526 | | |
2512 | 2527 | | |
2513 | 2528 | | |
2514 | 2529 | | |
2515 | 2530 | | |
| 2531 | + | |
2516 | 2532 | | |
2517 | 2533 | | |
2518 | 2534 | | |
| |||
2569 | 2585 | | |
2570 | 2586 | | |
2571 | 2587 | | |
2572 | | - | |
| 2588 | + | |
2573 | 2589 | | |
2574 | 2590 | | |
2575 | 2591 | | |
| |||
2580 | 2596 | | |
2581 | 2597 | | |
2582 | 2598 | | |
| 2599 | + | |
2583 | 2600 | | |
2584 | 2601 | | |
2585 | 2602 | | |
| |||
2630 | 2647 | | |
2631 | 2648 | | |
2632 | 2649 | | |
2633 | | - | |
| 2650 | + | |
2634 | 2651 | | |
2635 | 2652 | | |
2636 | 2653 | | |
| |||
2641 | 2658 | | |
2642 | 2659 | | |
2643 | 2660 | | |
| 2661 | + | |
2644 | 2662 | | |
2645 | 2663 | | |
2646 | 2664 | | |
| |||
2754 | 2772 | | |
2755 | 2773 | | |
2756 | 2774 | | |
| 2775 | + | |
2757 | 2776 | | |
2758 | 2777 | | |
2759 | 2778 | | |
| |||
2780 | 2799 | | |
2781 | 2800 | | |
2782 | 2801 | | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
2783 | 2807 | | |
2784 | 2808 | | |
2785 | 2809 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| |||
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
| |||
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
41 | 51 | | |
42 | 52 | | |
43 | 53 | | |
| |||
60 | 70 | | |
61 | 71 | | |
62 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
63 | 76 | | |
64 | 77 | | |
65 | 78 | | |
| |||
156 | 169 | | |
157 | 170 | | |
158 | 171 | | |
159 | | - | |
160 | | - | |
161 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
162 | 188 | | |
163 | 189 | | |
164 | 190 | | |
| |||
175 | 201 | | |
176 | 202 | | |
177 | 203 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
184 | 209 | | |
185 | 210 | | |
186 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
996 | 996 | | |
997 | 997 | | |
998 | 998 | | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2876 | 2876 | | |
2877 | 2877 | | |
2878 | 2878 | | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
| 2915 | + | |
| 2916 | + | |
2879 | 2917 | | |
2880 | 2918 | | |
2881 | 2919 | | |
| |||
0 commit comments