Skip to content

Commit 119ca4a

Browse files
authored
CHORE: Remove unused methods from helpers.py & Fix PR Description (#399)
### 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#XXYYZZ) For external contributors: Insert Github Issue number below (e.g. #XYZ) Only one reference is required - either GitHub issue OR ADO Work Item. --> <!-- mssql-python maintainers: ADO Work Item --> > [AB#41750](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/41750) ------------------------------------------------------------------- ### Summary <!-- Insert your summary of changes below. Minimum 10 characters required. --> This pull request removes unused helper functions related to connection string manipulation from the `mssql_python.helpers` module. The primary focus is on cleaning up the codebase by eliminating the `add_driver_to_connection_str` and `add_driver_name_to_app_parameter` functions, as well as their import and usage. Code cleanup and removal of unused functions: * Removed the import of `add_driver_to_connection_str` from `mssql_python/helpers.py` in `connection.py`, as it is no longer used. * Deleted the `add_driver_to_connection_str` function, which previously handled injecting a default ODBC driver into the connection string. * Deleted the `add_driver_name_to_app_parameter` function, which previously ensured the `APP` parameter was set in the connection string. <!-- ### PR Title Guide > For feature requests FEAT: (short-description) > For non-feature requests like test case updates, config updates , dependency updates etc CHORE: (short-description) > For Fix requests FIX: (short-description) > For doc update requests DOC: (short-description) > For Formatting, indentation, or styling update STYLE: (short-description) > For Refactor, without any feature changes REFACTOR: (short-description) > For release related changes, without any feature changes RELEASE: #<RELEASE_VERSION> (short-description) ### Contribution Guidelines External contributors: - Create a GitHub issue first: https://github.com/microsoft/mssql-python/issues/new - Link the GitHub issue in the "GitHub Issue" section above - Follow the PR title format and provide a meaningful summary mssql-python maintainers: - Create an ADO Work Item following internal processes - Link the ADO Work Item in the "ADO Work Item" section above - Follow the PR title format and provide a meaningful summary -->
1 parent 7fe5431 commit 119ca4a

File tree

3 files changed

+2
-105
lines changed

3 files changed

+2
-105
lines changed

.github/PULL_REQUEST_TEMPLATE.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
### Work Item / Issue Reference
22
<!--
33
IMPORTANT: Please follow the PR template guidelines below.
4-
For mssql-python maintainers: Insert your ADO Work Item ID below (e.g. AB#37452)
5-
For external contributors: Insert Github Issue number below (e.g. #149)
4+
For mssql-python maintainers: Insert your ADO Work Item ID below
5+
For external contributors: Insert Github Issue number below
66
Only one reference is required - either GitHub issue OR ADO Work Item.
77
-->
88

mssql_python/connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import mssql_python
2121
from mssql_python.cursor import Cursor
2222
from mssql_python.helpers import (
23-
add_driver_to_connection_str,
2423
sanitize_connection_string,
2524
sanitize_user_input,
2625
validate_attribute_value,

mssql_python/helpers.py

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -16,69 +16,6 @@
1616
# normalize_architecture import removed as it's unused
1717

1818

19-
def add_driver_to_connection_str(connection_str: str) -> str:
20-
"""
21-
Add the DDBC driver to the connection string if not present.
22-
23-
Args:
24-
connection_str (str): The original connection string.
25-
26-
27-
Returns:
28-
str: The connection string with the DDBC driver added.
29-
30-
Raises:
31-
Exception: If the connection string is invalid.
32-
"""
33-
logger.debug(
34-
"add_driver_to_connection_str: Processing connection string (length=%d)",
35-
len(connection_str),
36-
)
37-
driver_name = "Driver={ODBC Driver 18 for SQL Server}"
38-
try:
39-
# Strip any leading or trailing whitespace from the connection string
40-
connection_str = connection_str.strip()
41-
connection_str = add_driver_name_to_app_parameter(connection_str)
42-
43-
# Split the connection string into individual attributes
44-
connection_attributes = connection_str.split(";")
45-
final_connection_attributes = []
46-
47-
# Iterate through the attributes and exclude any existing driver attribute
48-
driver_found = False
49-
for attribute in connection_attributes:
50-
if attribute.lower().split("=")[0] == "driver":
51-
driver_found = True
52-
logger.debug(
53-
"add_driver_to_connection_str: Existing driver attribute found, removing"
54-
)
55-
continue
56-
final_connection_attributes.append(attribute)
57-
58-
# Join the remaining attributes back into a connection string
59-
connection_str = ";".join(final_connection_attributes)
60-
61-
# Insert the driver attribute at the beginning of the connection string
62-
final_connection_attributes.insert(0, driver_name)
63-
connection_str = ";".join(final_connection_attributes)
64-
logger.debug(
65-
"add_driver_to_connection_str: Driver added (had_existing=%s, attr_count=%d)",
66-
str(driver_found),
67-
len(final_connection_attributes),
68-
)
69-
70-
except Exception as e:
71-
logger.debug(
72-
"add_driver_to_connection_str: Failed to process connection string - %s", str(e)
73-
)
74-
raise ValueError(
75-
"Invalid connection string, Please follow the format: "
76-
"Server=server_name;Database=database_name;UID=user_name;PWD=password"
77-
) from e
78-
79-
return connection_str
80-
81-
8219
def check_error(handle_type: int, handle: Any, ret: int) -> None:
8320
"""
8421
Check for errors and raise an exception if an error is found.
@@ -101,45 +38,6 @@ def check_error(handle_type: int, handle: Any, ret: int) -> None:
10138
raise_exception(error_info.sqlState, error_info.ddbcErrorMsg)
10239

10340

104-
def add_driver_name_to_app_parameter(connection_string: str) -> str:
105-
"""
106-
Modifies the input connection string by appending the APP name.
107-
108-
Args:
109-
connection_string (str): The input connection string.
110-
111-
Returns:
112-
str: The modified connection string.
113-
"""
114-
logger.debug("add_driver_name_to_app_parameter: Processing connection string")
115-
# Split the input string into key-value pairs
116-
parameters = connection_string.split(";")
117-
118-
# Initialize variables
119-
app_found = False
120-
modified_parameters = []
121-
122-
# Iterate through the key-value pairs
123-
for param in parameters:
124-
if param.lower().startswith("app="):
125-
# Overwrite the value with 'MSSQL-Python'
126-
app_found = True
127-
key, _ = param.split("=", 1)
128-
modified_parameters.append(f"{key}=MSSQL-Python")
129-
logger.debug("add_driver_name_to_app_parameter: Existing APP parameter overwritten")
130-
else:
131-
# Keep other parameters as is
132-
modified_parameters.append(param)
133-
134-
# If APP key is not found, append it
135-
if not app_found:
136-
modified_parameters.append("APP=MSSQL-Python")
137-
logger.debug("add_driver_name_to_app_parameter: APP parameter added")
138-
139-
# Join the parameters back into a connection string
140-
return ";".join(modified_parameters) + ";"
141-
142-
14341
def sanitize_connection_string(conn_str: str) -> str:
14442
"""
14543
Sanitize the connection string by removing sensitive information.

0 commit comments

Comments
 (0)