From: Francis Dupont Date: Mon, 11 Feb 2019 10:27:56 +0000 (+0100) Subject: [94-cb-implement-mysqlconfigbackenddhcpv6-prepare] Shared getGlobalParameters X-Git-Tag: 397-cb-implement-mysqlconfigbackenddhcpv6_base~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e05f2de2803edd680d4208ba4fbfacc79704941;p=thirdparty%2Fkea.git [94-cb-implement-mysqlconfigbackenddhcpv6-prepare] Shared getGlobalParameters --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index c9106e616f..ec16f6f971 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -131,51 +131,6 @@ public: explicit MySqlConfigBackendDHCPv4Impl(const DatabaseConnection::ParameterMap& parameters); - /// @brief Sends query to retrieve multiple global parameters. - /// - /// @param index Index of the query to be used. - /// @param in_bindings Input bindings specifying selection criteria. The - /// size of the bindings collection must match the number of placeholders - /// in the prepared statement. The input bindings collection must be empty - /// if the query contains no WHERE clause. - /// @param [out] subnets Reference to the container where fetched parameters - /// will be inserted. - void getGlobalParameters4(const StatementIndex& index, - const MySqlBindingCollection& in_bindings, - StampedValueCollection& parameters) { - // The following parameters from the dhcp4_global_parameter table are - // returned: - // - id - // - name - parameter name - // - value - parameter value - // - modification_ts - modification timestamp. - MySqlBindingCollection out_bindings = { - MySqlBinding::createInteger(), // id - MySqlBinding::createString(GLOBAL_PARAMETER_NAME_BUF_LENGTH), // name - MySqlBinding::createString(GLOBAL_PARAMETER_VALUE_BUF_LENGTH), // value - MySqlBinding::createInteger(), // parameter_type - MySqlBinding::createTimestamp() // modification_ts - }; - - conn_.selectQuery(index, in_bindings, out_bindings, - [¶meters] - (MySqlBindingCollection& out_bindings) { - if (!out_bindings[1]->getString().empty()) { - - // Convert value read as string from the database to the actual - // data type known from the database as binding #3. - StampedValuePtr stamped_value = - StampedValue::create(out_bindings[1]->getString(), - out_bindings[2]->getString(), - static_cast - (out_bindings[3]->getInteger())); - - stamped_value->setModificationTime(out_bindings[4]->getTimestamp()); - parameters.insert(stamped_value); - } - }); - } - /// @brief Sends query to retrieve global parameter. /// /// @param server_selector Server selector. @@ -194,7 +149,7 @@ public: MySqlBinding::createString(name) }; - getGlobalParameters4(GET_GLOBAL_PARAMETER4, in_bindings, parameters); + getGlobalParameters(GET_GLOBAL_PARAMETER4, in_bindings, parameters); } return (parameters.empty() ? StampedValuePtr() : *parameters.begin()); @@ -2611,8 +2566,8 @@ MySqlConfigBackendDHCPv4::getAllGlobalParameters4(const ServerSelector& server_s auto tags = impl_->getServerTags(server_selector); for (auto tag : tags) { MySqlBindingCollection in_bindings = { MySqlBinding::createString(tag) }; - impl_->getGlobalParameters4(MySqlConfigBackendDHCPv4Impl::GET_ALL_GLOBAL_PARAMETERS4, - in_bindings, parameters); + impl_->getGlobalParameters(MySqlConfigBackendDHCPv4Impl::GET_ALL_GLOBAL_PARAMETERS4, + in_bindings, parameters); } return (parameters); } @@ -2629,8 +2584,8 @@ getModifiedGlobalParameters4(const db::ServerSelector& server_selector, MySqlBinding::createString(tag), MySqlBinding::createTimestamp(modification_time) }; - impl_->getGlobalParameters4(MySqlConfigBackendDHCPv4Impl::GET_MODIFIED_GLOBAL_PARAMETERS4, - in_bindings, parameters); + impl_->getGlobalParameters(MySqlConfigBackendDHCPv4Impl::GET_MODIFIED_GLOBAL_PARAMETERS4, + in_bindings, parameters); } return (parameters); diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index 1ddd5e211a..8017f5a31f 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -189,6 +189,42 @@ MySqlConfigBackendImpl::deleteFromTable(const int index, return (deleteFromTable(index, server_selector, operation, in_bindings)); } +void +MySqlConfigBackendImpl::getGlobalParameters(const int index, + const MySqlBindingCollection& in_bindings, + StampedValueCollection& parameters) { + // The following parameters from the dhcp[46]_global_parameter table are + // returned: + // - id + // - name - parameter name + // - value - parameter value + // - modification_ts - modification timestamp. + MySqlBindingCollection out_bindings = { + MySqlBinding::createInteger(), // id + MySqlBinding::createString(GLOBAL_PARAMETER_NAME_BUF_LENGTH), // name + MySqlBinding::createString(GLOBAL_PARAMETER_VALUE_BUF_LENGTH), // value + MySqlBinding::createInteger(), // parameter_type + MySqlBinding::createTimestamp() // modification_ts + }; + + conn_.selectQuery(index, in_bindings, out_bindings, + [¶meters] (MySqlBindingCollection& out_bindings) { + if (!out_bindings[1]->getString().empty()) { + + // Convert value read as string from the database to the actual + // data type known from the database as binding #3. + StampedValuePtr stamped_value = + StampedValue::create(out_bindings[1]->getString(), + out_bindings[2]->getString(), + static_cast + (out_bindings[3]->getInteger())); + + stamped_value->setModificationTime(out_bindings[4]->getTimestamp()); + parameters.insert(stamped_value); + } + }); +} + void MySqlConfigBackendImpl::getOptionDefs(const int index, const MySqlBindingCollection& in_bindings, diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h index 4650d69039..9e081426cf 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h @@ -7,6 +7,7 @@ #ifndef MYSQL_CONFIG_BACKEND_IMPL_H #define MYSQL_CONFIG_BACKEND_IMPL_H +#include #include #include #include @@ -296,6 +297,19 @@ public: return (deleteFromTable(index, server_selector, operation, in_bindings)); } + /// @brief Sends query to retrieve multiple global parameters. + /// + /// @param index Index of the query to be used. + /// @param in_bindings Input bindings specifying selection criteria. The + /// size of the bindings collection must match the number of placeholders + /// in the prepared statement. The input bindings collection must be empty + /// if the query contains no WHERE clause. + /// @param [out] subnets Reference to the container where fetched parameters + /// will be inserted. + void getGlobalParameters(const int index, + const db::MySqlBindingCollection& in_bindings, + data::StampedValueCollection& parameters); + /// @brief Sends query to the database to retrieve multiple option /// definitions. ///