@@ -152,8 +152,8 @@ def __init__(self, connection_str: str = "", autocommit: bool = False, attrs_bef
152152 # Initialize encoding settings with defaults for Python 3
153153 # Python 3 only has str (which is Unicode), so we use utf-16le by default
154154 self ._encoding_settings = {
155- 'encoding' : 'utf-16le ' ,
156- 'ctype' : ConstantsDDBC .SQL_WCHAR .value
155+ 'encoding' : 'utf-8 ' ,
156+ 'ctype' : ConstantsDDBC .SQL_CHAR .value
157157 }
158158
159159 # Initialize decoding settings with Python 3 defaults
@@ -373,9 +373,10 @@ def setencoding(self, encoding=None, ctype=None):
373373
374374 # Enforce UTF-16LE for SQL_WCHAR
375375 if ctype == ConstantsDDBC .SQL_WCHAR .value and encoding not in UTF16_ENCODINGS :
376- raise ValueError (
377- f"SQL_WCHAR must use UTF-16LE encoding. '{ encoding } ' is not supported for SQL_WCHAR. "
378- f"Use SQL_CHAR if you need to use '{ encoding } ' encoding."
376+ raise ProgrammingError (
377+ driver_error = f"SQL_WCHAR requires UTF-16LE encoding" ,
378+ ddbc_error = f"SQL_WCHAR must use UTF-16LE encoding. '{ encoding } ' is not supported for SQL_WCHAR. "
379+ f"Use SQL_CHAR if you need to use '{ encoding } ' encoding."
379380 )
380381
381382 # Store the encoding settings
@@ -462,9 +463,9 @@ def setdecoding(self, sqltype, encoding=None, ctype=None):
462463 # For SQL_WCHAR and SQL_WMETADATA, enforce UTF-16LE encoding and SQL_WCHAR ctype
463464 if sqltype in (ConstantsDDBC .SQL_WCHAR .value , SQL_WMETADATA ):
464465 if encoding is not None and encoding .lower () not in UTF16_ENCODINGS :
465- raise ValueError (
466- f"SQL_WCHAR and SQL_WMETADATA must use UTF-16LE encoding. '{ encoding } ' is not supported. "
467- f"Custom encodings are only supported for SQL_CHAR."
466+ raise ProgrammingError (
467+ driver_error = f"SQL_WCHAR and SQL_WMETADATA must use UTF-16LE encoding. '{ encoding } ' is not supported." ,
468+ ddbc_error = f"Custom encodings are only supported for SQL_CHAR. ' { encoding } ' is not valid for SQL_WCHAR or SQL_WMETADATA ."
468469 )
469470 # Always enforce UTF-16LE for wide character types
470471 encoding = 'utf-16le'
0 commit comments