@@ -94,4 +94,81 @@ def test_variant_data_retrieval(self, variant_table_fixture):
9494 # Parsing to verify it's valid JSON array
9595 parsed_array = json .loads (json_array )
9696 assert isinstance (parsed_array , list )
97- assert parsed_array == [1 , 2 , 3 , 4 ]
97+ assert parsed_array == [1 , 2 , 3 , 4 ]
98+
99+ @pytest .mark .parametrize (
100+ "test_id, json_value, expected_result, description" ,
101+ [
102+ # Primitive types
103+ (1 , '"string value"' , "string value" , "String value" ),
104+ (2 , '42' , 42 , "Integer value" ),
105+ (3 , '3.14159' , 3.14159 , "Float value" ),
106+ (4 , 'true' , True , "Boolean true" ),
107+ (5 , 'false' , False , "Boolean false" ),
108+ (6 , 'null' , None , "Null value" ),
109+
110+ # Complex types
111+ (7 , '["a", "b", "c"]' , ["a" , "b" , "c" ], "String array" ),
112+ (8 , '[1, 2, 3]' , [1 , 2 , 3 ], "Integer array" ),
113+ (9 , '{"key1": "value1", "key2": "value2"}' , {"key1" : "value1" , "key2" : "value2" }, "Simple object" ),
114+
115+ # Nested structures
116+ (10 , '{"nested": {"a": 1, "b": 2}}' , {"nested" : {"a" : 1 , "b" : 2 }}, "Nested object" ),
117+ (11 , '[["nested"], ["arrays"]]' , [["nested" ], ["arrays" ]], "Nested arrays" ),
118+ (12 , '{"array": [1, 2, 3], "object": {"a": "b"}}' , {"array" : [1 , 2 , 3 ], "object" : {"a" : "b" }}, "Mixed nested structures" ),
119+
120+ # Mixed types
121+ (13 , '[1, "string", true, null, {"key": "value"}]' , [1 , "string" , True , None , {"key" : "value" }], "Array with mixed types" ),
122+
123+ # Special cases
124+ (14 , '{}' , {}, "Empty object" ),
125+ (15 , '[]' , [], "Empty array" ),
126+ (16 , '{"unicode": "✓ öäü 😀"}' , {"unicode" : "✓ öäü 😀" }, "Unicode characters" ),
127+ (17 , '{"large_number": 9223372036854775807}' , {"large_number" : 9223372036854775807 }, "Large integer" ),
128+
129+ # Deeply nested structure
130+ (18 , '{"level1": {"level2": {"level3": {"level4": {"level5": "deep value"}}}}}' ,
131+ {"level1" : {"level2" : {"level3" : {"level4" : {"level5" : "deep value" }}}}}, "Deeply nested structure" ),
132+
133+ # Date and time types
134+ (19 , '"2023-01-01"' , "2023-01-01" , "Date as string (ISO format)" ),
135+ (20 , '"12:34:56"' , "12:34:56" , "Time as string (ISO format)" ),
136+ (21 , '"2023-01-01T12:34:56"' , "2023-01-01T12:34:56" , "Datetime as string (ISO format)" ),
137+ (22 , '"2023-01-01T12:34:56Z"' , "2023-01-01T12:34:56Z" , "Datetime with Z timezone (UTC)" ),
138+ (23 , '"2023-01-01T12:34:56+02:00"' , "2023-01-01T12:34:56+02:00" , "Datetime with timezone offset" ),
139+ (24 , '{"date": "2023-01-01", "time": "12:34:56"}' , {"date" : "2023-01-01" , "time" : "12:34:56" }, "Object with date and time fields" ),
140+ (25 , '["2023-01-01", "2023-02-02", "2023-03-03"]' , ["2023-01-01" , "2023-02-02" , "2023-03-03" ], "Array of dates" ),
141+ (26 , '{"events": [{"timestamp": "2023-01-01T12:34:56Z", "name": "event1"}, {"timestamp": "2023-02-02T12:34:56Z", "name": "event2"}]}' ,
142+ {"events" : [{"timestamp" : "2023-01-01T12:34:56Z" , "name" : "event1" }, {"timestamp" : "2023-02-02T12:34:56Z" , "name" : "event2" }]},
143+ "Complex object with timestamps" ),
144+ ]
145+ )
146+ def test_variant_data_types (self , test_id , json_value , expected_result , description ):
147+ """Test that different data types can be stored and retrieved from VARIANT columns"""
148+ # Use a unique table name for each test case to avoid conflicts in parallel execution
149+ table_name = f"pysql_test_variant_type_{ test_id } "
150+
151+ with self .cursor () as cursor :
152+ try :
153+ # Drop the table if it exists
154+ cursor .execute (f"DROP TABLE IF EXISTS { table_name } " )
155+
156+ # Create a new table with a variant column
157+ cursor .execute (f"CREATE TABLE { table_name } (id INTEGER, variant_col VARIANT)" )
158+
159+ # Insert the test value
160+ cursor .execute (f"INSERT INTO { table_name } VALUES (1, PARSE_JSON('{ json_value } '))" )
161+
162+ # Query the data
163+ cursor .execute (f"SELECT variant_col FROM { table_name } " )
164+ result = cursor .fetchone ()
165+
166+ # Parse the JSON result
167+ parsed_json = json .loads (result [0 ])
168+
169+ # Verify the result matches the expected value
170+ assert parsed_json == expected_result , f"Failed for test case { description } "
171+
172+ finally :
173+ # Clean up
174+ cursor .execute (f"DROP TABLE IF EXISTS { table_name } " )
0 commit comments