Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ public final void mockType(String sqlTypesName) throws SQLException {
Mockito.when(mockResultSet.getObject(1, LocalDateTime.class)).thenReturn(localDateTime);
Mockito.when(mockResultSet.getTimestamp(1)).thenReturn(timestamp);
break;
case Types.ARRAY:
// ExplicitTypeMapper remaps ARRAY to VARCHAR (toString fallback).
// Mock getString() so the Arrow adapter can read the degraded value.
object = "{1,2,3}";
Mockito.when(mockResultSet.getString(1)).thenReturn((String) object);
break;
default:
object = "DummyObject";
break;
Expand Down
18 changes: 18 additions & 0 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,24 @@ def test_execute_timestamptz_roundtrip_param_binding(self):
self.assertEqual(result[1], datetime(2024, 6, 15, 10, 30, 0, tzinfo=timezone.utc))
self.assertIsNotNone(result[1].tzinfo)

def test_array_column_read(self):
"""Verify ARRAY columns are readable as strings via ExplicitTypeMapper
VARCHAR fallback. Regression test for legacy issue baztian/jaydebeapi#159."""
with self.conn.cursor() as cursor:
cursor.execute("CREATE TABLE test_array_type (id INT, data INTEGER ARRAY)")
try:
cursor.execute(
"INSERT INTO test_array_type (id, data) VALUES (1, ARRAY[1,2,3])"
)
cursor.execute("SELECT data FROM test_array_type WHERE id = 1")
result = cursor.fetchone()
# Verify data is readable (degraded VARCHAR fallback — toString representation)
self.assertIsInstance(result[0], str)
# Verify cursor.description reports ARRAY type code
self.assertIs(cursor.description[0][1], jaydebeapiarrow.ARRAY)
finally:
cursor.execute("DROP TABLE test_array_type")


class MySQLTest(IntegrationTestBase, unittest.TestCase):

Expand Down
13 changes: 12 additions & 1 deletion test/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def tearDown(self):
self.conn.close()

# JDBC types not supported by the Arrow data path (no Arrow type mapping)
_ARROW_UNSUPPORTED_TYPES = {'OTHER', 'NCLOB', 'SQLXML', 'ROWID', 'ARRAY',
_ARROW_UNSUPPORTED_TYPES = {'OTHER', 'NCLOB', 'SQLXML', 'ROWID',
'TIME_WITH_TIMEZONE', 'TIMESTAMP_WITH_TIMEZONE'}

def test_all_db_api_type_objects_have_valid_mapping(self):
Expand Down Expand Up @@ -756,6 +756,17 @@ def test_binary_empty(self):
result = cursor.fetchone()
self.assertEqual(result[0], b'')

# --- ARRAY type tests (legacy issue #159) ---

def test_array_column_returns_string_via_varchar_fallback(self):
"""ARRAY columns are degraded to VARCHAR by ExplicitTypeMapper and
returned as Python strings (toString representation)."""
self.conn.jconn.mockType("ARRAY")
with self.conn.cursor() as cursor:
cursor.execute("dummy stmt")
result = cursor.fetchone()
self.assertIsInstance(result[0], str)

# --- DBAPITypeObject mapping tests ---

def test_description_returns_column_label_not_name(self):
Expand Down
Loading