]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#93,!63] Fixed update statement for option definition.
authorMarcin Siodelski <marcin@isc.org>
Tue, 16 Oct 2018 12:55:16 +0000 (14:55 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 18 Oct 2018 11:35:08 +0000 (13:35 +0200)
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h

index 9a890e88f12ec9c3cfd12a3e775c8936499cb8d7..6c69af34ea06038adcf0bf43082dd380a922223e 100644 (file)
@@ -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<uint8_t>(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<uint64_t>(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
             };
 
index 3b03229f8463549090a0794e2668a7bcfe03b865..2a0ea952349debd2fedf13beff090ac2a8b7f31f 100644 (file)
@@ -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