Skip to content

ADBC: prevent driver to open an empty GeoPackage file (as the GPKG driver itself doesn't allow it) #12117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
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
21 changes: 21 additions & 0 deletions autotest/ogr/ogr_adbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,27 @@ def test_ogr_adbc_sqlite3():
###############################################################################


@pytest.mark.require_driver("GPKG")
def test_ogr_adbc_create_empty_gpkg_and_open(tmp_path):

if not _has_sqlite_driver():
pytest.skip("adbc_driver_sqlite missing")

filename = tmp_path / "out.gpkg"
ogr.GetDriverByName("GPKG").CreateDataSource(filename)
with pytest.raises(Exception):
ogr.Open(filename)

with gdal.OpenEx(filename, allowed_drivers=["ADBC"]) as ds:
assert ds.GetLayerCount() == 6

with ogr.Open("ADBC:" + str(filename)) as ds:
assert ds.GetLayerCount() == 6


###############################################################################


def test_ogr_adbc_sql_open_option():

if not _has_sqlite_driver():
Expand Down
8 changes: 7 additions & 1 deletion ogr/ogrsf_frmts/adbc/ogradbcdrivercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ int OGRADBCDriverIdentify(GDALOpenInfo *poOpenInfo)
{
return STARTS_WITH(poOpenInfo->pszFilename, "ADBC:") ||
((OGRADBCDriverIsDuckDB(poOpenInfo) ||
OGRADBCDriverIsSQLite3(poOpenInfo) ||
(OGRADBCDriverIsSQLite3(poOpenInfo) &&
((!poOpenInfo->IsExtensionEqualToCI("gpkg") &&
(GDALGetDriverByName("SQLite") == nullptr ||
poOpenInfo->IsSingleAllowedDriver("ADBC"))) ||
(poOpenInfo->IsExtensionEqualToCI("gpkg") &&
(GDALGetDriverByName("GPKG") == nullptr ||
poOpenInfo->IsSingleAllowedDriver("ADBC"))))) ||
OGRADBCDriverIsParquet(poOpenInfo))
#ifndef OGR_ADBC_HAS_DRIVER_MANAGER
&& GDALGetAdbcLoadDriverOverride() != nullptr
Expand Down
Loading