Browse Source

Merge branch 'schema-version' of https://github.com/andreipavelQ/kea into andreipavelQ-schema-version

Tomek Mrugalski 8 years ago
parent
commit
a8d2dc9aaf

+ 10 - 6
src/lib/dhcpsrv/pgsql_connection.h

@@ -12,18 +12,22 @@
 #include <boost/scoped_ptr.hpp>
 #include <boost/scoped_ptr.hpp>
 
 
 #include <vector>
 #include <vector>
-
+#include <stdint.h>
 
 
 namespace isc {
 namespace isc {
 namespace dhcp {
 namespace dhcp {
 
 
+/// @brief Define PostgreSQL backend version: 3.0
+const uint32_t PG_SCHEMA_VERSION_MAJOR = 3;
+const uint32_t PG_SCHEMA_VERSION_MINOR = 0;
+
 // Maximum number of parameters that can be used a statement
 // Maximum number of parameters that can be used a statement
 // @todo This allows us to use an initializer list (since we can't
 // @todo This allows us to use an initializer list (since we can't
 // require C++11).  It's unlikely we'd go past this many a single
 // require C++11).  It's unlikely we'd go past this many a single
 // statement.
 // statement.
 const size_t PGSQL_MAX_PARAMETERS_IN_QUERY = 32;
 const size_t PGSQL_MAX_PARAMETERS_IN_QUERY = 32;
 
 
-/// @brief  Defines a Postgresql SQL statement
+/// @brief Define a PostgreSQL SQL statement
 ///
 ///
 /// Each statement is associated with an index, which is used to reference the
 /// Each statement is associated with an index, which is used to reference the
 /// associated prepared statement.
 /// associated prepared statement.
@@ -46,8 +50,9 @@ struct PgSqlTaggedStatement {
 };
 };
 
 
 /// @brief Constants for PostgreSQL data types
 /// @brief Constants for PostgreSQL data types
-/// This are defined by PostreSQL in <catalog/pg_type.h>, but including
+/// These are defined by PostgreSQL in <catalog/pg_type.h>, but including
 /// this file is extraordinarily convoluted, so we'll use these to fill-in.
 /// this file is extraordinarily convoluted, so we'll use these to fill-in.
+/// @{
 const size_t OID_NONE = 0;   // PostgreSQL infers proper type
 const size_t OID_NONE = 0;   // PostgreSQL infers proper type
 const size_t OID_BOOL = 16;
 const size_t OID_BOOL = 16;
 const size_t OID_BYTEA = 17;
 const size_t OID_BYTEA = 17;
@@ -57,8 +62,7 @@ const size_t OID_INT4 = 23;  // 4 byte int
 const size_t OID_TEXT = 25;
 const size_t OID_TEXT = 25;
 const size_t OID_VARCHAR = 1043;
 const size_t OID_VARCHAR = 1043;
 const size_t OID_TIMESTAMP = 1114;
 const size_t OID_TIMESTAMP = 1114;
-
-//@}
+///@}
 
 
 /// @brief RAII wrapper for Posgtresql Result sets
 /// @brief RAII wrapper for Posgtresql Result sets
 ///
 ///
@@ -289,7 +293,7 @@ private:
 /// that use instances of PgSqlConnection.
 /// that use instances of PgSqlConnection.
 class PgSqlConnection : public DatabaseConnection {
 class PgSqlConnection : public DatabaseConnection {
 public:
 public:
-    /// @brief Defines the PgSql error state for a duplicate key error
+    /// @brief Define the PgSql error state for a duplicate key error
     static const char DUPLICATE_KEY[];
     static const char DUPLICATE_KEY[];
 
 
     /// @brief Constructor
     /// @brief Constructor

+ 3 - 4
src/lib/dhcpsrv/pgsql_lease_mgr.cc

@@ -230,7 +230,6 @@ namespace dhcp {
 /// database.
 /// database.
 class PgSqlLeaseExchange : public PgSqlExchange {
 class PgSqlLeaseExchange : public PgSqlExchange {
 public:
 public:
-
     PgSqlLeaseExchange()
     PgSqlLeaseExchange()
         : addr_str_(""), valid_lifetime_(0), valid_lft_str_(""),
         : addr_str_(""), valid_lifetime_(0), valid_lft_str_(""),
           expire_(0), expire_str_(""), subnet_id_(0), subnet_id_str_(""),
           expire_(0), expire_str_(""), subnet_id_(0), subnet_id_str_(""),
@@ -819,7 +818,7 @@ PgSqlLeaseMgr::PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
                   << " does not match expected count:" << NUM_STATEMENTS);
                   << " does not match expected count:" << NUM_STATEMENTS);
     }
     }
 
 
-    pair<uint32_t, uint32_t> code_version(PG_CURRENT_VERSION, PG_CURRENT_MINOR);
+    pair<uint32_t, uint32_t> code_version(PG_SCHEMA_VERSION_MAJOR, PG_SCHEMA_VERSION_MINOR);
     pair<uint32_t, uint32_t> db_version = getVersion();
     pair<uint32_t, uint32_t> db_version = getVersion();
     if (code_version != db_version) {
     if (code_version != db_version) {
         isc_throw(DbOpenError, "Posgresql schema version mismatch: need version: "
         isc_throw(DbOpenError, "Posgresql schema version mismatch: need version: "
@@ -834,8 +833,8 @@ PgSqlLeaseMgr::~PgSqlLeaseMgr() {
 std::string
 std::string
 PgSqlLeaseMgr::getDBVersion() {
 PgSqlLeaseMgr::getDBVersion() {
     std::stringstream tmp;
     std::stringstream tmp;
-    tmp << "PostgreSQL backend " << PG_CURRENT_VERSION;
-    tmp << "." << PG_CURRENT_MINOR;
+    tmp << "PostgreSQL backend " << PG_SCHEMA_VERSION_MAJOR;
+    tmp << "." << PG_SCHEMA_VERSION_MINOR;
     tmp << ", library " << PQlibVersion();
     tmp << ", library " << PQlibVersion();
     return (tmp.str());
     return (tmp.str());
 }
 }

+ 0 - 4
src/lib/dhcpsrv/pgsql_lease_mgr.h

@@ -25,10 +25,6 @@ namespace dhcp {
 class PgSqlLease4Exchange;
 class PgSqlLease4Exchange;
 class PgSqlLease6Exchange;
 class PgSqlLease6Exchange;
 
 
-/// Defines PostgreSQL backend version: 3.0
-const uint32_t PG_CURRENT_VERSION = 3;
-const uint32_t PG_CURRENT_MINOR = 0;
-
 /// @brief PostgreSQL Lease Manager
 /// @brief PostgreSQL Lease Manager
 ///
 ///
 /// This class provides the \ref isc::dhcp::LeaseMgr interface to the PostgreSQL
 /// This class provides the \ref isc::dhcp::LeaseMgr interface to the PostgreSQL

+ 2 - 2
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc

@@ -190,8 +190,8 @@ TEST_F(PgSqlLeaseMgrTest, checkVersion) {
     // Check version
     // Check version
     pair<uint32_t, uint32_t> version;
     pair<uint32_t, uint32_t> version;
     ASSERT_NO_THROW(version = lmptr_->getVersion());
     ASSERT_NO_THROW(version = lmptr_->getVersion());
-    EXPECT_EQ(PG_CURRENT_VERSION, version.first);
-    EXPECT_EQ(PG_CURRENT_MINOR, version.second);
+    EXPECT_EQ(PG_SCHEMA_VERSION_MAJOR, version.first);
+    EXPECT_EQ(PG_SCHEMA_VERSION_MINOR, version.second);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////