From 470241f7cb39beb9b3f880aa542321e88ecd7318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Fri, 24 Oct 2025 20:23:24 +0200 Subject: [PATCH] fix(gdal): fix build with recent gdal version --- src/spatial/modules/gdal/gdal_module.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/spatial/modules/gdal/gdal_module.cpp b/src/spatial/modules/gdal/gdal_module.cpp index f24f0498..b0c1ea96 100644 --- a/src/spatial/modules/gdal/gdal_module.cpp +++ b/src/spatial/modules/gdal/gdal_module.cpp @@ -41,10 +41,11 @@ class DuckDBFileHandle final : public VSIVirtualHandle { private: unique_ptr file_handle; bool is_eof; + bool has_error; public: explicit DuckDBFileHandle(unique_ptr file_handle_p) - : file_handle(std::move(file_handle_p)), is_eof(false) { + : file_handle(std::move(file_handle_p)), is_eof(false), has_error(false) { } vsi_l_offset Tell() override { @@ -88,16 +89,19 @@ class DuckDBFileHandle final : public VSIVirtualHandle { pBuffer = static_cast(pBuffer) + read_bytes; } } catch (...) { + has_error = true; } if (remaining_bytes != 0) { if (file_handle->SeekPosition() == file_handle->GetFileSize()) { // Is at EOF! is_eof = true; + } else { + // else, error! + // unfortunately, this version of GDAL cant distinguish between errors and reading less bytes + // its avaiable in 3.9.2, but we're stuck on 3.8.5 for now. + has_error = true; } - // else, error! - // unfortunately, this version of GDAL cant distinguish between errors and reading less bytes - // its avaiable in 3.9.2, but we're stuck on 3.8.5 for now. } return nCount - (remaining_bytes / nSize); @@ -112,6 +116,7 @@ class DuckDBFileHandle final : public VSIVirtualHandle { try { written_bytes = file_handle->Write(const_cast(pBuffer), nSize * nCount); } catch (...) { + has_error = true; } // Return the number of items written return static_cast(written_bytes / nSize); @@ -130,6 +135,15 @@ class DuckDBFileHandle final : public VSIVirtualHandle { return 0; } + void ClearErr() override { + has_error = false; + is_eof = false; + } + + int Error() override { + return has_error ? TRUE : FALSE; + } + // int ReadMultiRange(int nRanges, void **ppData, const vsi_l_offset *panOffsets, const size_t *panSizes) override; // void AdviseRead(int nRanges, const vsi_l_offset *panOffsets, const size_t *panSizes) override; // VSIRangeStatus GetRangeStatus(vsi_l_offset nOffset, vsi_l_offset nLength) override; @@ -2030,7 +2044,7 @@ void RegisterGDALModule(ExtensionLoader &loader) { static std::once_flag loaded; std::call_once(loaded, [&]() { // Register all embedded drivers (dont go looking for plugins) - OGRRegisterAllInternal(); + OGRRegisterAll(); // Set GDAL error handler CPLSetErrorHandler([](CPLErr e, int code, const char *raw_msg) {