@@ -6921,6 +6921,102 @@ def test_uuid_insert_with_none(cursor, db_connection):
69216921 cursor .execute (f"DROP TABLE IF EXISTS { table_name } " )
69226922 db_connection .commit ()
69236923
6924+
6925+ def test_uuid_insert_and_select_none (cursor , db_connection ):
6926+ """Test inserting and retrieving None in a nullable UUID column."""
6927+ table_name = "#pytest_uuid_nullable"
6928+ try :
6929+ cursor .execute (f"DROP TABLE IF EXISTS { table_name } " )
6930+ cursor .execute (f"""
6931+ CREATE TABLE { table_name } (
6932+ id UNIQUEIDENTIFIER,
6933+ name NVARCHAR(50)
6934+ )
6935+ """ )
6936+ db_connection .commit ()
6937+
6938+ # Insert a row with None for the UUID
6939+ cursor .execute (f"INSERT INTO { table_name } (id, name) VALUES (?, ?)" , [None , "Bob" ])
6940+ db_connection .commit ()
6941+
6942+ # Fetch the row
6943+ cursor .execute (f"SELECT id, name FROM { table_name } " )
6944+ retrieved_uuid , retrieved_name = cursor .fetchone ()
6945+
6946+ # Assert that the retrieved UUID is None
6947+ assert retrieved_uuid is None , f"Expected None, got { type (retrieved_uuid )} "
6948+ assert retrieved_name == "Bob"
6949+ finally :
6950+ cursor .execute (f"DROP TABLE IF EXISTS { table_name } " )
6951+ db_connection .commit ()
6952+
6953+
6954+ def test_insert_multiple_uuids (cursor , db_connection ):
6955+ """Test inserting multiple UUIDs and verifying retrieval."""
6956+ table_name = "#pytest_uuid_multiple"
6957+ try :
6958+ cursor .execute (f"DROP TABLE IF EXISTS { table_name } " )
6959+ cursor .execute (f"""
6960+ CREATE TABLE { table_name } (
6961+ id UNIQUEIDENTIFIER PRIMARY KEY,
6962+ description NVARCHAR(50)
6963+ )
6964+ """ )
6965+ db_connection .commit ()
6966+
6967+ uuids_to_insert = {f"Item { i } " : uuid .uuid4 () for i in range (5 )}
6968+
6969+ # Insert UUIDs and descriptions directly
6970+ for desc , uid in uuids_to_insert .items ():
6971+ cursor .execute (f"INSERT INTO { table_name } (id, description) VALUES (?, ?)" , [uid , desc ])
6972+ db_connection .commit ()
6973+
6974+ # Fetch all data
6975+ cursor .execute (f"SELECT id, description FROM { table_name } " )
6976+ rows = cursor .fetchall ()
6977+
6978+ # Verify each fetched row against the original data
6979+ assert len (rows ) == len (uuids_to_insert ), "Number of fetched rows does not match."
6980+
6981+ for retrieved_uuid , retrieved_desc in rows :
6982+ # Assert type is correct
6983+ assert isinstance (retrieved_uuid , uuid .UUID ), f"Expected uuid.UUID, got { type (retrieved_uuid )} "
6984+
6985+ # Use the description to look up the original UUID
6986+ expected_uuid = uuids_to_insert .get (retrieved_desc )
6987+
6988+ assert expected_uuid is not None , f"Retrieved description '{ retrieved_desc } ' was not in the original data."
6989+ assert retrieved_uuid == expected_uuid , f"UUID mismatch for '{ retrieved_desc } ': expected { expected_uuid } , got { retrieved_uuid } "
6990+ finally :
6991+ cursor .execute (f"DROP TABLE IF EXISTS { table_name } " )
6992+ db_connection .commit ()
6993+
6994+
6995+ def test_uuid_insert_with_none (cursor , db_connection ):
6996+ """Test inserting None into a UUID column results in a NULL value."""
6997+ table_name = "#pytest_uuid_none"
6998+ try :
6999+ cursor .execute (f"DROP TABLE IF EXISTS { table_name } " )
7000+ cursor .execute (f"""
7001+ CREATE TABLE { table_name } (
7002+ id UNIQUEIDENTIFIER,
7003+ name NVARCHAR(50)
7004+ )
7005+ """ )
7006+ db_connection .commit ()
7007+
7008+ cursor .execute (f"INSERT INTO { table_name } (id, name) VALUES (?, ?)" , [None , "Bob" ])
7009+ db_connection .commit ()
7010+
7011+ cursor .execute (f"SELECT id, name FROM { table_name } " )
7012+ retrieved_uuid , retrieved_name = cursor .fetchone ()
7013+
7014+ assert retrieved_uuid is None , f"Expected NULL UUID, got { retrieved_uuid } "
7015+ assert retrieved_name == "Bob"
7016+ finally :
7017+ cursor .execute (f"DROP TABLE IF EXISTS { table_name } " )
7018+ db_connection .commit ()
7019+
69247020def test_close (db_connection ):
69257021 """Test closing the cursor"""
69267022 try :
0 commit comments