@@ -358,6 +358,112 @@ def test_insert_time_column_preserves_microseconds(cursor, db_connection):
358358 db_connection.commit()
359359
360360
361+ def test_time_column_with_null(cursor, db_connection):
362+ """Test TIME(2) column with NULL values — exercises NULL branch in SQLGetData path."""
363+ try:
364+ drop_table_if_exists(cursor, "#pytest_time_null")
365+ cursor.execute("CREATE TABLE #pytest_time_null (id INT, time_column TIME(2))")
366+ db_connection.commit()
367+ cursor.execute("INSERT INTO #pytest_time_null VALUES (1, '10:30:00.00')")
368+ cursor.execute("INSERT INTO #pytest_time_null VALUES (2, NULL)")
369+ cursor.execute("INSERT INTO #pytest_time_null VALUES (3, '23:59:59.99')")
370+ db_connection.commit()
371+
372+ cursor.execute("SELECT time_column FROM #pytest_time_null ORDER BY id")
373+ rows = cursor.fetchall()
374+ assert len(rows) == 3
375+ assert rows[0][0] == time(10, 30, 0)
376+ assert rows[1][0] is None, "NULL TIME should be returned as None"
377+ assert rows[2][0] == time(23, 59, 59, 990000)
378+ except Exception as e:
379+ pytest.fail(f"TIME with NULL test failed: {e}")
380+ finally:
381+ drop_table_if_exists(cursor, "#pytest_time_null")
382+ db_connection.commit()
383+
384+
385+ def test_time_column_no_fractional_seconds(cursor, db_connection):
386+ """Test TIME(0) column without fractional seconds — exercises dotPos==npos branch."""
387+ try:
388+ drop_table_if_exists(cursor, "#pytest_time_nofrac")
389+ cursor.execute("CREATE TABLE #pytest_time_nofrac (time_column TIME(0))")
390+ db_connection.commit()
391+ cursor.execute(
392+ "INSERT INTO #pytest_time_nofrac (time_column) VALUES (?)", [time(8, 15, 30)]
393+ )
394+ db_connection.commit()
395+
396+ cursor.execute("SELECT time_column FROM #pytest_time_nofrac")
397+ row = cursor.fetchone()
398+ assert row is not None
399+ assert row[0] == time(8, 15, 30)
400+ except Exception as e:
401+ pytest.fail(f"TIME(0) no fractional seconds test failed: {e}")
402+ finally:
403+ drop_table_if_exists(cursor, "#pytest_time_nofrac")
404+ db_connection.commit()
405+
406+
407+ def test_time_column_batch_fetch(cursor, db_connection):
408+ """Test fetching multiple TIME(6) rows via fetchall — exercises batch/column-bound path."""
409+ try:
410+ drop_table_if_exists(cursor, "#pytest_time_batch")
411+ cursor.execute("CREATE TABLE #pytest_time_batch (id INT, time_column TIME(6))")
412+ db_connection.commit()
413+
414+ expected = [
415+ time(0, 0, 0),
416+ time(6, 30, 0, 123456),
417+ time(12, 0, 0),
418+ time(18, 45, 59, 999999),
419+ time(23, 59, 59, 0),
420+ ]
421+ for i, t in enumerate(expected):
422+ cursor.execute("INSERT INTO #pytest_time_batch (id, time_column) VALUES (?, ?)", [i, t])
423+ db_connection.commit()
424+
425+ cursor.execute("SELECT time_column FROM #pytest_time_batch ORDER BY id")
426+ rows = cursor.fetchall()
427+ assert len(rows) == len(expected)
428+ for i, row in enumerate(rows):
429+ assert row[0] == expected[i], f"Row {i}: expected {expected[i]}, got {row[0]}"
430+ except Exception as e:
431+ pytest.fail(f"TIME batch fetch test failed: {e}")
432+ finally:
433+ drop_table_if_exists(cursor, "#pytest_time_batch")
434+ db_connection.commit()
435+
436+
437+ def test_time_executemany(cursor, db_connection):
438+ """Test executemany with TIME column — exercises cursor.py time→isoformat conversion."""
439+ try:
440+ drop_table_if_exists(cursor, "#pytest_time_execmany")
441+ cursor.execute("CREATE TABLE #pytest_time_execmany (id INT, time_column TIME(6))")
442+ db_connection.commit()
443+
444+ values = [
445+ (1, time(9, 0, 0)),
446+ (2, time(14, 30, 15, 234567)),
447+ (3, time(23, 59, 59, 999999)),
448+ ]
449+ cursor.executemany(
450+ "INSERT INTO #pytest_time_execmany (id, time_column) VALUES (?, ?)", values
451+ )
452+ db_connection.commit()
453+
454+ cursor.execute("SELECT id, time_column FROM #pytest_time_execmany ORDER BY id")
455+ rows = cursor.fetchall()
456+ assert len(rows) == 3
457+ for (exp_id, exp_time), row in zip(values, rows):
458+ assert row[0] == exp_id
459+ assert row[1] == exp_time, f"id {exp_id}: expected {exp_time}, got {row[1]}"
460+ except Exception as e:
461+ pytest.fail(f"TIME executemany test failed: {e}")
462+ finally:
463+ drop_table_if_exists(cursor, "#pytest_time_execmany")
464+ db_connection.commit()
465+
466+
361467def test_insert_datetime_column(cursor, db_connection):
362468 """Test inserting data into the datetime_column"""
363469 try:
0 commit comments