From 21d633bdf49f53b7a8f00856137bbe0191469e69 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 31 Oct 2015 10:20:35 +0100 Subject: [PATCH] Merged /serialize.h into operand and result_field --- include/sqlpp11/data_types/boolean.h | 1 - include/sqlpp11/data_types/boolean/operand.h | 14 ++++ .../sqlpp11/data_types/boolean/result_field.h | 7 ++ .../sqlpp11/data_types/boolean/serialize.h | 57 --------------- include/sqlpp11/data_types/day_point.h | 1 - .../sqlpp11/data_types/day_point/operand.h | 16 +++++ .../data_types/day_point/result_field.h | 16 +++++ .../sqlpp11/data_types/day_point/serialize.h | 66 ----------------- include/sqlpp11/data_types/floating_point.h | 1 - .../data_types/floating_point/operand.h | 14 ++++ .../data_types/floating_point/result_field.h | 7 ++ .../data_types/floating_point/serialize.h | 55 --------------- include/sqlpp11/data_types/integral.h | 1 - include/sqlpp11/data_types/integral/operand.h | 14 ++++ .../data_types/integral/result_field.h | 7 ++ .../sqlpp11/data_types/integral/serialize.h | 55 --------------- include/sqlpp11/data_types/text.h | 1 - include/sqlpp11/data_types/text/operand.h | 14 ++++ .../sqlpp11/data_types/text/result_field.h | 14 ++++ include/sqlpp11/data_types/text/serialize.h | 62 ---------------- include/sqlpp11/data_types/time_point.h | 1 - .../sqlpp11/data_types/time_point/operand.h | 18 +++++ .../data_types/time_point/result_field.h | 18 +++++ .../sqlpp11/data_types/time_point/serialize.h | 70 ------------------- 24 files changed, 159 insertions(+), 371 deletions(-) delete mode 100644 include/sqlpp11/data_types/boolean/serialize.h delete mode 100644 include/sqlpp11/data_types/day_point/serialize.h delete mode 100644 include/sqlpp11/data_types/floating_point/serialize.h delete mode 100644 include/sqlpp11/data_types/integral/serialize.h delete mode 100644 include/sqlpp11/data_types/text/serialize.h delete mode 100644 include/sqlpp11/data_types/time_point/serialize.h diff --git a/include/sqlpp11/data_types/boolean.h b/include/sqlpp11/data_types/boolean.h index dbc2f13a..b08fd5ce 100644 --- a/include/sqlpp11/data_types/boolean.h +++ b/include/sqlpp11/data_types/boolean.h @@ -34,6 +34,5 @@ #include #include #include -#include #endif diff --git a/include/sqlpp11/data_types/boolean/operand.h b/include/sqlpp11/data_types/boolean/operand.h index 14d820b6..68301c6b 100644 --- a/include/sqlpp11/data_types/boolean/operand.h +++ b/include/sqlpp11/data_types/boolean/operand.h @@ -29,6 +29,7 @@ #include #include +#include namespace sqlpp { @@ -63,6 +64,19 @@ namespace sqlpp _value_t _t; }; + + template + struct serializer_t + { + using _serialize_check = consistent_t; + using Operand = boolean_operand; + + static Context& _(const Operand& t, Context& context) + { + context << t._t; + return context; + } + }; } #endif diff --git a/include/sqlpp11/data_types/boolean/result_field.h b/include/sqlpp11/data_types/boolean/result_field.h index 4041585a..8e6c94e9 100644 --- a/include/sqlpp11/data_types/boolean/result_field.h +++ b/include/sqlpp11/data_types/boolean/result_field.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace sqlpp { @@ -103,5 +104,11 @@ namespace sqlpp bool _is_null; signed char _value; }; + + template + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + { + return serialize(e, os); + } } #endif diff --git a/include/sqlpp11/data_types/boolean/serialize.h b/include/sqlpp11/data_types/boolean/serialize.h deleted file mode 100644 index 093fc972..00000000 --- a/include/sqlpp11/data_types/boolean/serialize.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2013-2015, Roland Bock - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SQLPP_BOOLEAN_SERIALIZE_H -#define SQLPP_BOOLEAN_SERIALIZE_H - -#include -#include -#include - -namespace sqlpp -{ - struct boolean; - - template - struct serializer_t - { - using _serialize_check = consistent_t; - using Operand = boolean_operand; - - static Context& _(const Operand& t, Context& context) - { - context << t._t; - return context; - } - }; - - template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) - { - return serialize(e, os); - } -} -#endif diff --git a/include/sqlpp11/data_types/day_point.h b/include/sqlpp11/data_types/day_point.h index 0c6457bd..779dffae 100644 --- a/include/sqlpp11/data_types/day_point.h +++ b/include/sqlpp11/data_types/day_point.h @@ -34,6 +34,5 @@ #include #include #include -#include #endif diff --git a/include/sqlpp11/data_types/day_point/operand.h b/include/sqlpp11/data_types/day_point/operand.h index 68d16d46..a7f714c8 100644 --- a/include/sqlpp11/data_types/day_point/operand.h +++ b/include/sqlpp11/data_types/day_point/operand.h @@ -27,9 +27,11 @@ #ifndef SQLPP_DAY_POINT_OPERAND_H #define SQLPP_DAY_POINT_OPERAND_H +#include #include #include #include +#include namespace sqlpp { @@ -64,5 +66,19 @@ namespace sqlpp _value_t _t; }; + + template + struct serializer_t + { + using _serialize_check = consistent_t; + using Operand = day_point_operand; + + static Context& _(const Operand& t, Context& context) + { + const auto ymd = ::date::year_month_day{t._t}; + context << "DATE '" << ymd << "'"; + return context; + } + }; } #endif diff --git a/include/sqlpp11/data_types/day_point/result_field.h b/include/sqlpp11/data_types/day_point/result_field.h index cebdda71..db726706 100644 --- a/include/sqlpp11/data_types/day_point/result_field.h +++ b/include/sqlpp11/data_types/day_point/result_field.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace sqlpp { @@ -104,5 +105,20 @@ namespace sqlpp bool _is_null; _cpp_value_type _value; }; + + template + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + { + if (e.is_null() and not null_is_trivial_value_t::value) + { + os << "NULL"; + } + else + { + const auto ymd = ::date::year_month_day{e.value()}; + os << ymd; + } + return os; + } } #endif diff --git a/include/sqlpp11/data_types/day_point/serialize.h b/include/sqlpp11/data_types/day_point/serialize.h deleted file mode 100644 index e7bca1e7..00000000 --- a/include/sqlpp11/data_types/day_point/serialize.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2015-2015, Roland Bock - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SQLPP_DAY_POINT_SERIALIZE_H -#define SQLPP_DAY_POINT_SERIALIZE_H - -#include -#include -#include -#include - -namespace sqlpp -{ - template - struct serializer_t - { - using _serialize_check = consistent_t; - using Operand = day_point_operand; - - static Context& _(const Operand& t, Context& context) - { - const auto ymd = ::date::year_month_day{t._t}; - context << "DATE '" << ymd << "'"; - return context; - } - }; - - template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) - { - if (e.is_null() and not null_is_trivial_value_t::value) - { - os << "NULL"; - } - else - { - const auto ymd = ::date::year_month_day{e.value()}; - os << ymd; - } - return os; - } -} -#endif diff --git a/include/sqlpp11/data_types/floating_point.h b/include/sqlpp11/data_types/floating_point.h index 14731c5e..2be6924a 100644 --- a/include/sqlpp11/data_types/floating_point.h +++ b/include/sqlpp11/data_types/floating_point.h @@ -34,6 +34,5 @@ #include #include #include -#include #endif diff --git a/include/sqlpp11/data_types/floating_point/operand.h b/include/sqlpp11/data_types/floating_point/operand.h index e13d890f..ed53764c 100644 --- a/include/sqlpp11/data_types/floating_point/operand.h +++ b/include/sqlpp11/data_types/floating_point/operand.h @@ -29,6 +29,7 @@ #include #include +#include namespace sqlpp { @@ -61,5 +62,18 @@ namespace sqlpp _value_t _t; }; + + template + struct serializer_t + { + using _serialize_check = consistent_t; + using Operand = floating_point_operand; + + static Context& _(const Operand& t, Context& context) + { + context << t._t; + return context; + } + }; } #endif diff --git a/include/sqlpp11/data_types/floating_point/result_field.h b/include/sqlpp11/data_types/floating_point/result_field.h index f5e93119..27773b44 100644 --- a/include/sqlpp11/data_types/floating_point/result_field.h +++ b/include/sqlpp11/data_types/floating_point/result_field.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace sqlpp { @@ -104,5 +105,11 @@ namespace sqlpp bool _is_null; _cpp_value_type _value; }; + + template + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + { + return serialize(e, os); + } } #endif diff --git a/include/sqlpp11/data_types/floating_point/serialize.h b/include/sqlpp11/data_types/floating_point/serialize.h deleted file mode 100644 index 018b6a71..00000000 --- a/include/sqlpp11/data_types/floating_point/serialize.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2013-2015, Roland Bock - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SQLPP_FLOATING_POINT_SERIALIZE_H -#define SQLPP_FLOATING_POINT_SERIALIZE_H - -#include -#include -#include - -namespace sqlpp -{ - template - struct serializer_t - { - using _serialize_check = consistent_t; - using Operand = floating_point_operand; - - static Context& _(const Operand& t, Context& context) - { - context << t._t; - return context; - } - }; - - template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) - { - return serialize(e, os); - } -} -#endif diff --git a/include/sqlpp11/data_types/integral.h b/include/sqlpp11/data_types/integral.h index 1aa43498..a4836b23 100644 --- a/include/sqlpp11/data_types/integral.h +++ b/include/sqlpp11/data_types/integral.h @@ -34,6 +34,5 @@ #include #include #include -#include #endif diff --git a/include/sqlpp11/data_types/integral/operand.h b/include/sqlpp11/data_types/integral/operand.h index 181087ea..4625f06b 100644 --- a/include/sqlpp11/data_types/integral/operand.h +++ b/include/sqlpp11/data_types/integral/operand.h @@ -29,6 +29,7 @@ #include #include +#include namespace sqlpp { @@ -63,6 +64,19 @@ namespace sqlpp _value_t _t; }; + + template + struct serializer_t + { + using _serialize_check = consistent_t; + using Operand = integral_operand; + + static Context& _(const Operand& t, Context& context) + { + context << t._t; + return context; + } + }; } #endif diff --git a/include/sqlpp11/data_types/integral/result_field.h b/include/sqlpp11/data_types/integral/result_field.h index f36eb2da..7a07b1b0 100644 --- a/include/sqlpp11/data_types/integral/result_field.h +++ b/include/sqlpp11/data_types/integral/result_field.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace sqlpp { @@ -104,5 +105,11 @@ namespace sqlpp bool _is_null; _cpp_value_type _value; }; + + template + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + { + return serialize(e, os); + } } #endif diff --git a/include/sqlpp11/data_types/integral/serialize.h b/include/sqlpp11/data_types/integral/serialize.h deleted file mode 100644 index 857713b1..00000000 --- a/include/sqlpp11/data_types/integral/serialize.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2013-2015, Roland Bock - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SQLPP_INTEGRAL_SERIALIZE_H -#define SQLPP_INTEGRAL_SERIALIZE_H - -#include -#include -#include - -namespace sqlpp -{ - template - struct serializer_t - { - using _serialize_check = consistent_t; - using Operand = integral_operand; - - static Context& _(const Operand& t, Context& context) - { - context << t._t; - return context; - } - }; - - template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) - { - return serialize(e, os); - } -} -#endif diff --git a/include/sqlpp11/data_types/text.h b/include/sqlpp11/data_types/text.h index d7099cd4..c50d4b3f 100644 --- a/include/sqlpp11/data_types/text.h +++ b/include/sqlpp11/data_types/text.h @@ -34,7 +34,6 @@ #include #include #include -#include // text specific functions #include diff --git a/include/sqlpp11/data_types/text/operand.h b/include/sqlpp11/data_types/text/operand.h index 8b1fc6a4..d67a938e 100644 --- a/include/sqlpp11/data_types/text/operand.h +++ b/include/sqlpp11/data_types/text/operand.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace sqlpp { @@ -64,5 +65,18 @@ namespace sqlpp _value_t _t; }; + + template + struct serializer_t + { + using _serialize_check = consistent_t; + using Operand = text_operand; + + static Context& _(const Operand& t, Context& context) + { + context << '\'' << context.escape(t._t) << '\''; + return context; + } + }; } #endif diff --git a/include/sqlpp11/data_types/text/result_field.h b/include/sqlpp11/data_types/text/result_field.h index b166c0e8..8e6b7e21 100644 --- a/include/sqlpp11/data_types/text/result_field.h +++ b/include/sqlpp11/data_types/text/result_field.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace sqlpp { @@ -112,5 +113,18 @@ namespace sqlpp const char* _value_ptr; size_t _len; }; + + template + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + { + if (e.is_null() and not null_is_trivial_value_t::value) + { + return os << "NULL"; + } + else + { + return os << e.value(); + } + } } #endif diff --git a/include/sqlpp11/data_types/text/serialize.h b/include/sqlpp11/data_types/text/serialize.h deleted file mode 100644 index 41d3d442..00000000 --- a/include/sqlpp11/data_types/text/serialize.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2013-2015, Roland Bock - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SQLPP_TEXT_SERIALIZE_H -#define SQLPP_TEXT_SERIALIZE_H - -#include -#include -#include - -namespace sqlpp -{ - template - struct serializer_t - { - using _serialize_check = consistent_t; - using Operand = text_operand; - - static Context& _(const Operand& t, Context& context) - { - context << '\'' << context.escape(t._t) << '\''; - return context; - } - }; - - template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) - { - if (e.is_null() and not null_is_trivial_value_t::value) - { - return os << "NULL"; - } - else - { - return os << e.value(); - } - } -} -#endif diff --git a/include/sqlpp11/data_types/time_point.h b/include/sqlpp11/data_types/time_point.h index ec982439..e6f02703 100644 --- a/include/sqlpp11/data_types/time_point.h +++ b/include/sqlpp11/data_types/time_point.h @@ -34,6 +34,5 @@ #include #include #include -#include #endif diff --git a/include/sqlpp11/data_types/time_point/operand.h b/include/sqlpp11/data_types/time_point/operand.h index e3b78b57..2ff97840 100644 --- a/include/sqlpp11/data_types/time_point/operand.h +++ b/include/sqlpp11/data_types/time_point/operand.h @@ -27,9 +27,11 @@ #ifndef SQLPP_TIME_POINT_OPERAND_H #define SQLPP_TIME_POINT_OPERAND_H +#include #include #include #include +#include namespace sqlpp { @@ -65,5 +67,21 @@ namespace sqlpp _value_t _t; }; + + template + struct serializer_t> + { + using _serialize_check = consistent_t; + using Operand = time_point_operand; + + static Context& _(const Operand& t, Context& context) + { + const auto dp = ::date::floor<::date::days>(t._t); + const auto time = ::date::make_time(t._t - dp); + const auto ymd = ::date::year_month_day{dp}; + context << "TIMESTAMP '" << ymd << ' ' << time << "'"; + return context; + } + }; } #endif diff --git a/include/sqlpp11/data_types/time_point/result_field.h b/include/sqlpp11/data_types/time_point/result_field.h index edee6be4..66069dbb 100644 --- a/include/sqlpp11/data_types/time_point/result_field.h +++ b/include/sqlpp11/data_types/time_point/result_field.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace sqlpp { @@ -105,5 +106,22 @@ namespace sqlpp bool _is_null; _cpp_value_type _value; }; + + template + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + { + if (e.is_null() and not null_is_trivial_value_t::value) + { + os << "NULL"; + } + else + { + const auto dp = ::date::floor<::date::days>(e.value()); + const auto time = ::date::make_time(e.value() - dp); + const auto ymd = ::date::year_month_day{dp}; + os << ymd << 'T' << time; + } + return os; + } } #endif diff --git a/include/sqlpp11/data_types/time_point/serialize.h b/include/sqlpp11/data_types/time_point/serialize.h deleted file mode 100644 index a3d0f736..00000000 --- a/include/sqlpp11/data_types/time_point/serialize.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2015-2015, Roland Bock - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SQLPP_TIME_POINT_SERIALIZE_H -#define SQLPP_TIME_POINT_SERIALIZE_H - -#include -#include -#include -#include - -namespace sqlpp -{ - template - struct serializer_t> - { - using _serialize_check = consistent_t; - using Operand = time_point_operand; - - static Context& _(const Operand& t, Context& context) - { - const auto dp = ::date::floor<::date::days>(t._t); - const auto time = ::date::make_time(t._t - dp); - const auto ymd = ::date::year_month_day{dp}; - context << "TIMESTAMP '" << ymd << ' ' << time << "'"; - return context; - } - }; - - template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) - { - if (e.is_null() and not null_is_trivial_value_t::value) - { - os << "NULL"; - } - else - { - const auto dp = ::date::floor<::date::days>(e.value()); - const auto time = ::date::make_time(e.value() - dp); - const auto ymd = ::date::year_month_day{dp}; - os << "TIMESTAMP '" << ymd << ' ' << time << "'"; - } - return os; - } -} -#endif