From 4a1ed2c02e54a636a4769a8f41c3a229f7ca17c8 Mon Sep 17 00:00:00 2001 From: MeanSquaredError <35379301+MeanSquaredError@users.noreply.github.com> Date: Sun, 23 Jul 2023 11:40:27 +0300 Subject: [PATCH] Fix serialization of time points for MySQL. (#503) --- include/sqlpp11/data_types/time_point/operand.h | 2 +- include/sqlpp11/postgresql/serializer.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/data_types/time_point/operand.h b/include/sqlpp11/data_types/time_point/operand.h index bc2db479..dff77368 100644 --- a/include/sqlpp11/data_types/time_point/operand.h +++ b/include/sqlpp11/data_types/time_point/operand.h @@ -67,7 +67,7 @@ namespace sqlpp const auto dp = ::sqlpp::chrono::floor<::date::days>(t._t); const auto time = ::date::make_time(t._t - dp); const auto ymd = ::date::year_month_day{dp}; - context << "TIMESTAMP WITH TIME ZONE '" << ymd << ' ' << time << "+00'"; + context << "TIMESTAMP '" << ymd << ' ' << time << "'"; return context; } } // namespace sqlpp diff --git a/include/sqlpp11/postgresql/serializer.h b/include/sqlpp11/postgresql/serializer.h index 50c37cfd..57337098 100644 --- a/include/sqlpp11/postgresql/serializer.h +++ b/include/sqlpp11/postgresql/serializer.h @@ -28,6 +28,7 @@ #ifndef SQLPP_POSTGRESQL_SERIALIZER_H #define SQLPP_POSTGRESQL_SERIALIZER_H +#include #include #include @@ -54,6 +55,16 @@ namespace sqlpp return context; } + + template + postgresql::context_t& serialize(const time_point_operand& t, postgresql::context_t& context) + { + const auto dp = ::sqlpp::chrono::floor<::date::days>(t._t); + const auto time = ::date::make_time(t._t - dp); + const auto ymd = ::date::year_month_day{dp}; + context << "TIMESTAMP WITH TIME ZONE '" << ymd << ' ' << time << "+00'"; + return context; + } } #endif