]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1848] Small fixes in PgSqlConfigBackendImpl
authorTomek Mrugalski <tomek@isc.org>
Thu, 1 Jul 2021 14:23:03 +0000 (16:23 +0200)
committerTomek Mrugalski <tomek@isc.org>
Wed, 17 Nov 2021 14:35:18 +0000 (15:35 +0100)
src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.cc
src/hooks/dhcp/pgsql_cb/pgsql_cb_impl.h

index 70ed23fe0b22db2f55fb88d3cf7486843455f053..433aaf8903e2b3cff02d367ffee9cdc9e5f4c5f9 100644 (file)
@@ -71,41 +71,45 @@ PgSqlConfigBackendImpl::~PgSqlConfigBackendImpl() {
     /// will take care of releasing the compiled statements and similar.
 }
 
-#if 0
 PsqlBindArrayPtr
 PgSqlConfigBackendImpl::createBinding(const Triplet<uint32_t>& triplet) {
     PsqlBindArrayPtr bind(new PsqlBindArray());
 
+#if 0
     if (triplet.unspecified()) {
         bind->addNull();
     } else {
         bind->add<uint32_t>(triplet.get());
     }
+#endif
     return (bind);
 }
 
 PsqlBindArrayPtr
 PgSqlConfigBackendImpl::createMinBinding(const Triplet<uint32_t>& triplet) {
     PsqlBindArrayPtr bind(new PsqlBindArray());
+#if 0
     if (triplet.unspecified() || (triplet.getMin() == triplet.get())) {
         bind->addNull();
     } else {
         bind->add<uint32_t>(triplet.getMin());
     }
+#endif
     return (bind);
 }
 
 PsqlBindArrayPtr
 PgSqlConfigBackendImpl::createMaxBinding(const Triplet<uint32_t>& triplet) {
     PsqlBindArrayPtr bind(new PsqlBindArray());
+#if 0
     if (triplet.unspecified() || (triplet.getMax() == triplet.get())) {
         bind->addNull();
     } else {
         bind->add<uint32_t>(triplet.getMax());
     }
+#endif
     return (bind);
 }
-#endif
 
 /* Triplet<uint32_t>
 PgSqlConfigBackendImpl::createTriplet(const PsqlBindArrayPtr& binding) {
@@ -212,6 +216,15 @@ PgSqlConfigBackendImpl::deleteFromTable(const int index,
     return (deleteFromTable(index, server_selector, operation, in_bindings));
 }
 
+uint64_t
+PgSqlConfigBackendImpl::deleteFromTable(const int index,
+                                        const db::ServerSelector& server_selector,
+                                        const std::string& operation,
+                                        db::PsqlBindArray& bindings) {
+    isc_throw(NotImplemented, "todo");
+}
+
+
 void
 PgSqlConfigBackendImpl::getGlobalParameters(const int index,
                                             const PsqlBindArray& in_bindings,
index aad7b57887c717e37b92340a9a97858d865d5d10..57a114fa5fdd96ab3bebc6d2dd31acdaa9f01a74 100644 (file)
@@ -115,16 +115,37 @@ public:
     virtual ~PgSqlConfigBackendImpl();
 
     /// @todo: implement condCreateInteger(const util::Optional<T>& value)
-#if 0
     static db::PsqlBindArrayPtr createBinding(const Triplet<uint32_t>& triplet);
     static db::PsqlBindArrayPtr createMaxBinding(const Triplet<uint32_t>& triplet);
     static db::PsqlBindArrayPtr createMinBinding(const Triplet<uint32_t>& triplet);
+#if 0
     static Triplet<uint32_t> createTriplet(const db::PsqlBindArrayPtr& binding);
     static Triplet<uint32_t> createTriplet(const db::PsqlBindArrayPtr& def_binding,
         const db::PsqlBindArrayPtr& min_binding, const db::PsqlBindArrayPtr& max_binding);
 #endif
+
+    /// @brief Returns server tag associated with the particular selector.
+    ///
+    /// This method expects that there is exactly one server tag associated with
+    /// the server selector.
+    ///
+    /// @param server_selector Server selector.
+    /// @param operation Operation which results in calling this function. This is
+    /// used for error reporting purposes.
+    /// @return Server tag.
+    /// @throw InvalidOperation if the server selector is unassigned or if there
+    /// is more than one server tag associated with the selector.
     std::string getServerTag(const db::ServerSelector& server_selector,
-                            const std::string& operation );
+                             const std::string& operation) const {
+        auto tags = server_selector.getTags();
+        if (tags.size() != 1) {
+            isc_throw(InvalidOperation, "expected exactly one server tag to be specified"
+                      " while " << operation << ". Got: "
+                      << getServerTagsAsText(server_selector));
+        }
+
+        return (tags.begin()->get());
+    }
 
     /// @brief Returns server tags associated with the particular selector
     /// as text.
@@ -143,8 +164,6 @@ public:
         return (s.str());
     }
 
-
-
     /// @brief Invokes the corresponding stored procedure in MySQL.
     ///
     /// The @c createAuditRevision stored procedure creates new audit