From: Marcin Siodelski Date: Tue, 16 Oct 2018 12:55:16 +0000 (+0200) Subject: [#93,!63] Fixed update statement for option definition. X-Git-Tag: 153-netconf-configs_base~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=420d6e68946f2dfdbf465d94ba74f3ae8d8999e3;p=thirdparty%2Fkea.git [#93,!63] Fixed update statement for option definition. --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index 9a890e88f1..6c69af34ea 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -1604,12 +1604,7 @@ public: /// @param option_def Pointer to the option definition to be inserted or updated. void createUpdateOptionDef4(const ServerSelector& server_selector, const OptionDefinitionPtr& option_def) { - auto tags = getServerTags(server_selector); - if (tags.size() != 1) { - isc_throw(InvalidOperation, "expected exactly one server tag to be" - " specified while creating or updating option definition." - " Got: " << getServerTagsAsText(server_selector)); - } + auto tag = getServerTag(server_selector, "creating or updating option definition"); ElementPtr record_types = Element::createList(); for (auto field : option_def->getRecordFields()) { @@ -1646,7 +1641,8 @@ public: option_def->getCode(), option_def->getOptionSpaceName()); if (existing_definition) { - // Need to add two more bindings for WHERE clause. + // Need to add three more bindings for WHERE clause. + in_bindings.push_back(MySqlBinding::createString(tag)); in_bindings.push_back(MySqlBinding::createInteger(existing_definition->getCode())); in_bindings.push_back(MySqlBinding::createString(existing_definition->getOptionSpaceName())); conn_.updateDeleteQuery(MySqlConfigBackendDHCPv4Impl::UPDATE_OPTION_DEF4, @@ -1663,7 +1659,7 @@ public: MySqlBindingCollection in_server_bindings = { MySqlBinding::createInteger(id), // option_def_id - MySqlBinding::createString(*tags.begin()), // tag used to obtain server_id + MySqlBinding::createString(tag), // tag used to obtain server_id MySqlBinding::createTimestamp(option_def->getModificationTime()), // modification_ts }; diff --git a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h index 3b03229f84..2a0ea95234 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h +++ b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h @@ -307,17 +307,22 @@ namespace { #ifndef MYSQL_UPDATE_OPTION_DEF #define MYSQL_UPDATE_OPTION_DEF(table_prefix) \ - "UPDATE " #table_prefix "_option_def SET" \ - " code = ?," \ - " name = ?," \ - " space = ?," \ - " type = ?," \ - " modification_ts = ?," \ - " array = ?," \ - " encapsulate = ?," \ - " record_types = ?," \ - " user_context = ? " \ - "WHERE code = ? AND space = ?" + "UPDATE " #table_prefix "_option_def AS d " \ + "INNER JOIN " #table_prefix "_option_def_server AS a" \ + " ON d.id = a.option_def_id " \ + "INNER JOIN " #table_prefix "_server AS s" \ + " ON a.server_id = s.id " \ + "SET" \ + " d.code = ?," \ + " d.name = ?," \ + " d.space = ?," \ + " d.type = ?," \ + " d.modification_ts = ?," \ + " d.array = ?," \ + " d.encapsulate = ?," \ + " d.record_types = ?," \ + " d.user_context = ? " \ + "WHERE s.tag = ? AND d.code = ? AND d.space = ?" #endif #ifndef MYSQL_UPDATE_OPTION