From bba41c82c5623949f0c0b776c2caf9a42fed4bd1 Mon Sep 17 00:00:00 2001 From: "Y." Date: Wed, 10 Sep 2025 12:16:45 +0200 Subject: [PATCH] Add support for latest DuckDB (#22) --- CMakeLists.txt | 4 ++++ src/include/utils/helpers.hpp | 8 ++++++++ src/watcher.cpp | 17 +++++++++++------ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d681500..e7d96b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,10 @@ set(EXTENSION_SOURCES src/utils/serialization.cpp src/watcher.cpp) +add_definitions(-DDUCKDB_MAJOR_VERSION=${DUCKDB_MAJOR_VERSION}) +add_definitions(-DDUCKDB_MINOR_VERSION=${DUCKDB_MINOR_VERSION}) +add_definitions(-DDUCKDB_PATCH_VERSION=${DUCKDB_PATCH_VERSION}) + find_package(Git) if(NOT Git_FOUND) message(FATAL_ERROR "Git not found, unable to determine git sha") diff --git a/src/include/utils/helpers.hpp b/src/include/utils/helpers.hpp index 7e8c649..744d71d 100644 --- a/src/include/utils/helpers.hpp +++ b/src/include/utils/helpers.hpp @@ -6,6 +6,14 @@ #endif #include +// TODO we cannot run these checks because they are not defined for DuckDB < 1.4.x +// #ifndef DUCKDB_MAJOR_VERSION +// #error "DUCKDB_MAJOR_VERSION is not defined" +// ... +#define DUCKDB_VERSION_AT_MOST(major, minor, patch) \ + (DUCKDB_MAJOR_VERSION < (major) || (DUCKDB_MAJOR_VERSION == (major) && DUCKDB_MINOR_VERSION < (minor)) || \ + (DUCKDB_MAJOR_VERSION == (major) && DUCKDB_MINOR_VERSION == (minor) && DUCKDB_PATCH_VERSION <= (patch))) + namespace duckdb { typedef std::string (*simple_tf_t)(ClientContext &); diff --git a/src/watcher.cpp b/src/watcher.cpp index 1fa53c0..dd354b2 100644 --- a/src/watcher.cpp +++ b/src/watcher.cpp @@ -2,6 +2,7 @@ #include +#include "utils/helpers.hpp" #include "utils/md_helpers.hpp" #include "http_server.hpp" #include "settings.hpp" @@ -23,19 +24,23 @@ bool WasCatalogUpdated(DatabaseInstance &db, Connection &connection, // Check currently attached databases for (const auto &db_ref : databases) { - auto &db = db_ref.get(); - if (db.IsTemporary()) { +#if DUCKDB_VERSION_AT_MOST(1, 3, 2) + auto &db_instance = db_ref.get(); +#else + auto &db_instance = *db_ref; +#endif + if (db_instance.IsTemporary()) { continue; // ignore temp databases } - db_oids.insert(db.oid); - auto &catalog = db.GetCatalog(); + db_oids.insert(db_instance.oid); + auto &catalog = db_instance.GetCatalog(); auto current_version = catalog.GetCatalogVersion(context); - auto last_version_it = last_state.db_to_catalog_version.find(db.oid); + auto last_version_it = last_state.db_to_catalog_version.find(db_instance.oid); if (last_version_it == last_state.db_to_catalog_version.end() // first time || !(last_version_it->second == current_version)) { // updated has_change = true; - last_state.db_to_catalog_version[db.oid] = current_version; + last_state.db_to_catalog_version[db_instance.oid] = current_version; } }