2020from mssql_python .helpers import check_error
2121from mssql_python .logging import logger
2222from mssql_python import ddbc_bindings
23- from mssql_python .exceptions import InterfaceError , NotSupportedError , ProgrammingError , OperationalError , DatabaseError
23+ from mssql_python .exceptions import (
24+ InterfaceError ,
25+ NotSupportedError ,
26+ ProgrammingError ,
27+ OperationalError ,
28+ DatabaseError ,
29+ )
2430from mssql_python .row import Row
2531from mssql_python import get_settings
2632
@@ -292,23 +298,21 @@ def _get_encoding_settings(self):
292298 Returns:
293299 dict: A dictionary with 'encoding' and 'ctype' keys, or default settings if not available
294300 """
295- if hasattr (self ._connection , ' getencoding' ):
301+ if hasattr (self ._connection , " getencoding" ):
296302 try :
297303 return self ._connection .getencoding ()
298304 except (OperationalError , DatabaseError ) as db_error :
299305 # Only catch database-related errors, not programming errors
300306 from mssql_python .helpers import log
301- log ('warning' , f"Failed to get encoding settings from connection due to database error: { db_error } " )
302- return {
303- 'encoding' : 'utf-16le' ,
304- 'ctype' : ddbc_sql_const .SQL_WCHAR .value
305- }
307+
308+ log (
309+ "warning" ,
310+ f"Failed to get encoding settings from connection due to database error: { db_error } " ,
311+ )
312+ return {"encoding" : "utf-16le" , "ctype" : ddbc_sql_const .SQL_WCHAR .value }
306313
307314 # Return default encoding settings if getencoding is not available
308- return {
309- 'encoding' : 'utf-16le' ,
310- 'ctype' : ddbc_sql_const .SQL_WCHAR .value
311- }
315+ return {"encoding" : "utf-16le" , "ctype" : ddbc_sql_const .SQL_WCHAR .value }
312316
313317 def _get_decoding_settings (self , sql_type ):
314318 """
@@ -326,11 +330,15 @@ def _get_decoding_settings(self, sql_type):
326330 except (OperationalError , DatabaseError ) as db_error :
327331 # Only handle expected database-related errors
328332 from mssql_python .helpers import log
329- log ('warning' , f"Failed to get decoding settings for SQL type { sql_type } due to database error: { db_error } " )
333+
334+ log (
335+ "warning" ,
336+ f"Failed to get decoding settings for SQL type { sql_type } due to database error: { db_error } " ,
337+ )
330338 if sql_type == ddbc_sql_const .SQL_WCHAR .value :
331- return {' encoding' : ' utf-16le' , ' ctype' : ddbc_sql_const .SQL_WCHAR .value }
339+ return {" encoding" : " utf-16le" , " ctype" : ddbc_sql_const .SQL_WCHAR .value }
332340 else :
333- return {' encoding' : ' utf-8' , ' ctype' : ddbc_sql_const .SQL_CHAR .value }
341+ return {" encoding" : " utf-8" , " ctype" : ddbc_sql_const .SQL_CHAR .value }
334342
335343 def _map_sql_type ( # pylint: disable=too-many-arguments,too-many-positional-arguments,too-many-locals,too-many-return-statements,too-many-branches
336344 self ,
@@ -1252,7 +1260,7 @@ def execute( # pylint: disable=too-many-locals,too-many-branches,too-many-state
12521260 parameters_type ,
12531261 self .is_stmt_prepared ,
12541262 use_prepare ,
1255- encoding_settings
1263+ encoding_settings ,
12561264 )
12571265 # Check return code
12581266 try :
@@ -2130,7 +2138,12 @@ def fetchone(self) -> Union[None, Row]:
21302138 # Fetch raw data
21312139 row_data = []
21322140 try :
2133- ret = ddbc_bindings .DDBCSQLFetchOne (self .hstmt , row_data , char_decoding .get ('encoding' , 'utf-8' ), wchar_decoding .get ('encoding' , 'utf-16le' ))
2141+ ret = ddbc_bindings .DDBCSQLFetchOne (
2142+ self .hstmt ,
2143+ row_data ,
2144+ char_decoding .get ("encoding" , "utf-8" ),
2145+ wchar_decoding .get ("encoding" , "utf-16le" ),
2146+ )
21342147
21352148 if self .hstmt :
21362149 self .messages .extend (ddbc_bindings .DDBCSQLGetAllDiagRecords (self .hstmt ))
@@ -2184,7 +2197,13 @@ def fetchmany(self, size: Optional[int] = None) -> List[Row]:
21842197 # Fetch raw data
21852198 rows_data = []
21862199 try :
2187- ret = ddbc_bindings .DDBCSQLFetchMany (self .hstmt , rows_data , size , char_decoding .get ('encoding' , 'utf-8' ), wchar_decoding .get ('encoding' , 'utf-16le' ))
2200+ ret = ddbc_bindings .DDBCSQLFetchMany (
2201+ self .hstmt ,
2202+ rows_data ,
2203+ size ,
2204+ char_decoding .get ("encoding" , "utf-8" ),
2205+ wchar_decoding .get ("encoding" , "utf-16le" ),
2206+ )
21882207
21892208 if self .hstmt :
21902209 self .messages .extend (ddbc_bindings .DDBCSQLGetAllDiagRecords (self .hstmt ))
@@ -2230,7 +2249,12 @@ def fetchall(self) -> List[Row]:
22302249 # Fetch raw data
22312250 rows_data = []
22322251 try :
2233- ret = ddbc_bindings .DDBCSQLFetchAll (self .hstmt , rows_data , char_decoding .get ('encoding' , 'utf-8' ), wchar_decoding .get ('encoding' , 'utf-16le' ))
2252+ ret = ddbc_bindings .DDBCSQLFetchAll (
2253+ self .hstmt ,
2254+ rows_data ,
2255+ char_decoding .get ("encoding" , "utf-8" ),
2256+ wchar_decoding .get ("encoding" , "utf-16le" ),
2257+ )
22342258
22352259 if self .hstmt :
22362260 self .messages .extend (ddbc_bindings .DDBCSQLGetAllDiagRecords (self .hstmt ))
0 commit comments