Browse Source

[4489] Addressed second set of review comments.

Expand vector of statements depending on statement index and
some little fixes in doxygen.
Marcin Siodelski 8 years ago
parent
commit
7afd2addc6

+ 5 - 10
src/lib/dhcpsrv/mysql_connection.cc

@@ -12,7 +12,6 @@
 #include <boost/lexical_cast.hpp>
 
 #include <algorithm>
-#include <iterator>
 #include <stdint.h>
 #include <string>
 #include <limits>
@@ -215,18 +214,14 @@ MySqlConnection::prepareStatement(uint32_t index, const char* text) {
 void
 MySqlConnection::prepareStatements(const TaggedStatement* start_statement,
                                    const TaggedStatement* end_statement) {
-    size_t num_statements = std::distance(start_statement, end_statement);
-    if (num_statements == 0) {
-        return;
-    }
-
-    // Expand vectors of allocated statements to hold additional statements.
-    statements_.resize(statements_.size() + num_statements, NULL);
-    text_statements_.resize(text_statements_.size() + num_statements, std::string(""));
-
     // Created the MySQL prepared statements for each DML statement.
     for (const TaggedStatement* tagged_statement = start_statement;
          tagged_statement != end_statement; ++tagged_statement) {
+        if (tagged_statement->index >= statements_.size()) {
+            statements_.resize(tagged_statement->index + 1, NULL);
+            text_statements_.resize(tagged_statement->index + 1,
+                                    std::string(""));
+        }
         prepareStatement(tagged_statement->index,
                          tagged_statement->text);
     }

+ 5 - 1
src/lib/dhcpsrv/mysql_connection.h

@@ -240,7 +240,11 @@ public:
     ///
     /// Creates the prepared statements for all of the SQL statements used
     /// by the MySQL backend.
-    /// @param tagged_statements an array of statements to be compiled
+    ///
+    /// @param start_statement Pointer to the first statement in range of the
+    /// statements to be compiled.
+    /// @param end_statement Pointer to the statement marking end of the
+    /// range of statements to be compiled. This last statement is not compiled.
     ///
     /// @throw isc::dhcp::DbOperationError An operation on the open database has
     ///        failed.

+ 5 - 1
src/lib/dhcpsrv/pgsql_connection.h

@@ -317,7 +317,11 @@ public:
     ///
     /// Creates the prepared statements for all of the SQL statements used
     /// by the PostgreSQL backend.
-    /// @param tagged_statements an array of statements to be compiled
+    ///
+    /// @param start_statement Pointer to the first statement in range of the
+    /// statements to be compiled.
+    /// @param end_statement Pointer to the statement marking end of the
+    /// range of statements to be compiled. This last statement is not compiled.
     ///
     /// @throw isc::dhcp::DbOperationError An operation on the open database has
     ///        failed.