Skip to content
Merged
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
14 changes: 13 additions & 1 deletion python/adbc_driver_manager/adbc_driver_manager/_lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,26 @@ cdef class AdbcConnection(_AdbcHandle):
column_name = _to_bytes(column_name, "column_name")
c_column_name = column_name

cdef c_vector[const char*] c_table_types
cdef const char** c_table_types_ptr = NULL
if table_types:
# Keep the encoded bytes alive while c_table_types points into their buffers
table_types = [
_to_bytes(table_type, "table_types") for table_type in table_types
]
for table_type in table_types:
c_table_types.push_back(table_type)
c_table_types.push_back(<const char*> NULL)
c_table_types_ptr = c_table_types.data()

with nogil:
status = AdbcConnectionGetObjects(
&self.connection,
c_depth,
c_catalog,
c_db_schema,
c_table_name,
NULL, # TODO: support table_types
c_table_types_ptr,
c_column_name,
&stream.stream,
&c_error)
Expand Down
24 changes: 24 additions & 0 deletions python/adbc_driver_manager/tests/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ def test_get_objects(sqlite) -> None:
assert tables[0]["table_constraints"] == []


@pytest.mark.sqlite
def test_get_objects_table_types_filter(sqlite) -> None:
with sqlite.cursor() as cur:
cur.execute("CREATE TABLE base (ints)")
cur.execute("CREATE VIEW derived AS SELECT * FROM base")

def table_names(table_types_filter):
metadata = (
sqlite.adbc_get_objects(table_types_filter=table_types_filter)
.read_all()
.to_pylist()
)
return sorted(
table["table_name"]
for catalog in metadata
for schema in catalog["catalog_db_schemas"]
for table in schema["db_schema_tables"]
)

assert table_names(["table"]) == ["base"]
assert table_names(["view"]) == ["derived"]
assert table_names(["table", "view"]) == ["base", "derived"]


@pytest.mark.sqlite
def test_get_table_schema(sqlite) -> None:
with sqlite.cursor() as cur:
Expand Down
Loading