Skip to content

Commit 6583708

Browse files
committed
Resolving comments
1 parent b1bbd7d commit 6583708

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

mssql_python/connection.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ def setencoding(self, encoding: Optional[str] = None, ctype: Optional[int] = Non
437437
# Validate encoding using cached validation for better performance
438438
if not _validate_encoding(encoding):
439439
# Log the sanitized encoding for security
440-
logger.debug(
441-
"warning",
440+
logger.warning(
442441
"Invalid encoding attempted: %s",
443442
sanitize_user_input(str(encoding)),
444443
)
@@ -453,8 +452,7 @@ def setencoding(self, encoding: Optional[str] = None, ctype: Optional[int] = Non
453452

454453
# Reject 'utf-16' with BOM for SQL_WCHAR (ambiguous byte order)
455454
if encoding == "utf-16" and ctype == ConstantsDDBC.SQL_WCHAR.value:
456-
logger.debug(
457-
"warning",
455+
logger.warning(
458456
"utf-16 with BOM rejected for SQL_WCHAR",
459457
)
460458
raise ProgrammingError(
@@ -478,8 +476,7 @@ def setencoding(self, encoding: Optional[str] = None, ctype: Optional[int] = Non
478476
valid_ctypes = [ConstantsDDBC.SQL_CHAR.value, ConstantsDDBC.SQL_WCHAR.value]
479477
if ctype not in valid_ctypes:
480478
# Log the sanitized ctype for security
481-
logger.debug(
482-
"warning",
479+
logger.warning(
483480
"Invalid ctype attempted: %s",
484481
sanitize_user_input(str(ctype)),
485482
)
@@ -502,8 +499,7 @@ def setencoding(self, encoding: Optional[str] = None, ctype: Optional[int] = Non
502499
),
503500
)
504501
elif encoding not in UTF16_ENCODINGS:
505-
logger.debug(
506-
"warning",
502+
logger.warning(
507503
"Non-UTF-16 encoding %s attempted with SQL_WCHAR ctype",
508504
sanitize_user_input(encoding),
509505
)
@@ -520,8 +516,7 @@ def setencoding(self, encoding: Optional[str] = None, ctype: Optional[int] = Non
520516
self._encoding_settings = {"encoding": encoding, "ctype": ctype}
521517

522518
# Log with sanitized values for security
523-
logger.debug(
524-
"info",
519+
logger.info(
525520
"Text encoding set to %s with ctype %s",
526521
sanitize_user_input(encoding),
527522
sanitize_user_input(str(ctype)),
@@ -604,8 +599,7 @@ def setdecoding(
604599
SQL_WMETADATA,
605600
]
606601
if sqltype not in valid_sqltypes:
607-
logger.debug(
608-
"warning",
602+
logger.warning(
609603
"Invalid sqltype attempted: %s",
610604
sanitize_user_input(str(sqltype)),
611605
)
@@ -627,8 +621,7 @@ def setdecoding(
627621

628622
# Validate encoding using cached validation for better performance
629623
if not _validate_encoding(encoding):
630-
logger.debug(
631-
"warning",
624+
logger.warning(
632625
"Invalid encoding attempted: %s",
633626
sanitize_user_input(str(encoding)),
634627
)
@@ -642,8 +635,7 @@ def setdecoding(
642635

643636
# Reject 'utf-16' with BOM for SQL_WCHAR (ambiguous byte order)
644637
if sqltype == ConstantsDDBC.SQL_WCHAR.value and encoding == "utf-16":
645-
logger.debug(
646-
"warning",
638+
logger.warning(
647639
"utf-16 with BOM rejected for SQL_WCHAR",
648640
)
649641
raise ProgrammingError(
@@ -656,8 +648,7 @@ def setdecoding(
656648

657649
# Validate SQL_WCHAR only supports UTF-16 encodings (SQL_WMETADATA is more flexible)
658650
if sqltype == ConstantsDDBC.SQL_WCHAR.value and encoding not in UTF16_ENCODINGS:
659-
logger.debug(
660-
"warning",
651+
logger.warning(
661652
"Non-UTF-16 encoding %s attempted with SQL_WCHAR sqltype",
662653
sanitize_user_input(encoding),
663654
)
@@ -682,8 +673,7 @@ def setdecoding(
682673
# Validate ctype
683674
valid_ctypes = [ConstantsDDBC.SQL_CHAR.value, ConstantsDDBC.SQL_WCHAR.value]
684675
if ctype not in valid_ctypes:
685-
logger.debug(
686-
"warning",
676+
logger.warning(
687677
"Invalid ctype attempted: %s",
688678
sanitize_user_input(str(ctype)),
689679
)
@@ -706,8 +696,7 @@ def setdecoding(
706696
),
707697
)
708698
elif encoding not in UTF16_ENCODINGS:
709-
logger.debug(
710-
"warning",
699+
logger.warning(
711700
"Non-UTF-16 encoding %s attempted with SQL_WCHAR ctype",
712701
sanitize_user_input(encoding),
713702
)
@@ -730,8 +719,7 @@ def setdecoding(
730719
SQL_WMETADATA: "SQL_WMETADATA",
731720
}.get(sqltype, str(sqltype))
732721

733-
logger.debug(
734-
"info",
722+
logger.info(
735723
"Text decoding set for %s to %s with ctype %s",
736724
sqltype_name,
737725
sanitize_user_input(encoding),

0 commit comments

Comments
 (0)