]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2244] Fixed boost 1.53 build error
authorThomas Markwalder <tmark@isc.org>
Tue, 4 Jan 2022 19:02:52 +0000 (14:02 -0500)
committerThomas Markwalder <tmark@isc.org>
Fri, 7 Jan 2022 20:27:52 +0000 (15:27 -0500)
src/lib/pgsql/pgsql_exchange.cc
    PsqlBindArray::addTimestamp(const boost::posix_time::ptime& timestamp)
    - removed use of boost::posix_time::to_time_t

src/lib/pgsql/tests/pgsql_exchange_unittest.cc
    TEST_F(PgSqlBasicsTest, ptimeTimestamp)  - updated test

src/lib/pgsql/pgsql_exchange.cc
src/lib/pgsql/pgsql_exchange.h
src/lib/pgsql/tests/pgsql_exchange_unittest.cc

index e3db14022bd528331a97f3048ffcfe1848de10fd..9cee1d574033ad4265a226eee28165cfb002c731 100644 (file)
@@ -18,6 +18,7 @@
 
 using namespace isc::util;
 using namespace isc::data;
+using namespace boost::posix_time;
 
 namespace isc {
 namespace db {
@@ -206,7 +207,19 @@ PsqlBindArray::addOptionalInet6(const util::Optional<isc::asiolink::IOAddress>&
 
 void
 PsqlBindArray::addTimestamp(const boost::posix_time::ptime& timestamp) {
-    time_t input_time = boost::posix_time::to_time_t(timestamp);
+    // Convert the ptime to time_t, then use the existing conversion
+    // function to make db time.
+    //
+    // Sadly boost::posix_time::to_time_t() was not added until 1.58,
+    // so do it ourselves.
+    ptime epoch(boost::gregorian::date(1970,1,1));
+    time_duration::sec_type since_epoch = (timestamp - epoch).total_seconds();
+    time_t input_time(since_epoch);
+
+    if (input_time > DatabaseConnection::MAX_DB_TIME) {
+        isc_throw(isc::BadValue, "Time value is too large: " << input_time);
+    }
+
     // Converts to timestamp to local date/time string.
     addTempString(PgSqlExchange::convertToDatabaseTime(input_time));
 }
index 0c38d0b143cb722af6ee17e5d71516b29a984016..f45a5391f6f8e557654496da1afc0150d80c31a6 100644 (file)
@@ -400,6 +400,7 @@ struct PsqlBindArray {
     /// Precision is seconds.
     ///
     /// @param timestamp Timestamp value to be sent to the database.
+    /// @throw BadValue if the timestamp exceeds DatabaseConnection::MAX_DB_TIME.
     void addTimestamp(const boost::posix_time::ptime& timestamp);
 
     /// @brief Adds a timestamp of the current time to the bind array.
index a1eacb756b4ea3a7c8c37e96917563cb42251836..92d9c77fca6caaa54baf506b23c22c2d0ef1d9a1 100644 (file)
@@ -969,13 +969,17 @@ TEST_F(PgSqlBasicsTest, ptimeTimestamp) {
 
     ASSERT_NO_THROW(conn_->prepareStatement(statement[0]));
 
+    // Create an empty array.
+    PsqlBindArrayPtr bind_array(new PsqlBindArray());
+
+    // Make sure we catch values that are too big.
     time_duration duration = hours(10) + minutes(14) + seconds(15);
+    ptime day_too_far(date(3021, Jan, 21), duration);
+    ASSERT_THROW_MSG(bind_array->addTimestamp(day_too_far), BadValue,
+                     "Time value is too large: 33168132855");
 
-    // US National Ice Cream day
+    // Now add reasonable day, US National Ice Cream day.
     ptime nice_day(date(2021, Jul, 18), duration);
-
-    // Add timestamp with default/fractional seconds.
-    PsqlBindArrayPtr bind_array(new PsqlBindArray());
     bind_array->addTimestamp(nice_day);
     std::cout << "bind array: " << bind_array->toText() << std::endl;