Skip to content

Commit 2e21aab

Browse files
authored
Merge branch 'main' into subrata-ms/GCSegFault
2 parents b7f105f + 0c8e43c commit 2e21aab

File tree

4 files changed

+19
-107
lines changed

4 files changed

+19
-107
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

eng/pipelines/pr-validation-pipeline.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
displayName: 'CodeQL Security Analysis'
1212
pool:
1313
vmImage: 'ubuntu-latest'
14-
14+
1515
steps:
1616
- script: |
1717
sudo apt-get update
@@ -45,10 +45,14 @@ jobs:
4545
condition: always()
4646
displayName: 'Finalize CodeQL'
4747

48-
- job: PytestOnWindows
48+
- job: pytestonwindows
4949
displayName: 'Windows x64'
5050
pool:
5151
vmImage: 'windows-latest'
52+
variables:
53+
# Enable CodeQL for this job to update the old stale snapshot (build_jobname=pytestonwindows)
54+
# This can be removed once the old CodeQL issue SM02986 is cleared
55+
Codeql.Enabled: true
5256

5357
strategy:
5458
matrix:
@@ -225,11 +229,22 @@ jobs:
225229
env:
226230
DB_PASSWORD: $(DB_PASSWORD)
227231
232+
# ============== CodeQL Init (temporary - remove after SM02986 is cleared) ==============
233+
- task: CodeQL3000Init@0
234+
inputs:
235+
Enabled: true
236+
displayName: 'Initialize CodeQL (temporary)'
237+
228238
- script: |
229239
cd mssql_python\pybind
230240
build.bat x64
231241
displayName: 'Build .pyd file'
232242
243+
# ============== CodeQL Finalize (temporary - remove after SM02986 is cleared) ==============
244+
- task: CodeQL3000Finalize@0
245+
condition: always()
246+
displayName: 'Finalize CodeQL (temporary)'
247+
233248
# Run tests for LocalDB
234249
- script: |
235250
python -m pytest -v --junitxml=test-results-localdb.xml --cov=. --cov-report=xml:coverage-localdb.xml --capture=tee-sys --cache-clear

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)