@@ -4273,32 +4273,15 @@ def test_converter_integration(db_connection):
42734273 cursor = db_connection .cursor ()
42744274 sql_wvarchar = ConstantsDDBC .SQL_WVARCHAR .value
42754275
4276- # Test with string converter
4276+ # Register converter for SQL_WVARCHAR type
42774277 db_connection .add_output_converter (sql_wvarchar , custom_string_converter )
42784278
42794279 # Test a simple string query
42804280 cursor .execute ("SELECT N'test string' AS test_col" )
42814281 row = cursor .fetchone ()
42824282
4283- # Check if the type matches what we expect for SQL_WVARCHAR
4284- # For Cursor.description, the second element is the type code
4285- column_type = cursor .description [0 ][1 ]
4286-
4287- # If the cursor description has SQL_WVARCHAR as the type code,
4288- # then our converter should be applied
4289- if column_type == sql_wvarchar :
4290- assert row [0 ].startswith ("CONVERTED:" ), "Output converter not applied"
4291- else :
4292- # If the type code is different, adjust the test or the converter
4293- print (f"Column type is { column_type } , not { sql_wvarchar } " )
4294- # Add converter for the actual type used
4295- db_connection .clear_output_converters ()
4296- db_connection .add_output_converter (column_type , custom_string_converter )
4297-
4298- # Re-execute the query
4299- cursor .execute ("SELECT N'test string' AS test_col" )
4300- row = cursor .fetchone ()
4301- assert row [0 ].startswith ("CONVERTED:" ), "Output converter not applied"
4283+ # The converter should be applied based on the SQL type code
4284+ assert row [0 ].startswith ("CONVERTED:" ), "Output converter not applied"
43024285
43034286 # Clean up
43044287 db_connection .clear_output_converters ()
@@ -4385,26 +4368,23 @@ def test_multiple_output_converters(db_connection):
43854368 """Test that multiple output converters can work together"""
43864369 cursor = db_connection .cursor ()
43874370
4388- # Execute a query to get the actual type codes used
4389- cursor .execute ("SELECT CAST(42 AS INT) as int_col, N'test' as str_col" )
4390- int_type = cursor .description [0 ][1 ] # Type code for integer column
4391- str_type = cursor .description [1 ][1 ] # Type code for string column
4371+ # Use SQL type constants directly
4372+ sql_integer = ConstantsDDBC .SQL_INTEGER .value # SQL type code for INT
4373+ sql_wvarchar = ConstantsDDBC .SQL_WVARCHAR .value # SQL type code for NVARCHAR
43924374
43934375 # Add converter for string type
4394- db_connection .add_output_converter (str_type , custom_string_converter )
4376+ db_connection .add_output_converter (sql_wvarchar , custom_string_converter )
43954377
43964378 # Add converter for integer type
43974379 def int_converter (value ):
43984380 if value is None :
43994381 return None
4400- # Convert from bytes to int and multiply by 2
4401- if isinstance (value , bytes ):
4402- return int .from_bytes (value , byteorder = "little" ) * 2
4403- elif isinstance (value , int ):
4382+ # Integers are already Python ints, so just multiply by 2
4383+ if isinstance (value , int ):
44044384 return value * 2
44054385 return value
44064386
4407- db_connection .add_output_converter (int_type , int_converter )
4387+ db_connection .add_output_converter (sql_integer , int_converter )
44084388
44094389 # Test query with both types
44104390 cursor .execute ("SELECT CAST(42 AS INT) as int_col, N'test' as str_col" )
@@ -4811,32 +4791,15 @@ def test_converter_integration(db_connection):
48114791 cursor = db_connection .cursor ()
48124792 sql_wvarchar = ConstantsDDBC .SQL_WVARCHAR .value
48134793
4814- # Test with string converter
4794+ # Register converter for SQL_WVARCHAR type
48154795 db_connection .add_output_converter (sql_wvarchar , custom_string_converter )
48164796
48174797 # Test a simple string query
48184798 cursor .execute ("SELECT N'test string' AS test_col" )
48194799 row = cursor .fetchone ()
48204800
4821- # Check if the type matches what we expect for SQL_WVARCHAR
4822- # For Cursor.description, the second element is the type code
4823- column_type = cursor .description [0 ][1 ]
4824-
4825- # If the cursor description has SQL_WVARCHAR as the type code,
4826- # then our converter should be applied
4827- if column_type == sql_wvarchar :
4828- assert row [0 ].startswith ("CONVERTED:" ), "Output converter not applied"
4829- else :
4830- # If the type code is different, adjust the test or the converter
4831- print (f"Column type is { column_type } , not { sql_wvarchar } " )
4832- # Add converter for the actual type used
4833- db_connection .clear_output_converters ()
4834- db_connection .add_output_converter (column_type , custom_string_converter )
4835-
4836- # Re-execute the query
4837- cursor .execute ("SELECT N'test string' AS test_col" )
4838- row = cursor .fetchone ()
4839- assert row [0 ].startswith ("CONVERTED:" ), "Output converter not applied"
4801+ # The converter should be applied based on the SQL type code
4802+ assert row [0 ].startswith ("CONVERTED:" ), "Output converter not applied"
48404803
48414804 # Clean up
48424805 db_connection .clear_output_converters ()
@@ -4923,26 +4886,23 @@ def test_multiple_output_converters(db_connection):
49234886 """Test that multiple output converters can work together"""
49244887 cursor = db_connection .cursor ()
49254888
4926- # Execute a query to get the actual type codes used
4927- cursor .execute ("SELECT CAST(42 AS INT) as int_col, N'test' as str_col" )
4928- int_type = cursor .description [0 ][1 ] # Type code for integer column
4929- str_type = cursor .description [1 ][1 ] # Type code for string column
4889+ # Use SQL type constants directly
4890+ sql_integer = ConstantsDDBC .SQL_INTEGER .value # SQL type code for INT
4891+ sql_wvarchar = ConstantsDDBC .SQL_WVARCHAR .value # SQL type code for NVARCHAR
49304892
49314893 # Add converter for string type
4932- db_connection .add_output_converter (str_type , custom_string_converter )
4894+ db_connection .add_output_converter (sql_wvarchar , custom_string_converter )
49334895
49344896 # Add converter for integer type
49354897 def int_converter (value ):
49364898 if value is None :
49374899 return None
4938- # Convert from bytes to int and multiply by 2
4939- if isinstance (value , bytes ):
4940- return int .from_bytes (value , byteorder = "little" ) * 2
4941- elif isinstance (value , int ):
4900+ # Integers are already Python ints, so just multiply by 2
4901+ if isinstance (value , int ):
49424902 return value * 2
49434903 return value
49444904
4945- db_connection .add_output_converter (int_type , int_converter )
4905+ db_connection .add_output_converter (sql_integer , int_converter )
49464906
49474907 # Test query with both types
49484908 cursor .execute ("SELECT CAST(42 AS INT) as int_col, N'test' as str_col" )
0 commit comments