From 914c31e95aad08b76746ba4d577bf1f5621ad249 Mon Sep 17 00:00:00 2001 From: Popa Adrian Marius Date: Wed, 1 Jul 2026 18:39:56 +0300 Subject: [PATCH 1/5] =?UTF-8?q?add=20DatabasePropertyManager=C2=A0=20for?= =?UTF-8?q?=20database=20shutdown/startup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fb-cpp/DatabasePropertyManager.cpp | 59 ++++++++++ src/fb-cpp/DatabasePropertyManager.h | 144 +++++++++++++++++++++++++ src/fb-cpp/fb-cpp.h | 1 + 3 files changed, 204 insertions(+) create mode 100644 src/fb-cpp/DatabasePropertyManager.cpp create mode 100644 src/fb-cpp/DatabasePropertyManager.h diff --git a/src/fb-cpp/DatabasePropertyManager.cpp b/src/fb-cpp/DatabasePropertyManager.cpp new file mode 100644 index 0000000..0aa9114 --- /dev/null +++ b/src/fb-cpp/DatabasePropertyManager.cpp @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) 2026 Adriano dos Santos Fernandes + * ... + */ + +#include "DatabasePropertyManager.h" +#include "Client.h" + +using namespace fbcpp; +using namespace fbcpp::impl; + +void DatabasePropertyManager::shutdown(const ShutdownOptions& options) +{ + StatusWrapper statusWrapper{getClient()}; + auto builder = + fbUnique(getClient().getUtil()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::SPB_START, nullptr, 0)); + + builder->insertTag(&statusWrapper, isc_action_svc_properties); + builder->insertString(&statusWrapper, isc_spb_dbname, options.getDatabase().c_str()); + + switch (options.getMode()) + { + case ShutdownMode::DENY_TRANSACTIONS: + builder->insertInt(&statusWrapper, isc_spb_prp_deny_new_transactions, options.getTimeout()); + break; + case ShutdownMode::DENY_ATTACHMENTS: + builder->insertInt(&statusWrapper, isc_spb_prp_deny_new_attachments, options.getTimeout()); + break; + case ShutdownMode::FORCED: + default: + builder->insertInt(&statusWrapper, isc_spb_prp_force_shutdown, options.getTimeout()); + break; + } + + const auto buffer = builder->getBuffer(&statusWrapper); + const auto length = builder->getBufferLength(&statusWrapper); + + startAction(std::vector(buffer, buffer + length)); + waitForCompletion(); +} + +void DatabasePropertyManager::startup(const std::string& database) +{ + StatusWrapper statusWrapper{getClient()}; + auto builder = + fbUnique(getClient().getUtil()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::SPB_START, nullptr, 0)); + + builder->insertTag(&statusWrapper, isc_action_svc_properties); + builder->insertString(&statusWrapper, isc_spb_dbname, database.c_str()); + builder->insertInt(&statusWrapper, isc_spb_options, isc_spb_prp_db_online); + + const auto buffer = builder->getBuffer(&statusWrapper); + const auto length = builder->getBufferLength(&statusWrapper); + + startAction(std::vector(buffer, buffer + length)); + waitForCompletion(); +} diff --git a/src/fb-cpp/DatabasePropertyManager.h b/src/fb-cpp/DatabasePropertyManager.h new file mode 100644 index 0000000..c1314de --- /dev/null +++ b/src/fb-cpp/DatabasePropertyManager.h @@ -0,0 +1,144 @@ +/* + * MIT License + * + * Copyright (c) 2026 Adriano dos Santos Fernandes + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef FBCPP_DATABASE_PROPERTY_MANAGER_H +#define FBCPP_DATABASE_PROPERTY_MANAGER_H + +#include "ServiceManager.h" +#include + + +/// +/// fb-cpp namespace. +/// +namespace fbcpp +{ + /// + /// Shutdown mode for a Firebird database (Firebird 2.0+). + /// + enum class ShutdownMode + { + /// + /// Forced shutdown: disconnects all users immediately after the timeout. + /// + FORCED, + + /// + /// Deny new transactions: waits for existing transactions to finish. + /// + DENY_TRANSACTIONS, + + /// + /// Deny new attachments: waits for existing connections to finish. + /// + DENY_ATTACHMENTS + }; + + /// + /// Represents options used to shut down a Firebird database. + /// + class ShutdownOptions final + { + public: + /// + /// Returns the database path. + /// + const std::string& getDatabase() const + { + return database; + } + + /// + /// Sets the database path. + /// + ShutdownOptions& setDatabase(const std::string& value) + { + database = value; + return *this; + } + + /// + /// Returns the shutdown mode. + /// + ShutdownMode getMode() const + { + return mode; + } + + /// + /// Sets the shutdown mode. Defaults to ShutdownMode::FORCED. + /// + ShutdownOptions& setMode(ShutdownMode value) + { + mode = value; + return *this; + } + + /// + /// Returns the timeout in seconds. + /// + int getTimeout() const + { + return timeout; + } + + /// + /// Sets the timeout in seconds (0 = immediate). Defaults to 0. + /// + ShutdownOptions& setTimeout(int value) + { + timeout = value; + return *this; + } + + private: + std::string database; + ShutdownMode mode = ShutdownMode::FORCED; + int timeout = 0; + }; + + /// + /// Executes database property operations (shutdown, startup) through + /// the Firebird service manager. + /// + class DatabasePropertyManager final : public ServiceManager + { + public: + using ServiceManager::ServiceManager; + + public: + /// + /// Shuts down a database using the given options. + /// + void shutdown(const ShutdownOptions& options); + + /// + /// Brings a database back online (online = normal read/write access). + /// + void startup(const std::string& database); + }; +} // namespace fbcpp + + +#endif // FBCPP_DATABASE_PROPERTY_MANAGER_H diff --git a/src/fb-cpp/fb-cpp.h b/src/fb-cpp/fb-cpp.h index b3f8fc8..e4cfd26 100644 --- a/src/fb-cpp/fb-cpp.h +++ b/src/fb-cpp/fb-cpp.h @@ -37,5 +37,6 @@ #include "ServiceManager.h" #include "BackupManager.h" #include "DatabaseManager.h" +#include "DatabasePropertyManager.h" #endif // FBCPP_H From b92c725ac196191f8d063baf0b9b16097cbc18e4 Mon Sep 17 00:00:00 2001 From: Popa Adrian Marius Date: Tue, 7 Jul 2026 14:28:17 +0300 Subject: [PATCH 2/5] Support database shutdown and online properties in DatabaseManager --- src/fb-cpp/DatabaseManager.cpp | 52 +++++++++ src/fb-cpp/DatabaseManager.h | 119 ++++++++++++++++++++ src/fb-cpp/DatabasePropertyManager.cpp | 59 ---------- src/fb-cpp/DatabasePropertyManager.h | 144 ------------------------- src/fb-cpp/fb-cpp.h | 1 - src/test/DatabaseManager.cpp | 47 ++++++++ 6 files changed, 218 insertions(+), 204 deletions(-) delete mode 100644 src/fb-cpp/DatabasePropertyManager.cpp delete mode 100644 src/fb-cpp/DatabasePropertyManager.h diff --git a/src/fb-cpp/DatabaseManager.cpp b/src/fb-cpp/DatabaseManager.cpp index 24a8792..610db4e 100644 --- a/src/fb-cpp/DatabaseManager.cpp +++ b/src/fb-cpp/DatabaseManager.cpp @@ -25,6 +25,7 @@ #include "DatabaseManager.h" #include "Client.h" #include +#include using namespace fbcpp; using namespace fbcpp::impl; @@ -59,6 +60,57 @@ void DatabaseManager::setProperties(const DatabasePropertiesOptions& options) builder->insertBytes(&statusWrapper, isc_spb_prp_replica_mode, &modeVal, 1u); } + if (const auto shutdownState = options.getShutdownState()) + { + std::uint8_t stateVal = 0; + switch (*shutdownState) + { + case ShutdownState::NORMAL: + stateVal = isc_spb_prp_sm_normal; + break; + case ShutdownState::MULTI: + stateVal = isc_spb_prp_sm_multi; + break; + case ShutdownState::SINGLE: + stateVal = isc_spb_prp_sm_single; + break; + case ShutdownState::FULL: + stateVal = isc_spb_prp_sm_full; + break; + default: + assert(false); + break; + } + builder->insertBytes(&statusWrapper, isc_spb_prp_shutdown_mode, &stateVal, 1u); + } + + if (const auto shutdownMode = options.getShutdownMode()) + { + const auto timeout = options.getShutdownTimeout().value_or(0); + switch (*shutdownMode) + { + case ShutdownMode::DENY_TRANSACTIONS: + builder->insertInt(&statusWrapper, isc_spb_prp_deny_new_transactions, timeout); + break; + case ShutdownMode::DENY_ATTACHMENTS: + builder->insertInt(&statusWrapper, isc_spb_prp_deny_new_attachments, timeout); + break; + case ShutdownMode::FORCED: + default: + builder->insertInt(&statusWrapper, isc_spb_prp_force_shutdown, timeout); + break; + } + } + + if (const auto online = options.getOnline()) + { + if (*online) + { + std::uint8_t stateVal = isc_spb_prp_sm_normal; + builder->insertBytes(&statusWrapper, isc_spb_prp_online_mode, &stateVal, 1u); + } + } + const auto buffer = builder->getBuffer(&statusWrapper); const auto length = builder->getBufferLength(&statusWrapper); diff --git a/src/fb-cpp/DatabaseManager.h b/src/fb-cpp/DatabaseManager.h index 29173bb..377c2dd 100644 --- a/src/fb-cpp/DatabaseManager.h +++ b/src/fb-cpp/DatabaseManager.h @@ -36,6 +36,53 @@ /// namespace fbcpp { + /// + /// Shutdown state for a Firebird database. + /// + enum class ShutdownState + { + /// + /// Normal online state. + /// + NORMAL, + + /// + /// Multi-user shutdown. + /// + MULTI, + + /// + /// Single-user shutdown. + /// + SINGLE, + + /// + /// Full exclusive shutdown. + /// + FULL + }; + + /// + /// Shutdown mode for a Firebird database. + /// + enum class ShutdownMode + { + /// + /// Forced shutdown: disconnects all users immediately after the timeout. + /// + FORCED, + + /// + /// Deny new transactions: waits for existing transactions to finish. + /// + DENY_TRANSACTIONS, + + /// + /// Deny new attachments: waits for existing connections to finish. + /// + DENY_ATTACHMENTS + }; + /// /// Represents options used to configure database properties through the service manager. /// @@ -76,9 +123,81 @@ namespace fbcpp return *this; } + /// + /// Returns the shutdown state. + /// + const std::optional& getShutdownState() const + { + return shutdownState; + } + + /// + /// Sets the shutdown state. + /// + DatabasePropertiesOptions& setShutdownState(ShutdownState value) + { + shutdownState = value; + return *this; + } + + /// + /// Returns the shutdown mode. + /// + const std::optional& getShutdownMode() const + { + return shutdownMode; + } + + /// + /// Sets the shutdown mode. + /// + DatabasePropertiesOptions& setShutdownMode(ShutdownMode value) + { + shutdownMode = value; + return *this; + } + + /// + /// Returns the shutdown timeout in seconds. + /// + const std::optional& getShutdownTimeout() const + { + return shutdownTimeout; + } + + /// + /// Sets the shutdown timeout in seconds. + /// + DatabasePropertiesOptions& setShutdownTimeout(int value) + { + shutdownTimeout = value; + return *this; + } + + /// + /// Returns whether the database should be brought online. + /// + const std::optional& getOnline() const + { + return online; + } + + /// + /// Sets whether the database should be brought online. + /// + DatabasePropertiesOptions& setOnline(bool value) + { + online = value; + return *this; + } + private: std::string database; std::optional replicaMode; + std::optional shutdownState; + std::optional shutdownMode; + std::optional shutdownTimeout; + std::optional online; }; /// diff --git a/src/fb-cpp/DatabasePropertyManager.cpp b/src/fb-cpp/DatabasePropertyManager.cpp deleted file mode 100644 index 0aa9114..0000000 --- a/src/fb-cpp/DatabasePropertyManager.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2026 Adriano dos Santos Fernandes - * ... - */ - -#include "DatabasePropertyManager.h" -#include "Client.h" - -using namespace fbcpp; -using namespace fbcpp::impl; - -void DatabasePropertyManager::shutdown(const ShutdownOptions& options) -{ - StatusWrapper statusWrapper{getClient()}; - auto builder = - fbUnique(getClient().getUtil()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::SPB_START, nullptr, 0)); - - builder->insertTag(&statusWrapper, isc_action_svc_properties); - builder->insertString(&statusWrapper, isc_spb_dbname, options.getDatabase().c_str()); - - switch (options.getMode()) - { - case ShutdownMode::DENY_TRANSACTIONS: - builder->insertInt(&statusWrapper, isc_spb_prp_deny_new_transactions, options.getTimeout()); - break; - case ShutdownMode::DENY_ATTACHMENTS: - builder->insertInt(&statusWrapper, isc_spb_prp_deny_new_attachments, options.getTimeout()); - break; - case ShutdownMode::FORCED: - default: - builder->insertInt(&statusWrapper, isc_spb_prp_force_shutdown, options.getTimeout()); - break; - } - - const auto buffer = builder->getBuffer(&statusWrapper); - const auto length = builder->getBufferLength(&statusWrapper); - - startAction(std::vector(buffer, buffer + length)); - waitForCompletion(); -} - -void DatabasePropertyManager::startup(const std::string& database) -{ - StatusWrapper statusWrapper{getClient()}; - auto builder = - fbUnique(getClient().getUtil()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::SPB_START, nullptr, 0)); - - builder->insertTag(&statusWrapper, isc_action_svc_properties); - builder->insertString(&statusWrapper, isc_spb_dbname, database.c_str()); - builder->insertInt(&statusWrapper, isc_spb_options, isc_spb_prp_db_online); - - const auto buffer = builder->getBuffer(&statusWrapper); - const auto length = builder->getBufferLength(&statusWrapper); - - startAction(std::vector(buffer, buffer + length)); - waitForCompletion(); -} diff --git a/src/fb-cpp/DatabasePropertyManager.h b/src/fb-cpp/DatabasePropertyManager.h deleted file mode 100644 index c1314de..0000000 --- a/src/fb-cpp/DatabasePropertyManager.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2026 Adriano dos Santos Fernandes - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef FBCPP_DATABASE_PROPERTY_MANAGER_H -#define FBCPP_DATABASE_PROPERTY_MANAGER_H - -#include "ServiceManager.h" -#include - - -/// -/// fb-cpp namespace. -/// -namespace fbcpp -{ - /// - /// Shutdown mode for a Firebird database (Firebird 2.0+). - /// - enum class ShutdownMode - { - /// - /// Forced shutdown: disconnects all users immediately after the timeout. - /// - FORCED, - - /// - /// Deny new transactions: waits for existing transactions to finish. - /// - DENY_TRANSACTIONS, - - /// - /// Deny new attachments: waits for existing connections to finish. - /// - DENY_ATTACHMENTS - }; - - /// - /// Represents options used to shut down a Firebird database. - /// - class ShutdownOptions final - { - public: - /// - /// Returns the database path. - /// - const std::string& getDatabase() const - { - return database; - } - - /// - /// Sets the database path. - /// - ShutdownOptions& setDatabase(const std::string& value) - { - database = value; - return *this; - } - - /// - /// Returns the shutdown mode. - /// - ShutdownMode getMode() const - { - return mode; - } - - /// - /// Sets the shutdown mode. Defaults to ShutdownMode::FORCED. - /// - ShutdownOptions& setMode(ShutdownMode value) - { - mode = value; - return *this; - } - - /// - /// Returns the timeout in seconds. - /// - int getTimeout() const - { - return timeout; - } - - /// - /// Sets the timeout in seconds (0 = immediate). Defaults to 0. - /// - ShutdownOptions& setTimeout(int value) - { - timeout = value; - return *this; - } - - private: - std::string database; - ShutdownMode mode = ShutdownMode::FORCED; - int timeout = 0; - }; - - /// - /// Executes database property operations (shutdown, startup) through - /// the Firebird service manager. - /// - class DatabasePropertyManager final : public ServiceManager - { - public: - using ServiceManager::ServiceManager; - - public: - /// - /// Shuts down a database using the given options. - /// - void shutdown(const ShutdownOptions& options); - - /// - /// Brings a database back online (online = normal read/write access). - /// - void startup(const std::string& database); - }; -} // namespace fbcpp - - -#endif // FBCPP_DATABASE_PROPERTY_MANAGER_H diff --git a/src/fb-cpp/fb-cpp.h b/src/fb-cpp/fb-cpp.h index e4cfd26..b3f8fc8 100644 --- a/src/fb-cpp/fb-cpp.h +++ b/src/fb-cpp/fb-cpp.h @@ -37,6 +37,5 @@ #include "ServiceManager.h" #include "BackupManager.h" #include "DatabaseManager.h" -#include "DatabasePropertyManager.h" #endif // FBCPP_H diff --git a/src/test/DatabaseManager.cpp b/src/test/DatabaseManager.cpp index 85cd176..99e8551 100644 --- a/src/test/DatabaseManager.cpp +++ b/src/test/DatabaseManager.cpp @@ -194,4 +194,51 @@ BOOST_AUTO_TEST_CASE(databaseSweepAndValidate) cleanup.dropDatabase(); } +BOOST_AUTO_TEST_CASE(databaseShutdownAndOnline) +{ + const auto databasePath = getTempFile("DatabaseManager-shutdownAndOnline.fdb", false); + const auto databaseUri = getTempFile("DatabaseManager-shutdownAndOnline.fdb"); + const auto attachmentOptions = AttachmentOptions().setConnectionCharSet("UTF8"); + + { // scope + Attachment attachment{ + CLIENT, databaseUri, AttachmentOptions().setCreateDatabase(true).setConnectionCharSet("UTF8")}; + Transaction transaction{attachment}; + Statement createTable{attachment, transaction, "create table test (id integer)"}; + BOOST_REQUIRE(createTable.execute(transaction)); + transaction.commit(); + } + + DatabaseManager manager{CLIENT, makeServiceManagerOptions()}; + + // Shutdown the database + manager.setProperties( + DatabasePropertiesOptions() + .setDatabase(databasePath) + .setShutdownState(ShutdownState::FULL) + .setShutdownMode(ShutdownMode::FORCED) + .setShutdownTimeout(0)); + + // Attachment should fail when the database is shutdown + BOOST_CHECK_THROW(Attachment(CLIENT, databaseUri, attachmentOptions), DatabaseException); + + // Bring the database online + manager.setProperties( + DatabasePropertiesOptions() + .setDatabase(databasePath) + .setOnline(true)); + + // Attachment should succeed when online + { // scope + Attachment attachment{CLIENT, databaseUri, attachmentOptions}; + Transaction transaction{attachment}; + Statement query{attachment, transaction, "select count(*) from test"}; + BOOST_REQUIRE(query.execute(transaction)); + BOOST_CHECK_EQUAL(query.getInt32(0).value(), 0); + } + + Attachment cleanup{CLIENT, databaseUri, attachmentOptions}; + cleanup.dropDatabase(); +} + BOOST_AUTO_TEST_SUITE_END() From 03176d144fb63c336b1620730a0557d0e3099563 Mon Sep 17 00:00:00 2001 From: Popa Adrian Marius Date: Tue, 7 Jul 2026 14:44:01 +0300 Subject: [PATCH 3/5] Format src/test/DatabaseManager.cpp --- src/test/DatabaseManager.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/test/DatabaseManager.cpp b/src/test/DatabaseManager.cpp index 99e8551..5a55e8c 100644 --- a/src/test/DatabaseManager.cpp +++ b/src/test/DatabaseManager.cpp @@ -212,8 +212,7 @@ BOOST_AUTO_TEST_CASE(databaseShutdownAndOnline) DatabaseManager manager{CLIENT, makeServiceManagerOptions()}; // Shutdown the database - manager.setProperties( - DatabasePropertiesOptions() + manager.setProperties(DatabasePropertiesOptions() .setDatabase(databasePath) .setShutdownState(ShutdownState::FULL) .setShutdownMode(ShutdownMode::FORCED) @@ -223,10 +222,7 @@ BOOST_AUTO_TEST_CASE(databaseShutdownAndOnline) BOOST_CHECK_THROW(Attachment(CLIENT, databaseUri, attachmentOptions), DatabaseException); // Bring the database online - manager.setProperties( - DatabasePropertiesOptions() - .setDatabase(databasePath) - .setOnline(true)); + manager.setProperties(DatabasePropertiesOptions().setDatabase(databasePath).setOnline(true)); // Attachment should succeed when online { // scope From 6fbfeb2a36ca98ec5db675f9a82ac93e3a2d050c Mon Sep 17 00:00:00 2001 From: Popa Adrian Marius Date: Tue, 7 Jul 2026 13:38:20 +0000 Subject: [PATCH 4/5] Address review comments: remove unused iostream include and fix default branch --- src/fb-cpp/DatabaseManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fb-cpp/DatabaseManager.cpp b/src/fb-cpp/DatabaseManager.cpp index 610db4e..895141b 100644 --- a/src/fb-cpp/DatabaseManager.cpp +++ b/src/fb-cpp/DatabaseManager.cpp @@ -25,7 +25,6 @@ #include "DatabaseManager.h" #include "Client.h" #include -#include using namespace fbcpp; using namespace fbcpp::impl; @@ -96,9 +95,11 @@ void DatabaseManager::setProperties(const DatabasePropertiesOptions& options) builder->insertInt(&statusWrapper, isc_spb_prp_deny_new_attachments, timeout); break; case ShutdownMode::FORCED: - default: builder->insertInt(&statusWrapper, isc_spb_prp_force_shutdown, timeout); break; + default: + assert(false); + break; } } From 0e7fe6ec2c8e14372ab16214486fdbed8d63fa70 Mon Sep 17 00:00:00 2001 From: Adriano dos Santos Fernandes Date: Tue, 7 Jul 2026 21:21:38 -0300 Subject: [PATCH 5/5] Rename enums to match Firebird names --- src/fb-cpp/DatabaseManager.cpp | 27 ++++++++++++++++----------- src/fb-cpp/DatabaseManager.h | 34 +++++++++++++++++----------------- src/test/DatabaseManager.cpp | 4 ++-- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/fb-cpp/DatabaseManager.cpp b/src/fb-cpp/DatabaseManager.cpp index 895141b..6bda793 100644 --- a/src/fb-cpp/DatabaseManager.cpp +++ b/src/fb-cpp/DatabaseManager.cpp @@ -41,6 +41,7 @@ void DatabaseManager::setProperties(const DatabasePropertiesOptions& options) if (const auto replicaMode = options.getReplicaMode()) { std::uint8_t modeVal = 0; + switch (*replicaMode) { case ReplicaMode::NONE: @@ -56,45 +57,49 @@ void DatabaseManager::setProperties(const DatabasePropertiesOptions& options) assert(false); break; } + builder->insertBytes(&statusWrapper, isc_spb_prp_replica_mode, &modeVal, 1u); } - if (const auto shutdownState = options.getShutdownState()) + if (const auto shutdownMode = options.getShutdownMode()) { std::uint8_t stateVal = 0; - switch (*shutdownState) + + switch (*shutdownMode) { - case ShutdownState::NORMAL: + case ShutdownMode::NORMAL: stateVal = isc_spb_prp_sm_normal; break; - case ShutdownState::MULTI: + case ShutdownMode::MULTI: stateVal = isc_spb_prp_sm_multi; break; - case ShutdownState::SINGLE: + case ShutdownMode::SINGLE: stateVal = isc_spb_prp_sm_single; break; - case ShutdownState::FULL: + case ShutdownMode::FULL: stateVal = isc_spb_prp_sm_full; break; default: assert(false); break; } + builder->insertBytes(&statusWrapper, isc_spb_prp_shutdown_mode, &stateVal, 1u); } - if (const auto shutdownMode = options.getShutdownMode()) + if (const auto shutdownType = options.getShutdownType()) { const auto timeout = options.getShutdownTimeout().value_or(0); - switch (*shutdownMode) + + switch (*shutdownType) { - case ShutdownMode::DENY_TRANSACTIONS: + case ShutdownType::DENY_TRANSACTIONS: builder->insertInt(&statusWrapper, isc_spb_prp_deny_new_transactions, timeout); break; - case ShutdownMode::DENY_ATTACHMENTS: + case ShutdownType::DENY_ATTACHMENTS: builder->insertInt(&statusWrapper, isc_spb_prp_deny_new_attachments, timeout); break; - case ShutdownMode::FORCED: + case ShutdownType::FORCED: builder->insertInt(&statusWrapper, isc_spb_prp_force_shutdown, timeout); break; default: diff --git a/src/fb-cpp/DatabaseManager.h b/src/fb-cpp/DatabaseManager.h index 377c2dd..5d55089 100644 --- a/src/fb-cpp/DatabaseManager.h +++ b/src/fb-cpp/DatabaseManager.h @@ -37,9 +37,9 @@ namespace fbcpp { /// - /// Shutdown state for a Firebird database. + /// Shutdown mode for a Firebird database. /// - enum class ShutdownState + enum class ShutdownMode { /// /// Normal online state. @@ -63,9 +63,9 @@ namespace fbcpp }; /// - /// Shutdown mode for a Firebird database. + /// Shutdown type for a Firebird database. /// - enum class ShutdownMode + enum class ShutdownType { /// /// Forced shutdown: disconnects all users immediately after the timeout. @@ -124,36 +124,36 @@ namespace fbcpp } /// - /// Returns the shutdown state. + /// Returns the shutdown mode. /// - const std::optional& getShutdownState() const + const std::optional& getShutdownMode() const { - return shutdownState; + return shutdownMode; } /// - /// Sets the shutdown state. + /// Sets the shutdown mode. /// - DatabasePropertiesOptions& setShutdownState(ShutdownState value) + DatabasePropertiesOptions& setShutdownMode(ShutdownMode value) { - shutdownState = value; + shutdownMode = value; return *this; } /// - /// Returns the shutdown mode. + /// Returns the shutdown type. /// - const std::optional& getShutdownMode() const + const std::optional& getShutdownType() const { - return shutdownMode; + return shutdownType; } /// - /// Sets the shutdown mode. + /// Sets the shutdown type. /// - DatabasePropertiesOptions& setShutdownMode(ShutdownMode value) + DatabasePropertiesOptions& setShutdownType(ShutdownType value) { - shutdownMode = value; + shutdownType = value; return *this; } @@ -194,8 +194,8 @@ namespace fbcpp private: std::string database; std::optional replicaMode; - std::optional shutdownState; std::optional shutdownMode; + std::optional shutdownType; std::optional shutdownTimeout; std::optional online; }; diff --git a/src/test/DatabaseManager.cpp b/src/test/DatabaseManager.cpp index 5a55e8c..13cb5d7 100644 --- a/src/test/DatabaseManager.cpp +++ b/src/test/DatabaseManager.cpp @@ -214,8 +214,8 @@ BOOST_AUTO_TEST_CASE(databaseShutdownAndOnline) // Shutdown the database manager.setProperties(DatabasePropertiesOptions() .setDatabase(databasePath) - .setShutdownState(ShutdownState::FULL) - .setShutdownMode(ShutdownMode::FORCED) + .setShutdownMode(ShutdownMode::FULL) + .setShutdownType(ShutdownType::FORCED) .setShutdownTimeout(0)); // Attachment should fail when the database is shutdown