From 37b7966ab238001745e8b6ad77668d2986316880 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 Oct 2015 21:47:31 +0100 Subject: [PATCH] Split day_point and time_point --- include/sqlpp11/{date_time_fwd.h => chrono.h} | 7 +- .../data_types/boolean/expression_operators.h | 1 + include/sqlpp11/data_types/day_point.h | 213 +----------------- .../data_types/day_point/column_operators.h | 44 ++++ .../sqlpp11/data_types/day_point/data_type.h | 47 ++++ .../day_point/expression_operators.h | 44 ++++ .../sqlpp11/data_types/day_point/operand.h | 68 ++++++ .../data_types/day_point/parameter_type.h | 106 +++++++++ .../data_types/day_point/result_field.h | 108 +++++++++ .../sqlpp11/data_types/day_point/serialize.h | 66 ++++++ .../data_types/day_point/wrap_operand.h | 45 ++++ .../floating_point/expression_operators.h | 2 +- .../integral/expression_operators.h | 2 +- include/sqlpp11/data_types/text/concat.h | 4 +- .../data_types/text/expression_operators.h | 2 +- include/sqlpp11/data_types/text/like.h | 6 +- include/sqlpp11/data_types/text/operand.h | 1 + include/sqlpp11/data_types/time_point.h | 212 +---------------- .../data_types/time_point/column_operators.h | 44 ++++ .../sqlpp11/data_types/time_point/data_type.h | 45 ++++ .../time_point/expression_operators.h | 45 ++++ .../sqlpp11/data_types/time_point/operand.h | 69 ++++++ .../data_types/time_point/parameter_type.h | 107 +++++++++ .../data_types/time_point/result_field.h | 109 +++++++++ .../sqlpp11/data_types/time_point/serialize.h | 70 ++++++ .../data_types/time_point/wrap_operand.h | 41 ++++ include/sqlpp11/expression_operators.h | 41 ++++ include/sqlpp11/no_value.h | 2 +- include/sqlpp11/value_type_fwd.h | 7 - include/sqlpp11/wrap_operand.h | 116 ---------- 30 files changed, 1130 insertions(+), 544 deletions(-) rename include/sqlpp11/{date_time_fwd.h => chrono.h} (94%) create mode 100644 include/sqlpp11/data_types/day_point/column_operators.h create mode 100644 include/sqlpp11/data_types/day_point/data_type.h create mode 100644 include/sqlpp11/data_types/day_point/expression_operators.h create mode 100644 include/sqlpp11/data_types/day_point/operand.h create mode 100644 include/sqlpp11/data_types/day_point/parameter_type.h create mode 100644 include/sqlpp11/data_types/day_point/result_field.h create mode 100644 include/sqlpp11/data_types/day_point/serialize.h create mode 100644 include/sqlpp11/data_types/day_point/wrap_operand.h create mode 100644 include/sqlpp11/data_types/time_point/column_operators.h create mode 100644 include/sqlpp11/data_types/time_point/data_type.h create mode 100644 include/sqlpp11/data_types/time_point/expression_operators.h create mode 100644 include/sqlpp11/data_types/time_point/operand.h create mode 100644 include/sqlpp11/data_types/time_point/parameter_type.h create mode 100644 include/sqlpp11/data_types/time_point/result_field.h create mode 100644 include/sqlpp11/data_types/time_point/serialize.h create mode 100644 include/sqlpp11/data_types/time_point/wrap_operand.h create mode 100644 include/sqlpp11/expression_operators.h diff --git a/include/sqlpp11/date_time_fwd.h b/include/sqlpp11/chrono.h similarity index 94% rename from include/sqlpp11/date_time_fwd.h rename to include/sqlpp11/chrono.h index 3855dc1c..be62e7d9 100644 --- a/include/sqlpp11/date_time_fwd.h +++ b/include/sqlpp11/chrono.h @@ -24,8 +24,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_DATE_FWD_H -#define SQLPP_DATE_FWD_H +#ifndef SQLPP_CHRONO_H +#define SQLPP_CHRONO_H #include @@ -38,9 +38,6 @@ namespace sqlpp using day_point = std::chrono::time_point; using mus_point = std::chrono::time_point; } - - struct day_point; - struct time_point; } #endif diff --git a/include/sqlpp11/data_types/boolean/expression_operators.h b/include/sqlpp11/data_types/boolean/expression_operators.h index 0ec0f48f..d4ff9d27 100644 --- a/include/sqlpp11/data_types/boolean/expression_operators.h +++ b/include/sqlpp11/data_types/boolean/expression_operators.h @@ -27,6 +27,7 @@ #ifndef SQLPP_BOOLEAN_EXPRESSION_OPERATORS_H #define SQLPP_BOOLEAN_EXPRESSION_OPERATORS_H +#include #include namespace sqlpp diff --git a/include/sqlpp11/data_types/day_point.h b/include/sqlpp11/data_types/day_point.h index 7ca4925b..78f36460 100644 --- a/include/sqlpp11/data_types/day_point.h +++ b/include/sqlpp11/data_types/day_point.h @@ -27,210 +27,13 @@ #ifndef SQLPP_DAY_POINT_H #define SQLPP_DAY_POINT_H -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include -namespace sqlpp -{ - // day_point value type - struct day_point - { - using _traits = make_traits; - using _tag = tag::is_date; - using _cpp_value_type = ::sqlpp::chrono::day_point; - - template - using _is_valid_operand = is_time_point_t; - template - using _is_valid_assignment_operand = is_date_t; - }; - - // day_point parameter value - template <> - struct parameter_value_t - { - using _value_type = day_point; - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value{}, _is_null(true) - { - } - - explicit parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false) - { - } - - parameter_value_t& operator=(const _cpp_value_type& val) - { - _value = val; - _is_null = false; - return *this; - } - - parameter_value_t& operator=(const tvin_t>& t) - { - if (t._is_trivial()) - { - _value = _cpp_value_type{}; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - void set_null() - { - _value = _cpp_value_type{}; - _is_null = true; - } - - bool is_null() const - { - return _is_null; - } - - const _cpp_value_type& value() const - { - return _value; - } - - operator _cpp_value_type() const - { - return _value; - } - - template - void _bind(Target& target, size_t index) const - { - target._bind_date_parameter(index, &_value, _is_null); - } - - private: - _cpp_value_type _value; - bool _is_null; - }; - - // day_point expression operators - template - struct expression_operators : public basic_expression_operators - { - template - using _is_valid_operand = is_valid_operand; - }; - - // day_point column operators - template - struct column_operators - { - template - using _is_valid_operand = is_valid_operand; - }; - - // day_point result field - template - struct result_field_t - : public result_field_methods_t> - { - static_assert(std::is_same, day_point>::value, "field type mismatch"); - using _cpp_value_type = typename sqlpp::day_point::_cpp_value_type; - - result_field_t() : _is_valid(false), _is_null(true), _value{} - { - } - - void _invalidate() - { - _is_valid = false; - _is_null = true; - _value = _cpp_value_type{}; - } - - void _validate() - { - _is_valid = true; - } - - bool is_null() const - { - if (not _is_valid) - throw exception("accessing is_null in non-existing row"); - return _is_null; - } - - bool _is_trivial() const - { - if (not _is_valid) - throw exception("accessing is_null in non-existing row"); - - return value() == _cpp_value_type{}; - } - - _cpp_value_type value() const - { - if (not _is_valid) - throw exception("accessing value in non-existing row"); - - if (_is_null) - { - if (enforce_null_result_treatment_t::value and not null_is_trivial_value_t::value) - { - throw exception("accessing value of NULL field"); - } - else - { - return _cpp_value_type{}; - } - } - return _value; - } - - template - void _bind(Target& target, size_t i) - { - target._bind_date_result(i, &_value, &_is_null); - } - - private: - bool _is_valid; - bool _is_null; - _cpp_value_type _value; - }; - - template - struct serializer_t> - { - using _serialize_check = consistent_t; - using T = result_field_t; - - static Context& _(const T& t, Context& context) - { - if (t.is_null() and not null_is_trivial_value_t::value) - { - context << "NULL"; - } - else - { - const auto ymd = ::date::year_month_day{t.value()}; - context << ymd; - } - 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/column_operators.h b/include/sqlpp11/data_types/day_point/column_operators.h new file mode 100644 index 00000000..ba2788cb --- /dev/null +++ b/include/sqlpp11/data_types/day_point/column_operators.h @@ -0,0 +1,44 @@ +/* + * 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_COLUMN_OPERATORS_H +#define SQLPP_DAY_POINT_COLUMN_OPERATORS_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct column_operators + { + template + using _is_valid_operand = is_valid_operand; + }; +} +#endif diff --git a/include/sqlpp11/data_types/day_point/data_type.h b/include/sqlpp11/data_types/day_point/data_type.h new file mode 100644 index 00000000..abd7ba8a --- /dev/null +++ b/include/sqlpp11/data_types/day_point/data_type.h @@ -0,0 +1,47 @@ +/* + * 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_DATA_TYPE_H +#define SQLPP_DAY_POINT_DATA_TYPE_H + +#include +#include + +namespace sqlpp +{ + struct day_point + { + using _traits = make_traits; + using _tag = tag::is_date; + using _cpp_value_type = ::sqlpp::chrono::day_point; + + template + using _is_valid_operand = is_time_point_t; + template + using _is_valid_assignment_operand = is_date_t; + }; +} +#endif diff --git a/include/sqlpp11/data_types/day_point/expression_operators.h b/include/sqlpp11/data_types/day_point/expression_operators.h new file mode 100644 index 00000000..f6877d0b --- /dev/null +++ b/include/sqlpp11/data_types/day_point/expression_operators.h @@ -0,0 +1,44 @@ +/* + * 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_EXPRESSION_OPERATORS_H +#define SQLPP_DAY_POINT_EXPRESSION_OPERATORS_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct expression_operators : public basic_expression_operators + { + template + using _is_valid_operand = is_valid_operand; + }; +} +#endif diff --git a/include/sqlpp11/data_types/day_point/operand.h b/include/sqlpp11/data_types/day_point/operand.h new file mode 100644 index 00000000..68d16d46 --- /dev/null +++ b/include/sqlpp11/data_types/day_point/operand.h @@ -0,0 +1,68 @@ +/* + * 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_OPERAND_H +#define SQLPP_DAY_POINT_OPERAND_H + +#include +#include +#include + +namespace sqlpp +{ + struct day_point; + + struct day_point_operand : public alias_operators + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = ::sqlpp::chrono::day_point; + + day_point_operand() : _t{} + { + } + + day_point_operand(_value_t t) : _t(t) + { + } + + day_point_operand(const day_point_operand&) = default; + day_point_operand(day_point_operand&&) = default; + day_point_operand& operator=(const day_point_operand&) = default; + day_point_operand& operator=(day_point_operand&&) = default; + ~day_point_operand() = default; + + bool _is_trivial() const + { + return _t == _value_t{}; + } + + _value_t _t; + }; +} +#endif diff --git a/include/sqlpp11/data_types/day_point/parameter_type.h b/include/sqlpp11/data_types/day_point/parameter_type.h new file mode 100644 index 00000000..6ff2ac4c --- /dev/null +++ b/include/sqlpp11/data_types/day_point/parameter_type.h @@ -0,0 +1,106 @@ +/* + * 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_PARAMETER_TYPE_H +#define SQLPP_DAY_POINT_PARAMETER_TYPE_H + +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t + { + using _value_type = day_point; + using _cpp_value_type = typename _value_type::_cpp_value_type; + + parameter_value_t() : _value{}, _is_null(true) + { + } + + explicit parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false) + { + } + + parameter_value_t& operator=(const _cpp_value_type& val) + { + _value = val; + _is_null = false; + return *this; + } + + parameter_value_t& operator=(const tvin_t>& t) + { + if (t._is_trivial()) + { + _value = _cpp_value_type{}; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + + void set_null() + { + _value = _cpp_value_type{}; + _is_null = true; + } + + bool is_null() const + { + return _is_null; + } + + const _cpp_value_type& value() const + { + return _value; + } + + operator _cpp_value_type() const + { + return _value; + } + + template + void _bind(Target& target, size_t index) const + { + target._bind_date_parameter(index, &_value, _is_null); + } + + private: + _cpp_value_type _value; + bool _is_null; + }; +} +#endif diff --git a/include/sqlpp11/data_types/day_point/result_field.h b/include/sqlpp11/data_types/day_point/result_field.h new file mode 100644 index 00000000..cebdda71 --- /dev/null +++ b/include/sqlpp11/data_types/day_point/result_field.h @@ -0,0 +1,108 @@ +/* + * 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_RESULT_FIELD_H +#define SQLPP_DAY_POINT_RESULT_FIELD_H + +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct result_field_t + : public result_field_methods_t> + { + static_assert(std::is_same, day_point>::value, "field type mismatch"); + using _cpp_value_type = typename sqlpp::day_point::_cpp_value_type; + + result_field_t() : _is_valid(false), _is_null(true), _value{} + { + } + + void _invalidate() + { + _is_valid = false; + _is_null = true; + _value = _cpp_value_type{}; + } + + void _validate() + { + _is_valid = true; + } + + bool is_null() const + { + if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + return _is_null; + } + + bool _is_trivial() const + { + if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + + return value() == _cpp_value_type{}; + } + + _cpp_value_type value() const + { + if (not _is_valid) + throw exception("accessing value in non-existing row"); + + if (_is_null) + { + if (enforce_null_result_treatment_t::value and not null_is_trivial_value_t::value) + { + throw exception("accessing value of NULL field"); + } + else + { + return _cpp_value_type{}; + } + } + return _value; + } + + template + void _bind(Target& target, size_t i) + { + target._bind_date_result(i, &_value, &_is_null); + } + + private: + bool _is_valid; + bool _is_null; + _cpp_value_type _value; + }; +} +#endif diff --git a/include/sqlpp11/data_types/day_point/serialize.h b/include/sqlpp11/data_types/day_point/serialize.h new file mode 100644 index 00000000..e7bca1e7 --- /dev/null +++ b/include/sqlpp11/data_types/day_point/serialize.h @@ -0,0 +1,66 @@ +/* + * 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/day_point/wrap_operand.h b/include/sqlpp11/data_types/day_point/wrap_operand.h new file mode 100644 index 00000000..a695cb24 --- /dev/null +++ b/include/sqlpp11/data_types/day_point/wrap_operand.h @@ -0,0 +1,45 @@ +/* + * 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_WRAP_OPERAND_H +#define SQLPP_DAY_POINT_WRAP_OPERAND_H + +#include +#include +#include +#include + +namespace sqlpp +{ + struct day_point_operand; + + template <> + struct wrap_operand, void> + { + using type = day_point_operand; + }; +} +#endif diff --git a/include/sqlpp11/data_types/floating_point/expression_operators.h b/include/sqlpp11/data_types/floating_point/expression_operators.h index 773eebca..e218fe98 100644 --- a/include/sqlpp11/data_types/floating_point/expression_operators.h +++ b/include/sqlpp11/data_types/floating_point/expression_operators.h @@ -27,10 +27,10 @@ #ifndef SQLPP_FLOATING_POINT_EXPRESSION_OPERATORS_H #define SQLPP_FLOATING_POINT_EXPRESSION_OPERATORS_H +#include #include #include #include -#include namespace sqlpp { diff --git a/include/sqlpp11/data_types/integral/expression_operators.h b/include/sqlpp11/data_types/integral/expression_operators.h index 5dc1d0af..2cfe3be9 100644 --- a/include/sqlpp11/data_types/integral/expression_operators.h +++ b/include/sqlpp11/data_types/integral/expression_operators.h @@ -27,11 +27,11 @@ #ifndef SQLPP_INTEGRAL_EXPRESSION_OPERATORS_H #define SQLPP_INTEGRAL_EXPRESSION_OPERATORS_H +#include #include #include #include #include -#include namespace sqlpp { diff --git a/include/sqlpp11/data_types/text/concat.h b/include/sqlpp11/data_types/text/concat.h index dba4cddc..25164882 100644 --- a/include/sqlpp11/data_types/text/concat.h +++ b/include/sqlpp11/data_types/text/concat.h @@ -30,8 +30,10 @@ #include #include #include -#include +#include +#include #include +#include namespace sqlpp { diff --git a/include/sqlpp11/data_types/text/expression_operators.h b/include/sqlpp11/data_types/text/expression_operators.h index 01d9ccb7..e9b4681e 100644 --- a/include/sqlpp11/data_types/text/expression_operators.h +++ b/include/sqlpp11/data_types/text/expression_operators.h @@ -27,10 +27,10 @@ #ifndef SQLPP_TEXT_EXPRESSION_OPERATORS_H #define SQLPP_TEXT_EXPRESSION_OPERATORS_H +#include #include #include #include -#include namespace sqlpp { diff --git a/include/sqlpp11/data_types/text/like.h b/include/sqlpp11/data_types/text/like.h index 68b2f84e..dc86f211 100644 --- a/include/sqlpp11/data_types/text/like.h +++ b/include/sqlpp11/data_types/text/like.h @@ -27,13 +27,15 @@ #ifndef SQLPP_LIKE_H #define SQLPP_LIKE_H -#include +#include +#include #include #include -#include namespace sqlpp { + struct boolean; + template struct like_t : public expression_operators, boolean>, public alias_operators> diff --git a/include/sqlpp11/data_types/text/operand.h b/include/sqlpp11/data_types/text/operand.h index a73341e2..8b1fc6a4 100644 --- a/include/sqlpp11/data_types/text/operand.h +++ b/include/sqlpp11/data_types/text/operand.h @@ -27,6 +27,7 @@ #ifndef SQLPP_TEXT_OPERAND_H #define SQLPP_TEXT_OPERAND_H +#include #include #include diff --git a/include/sqlpp11/data_types/time_point.h b/include/sqlpp11/data_types/time_point.h index a1686366..cbf90688 100644 --- a/include/sqlpp11/data_types/time_point.h +++ b/include/sqlpp11/data_types/time_point.h @@ -27,209 +27,13 @@ #ifndef SQLPP_TIME_POINT_H #define SQLPP_TIME_POINT_H -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include -namespace sqlpp -{ - // time_point value type - struct time_point - { - using _traits = make_traits; - using _tag = tag::is_date_time; - using _cpp_value_type = ::sqlpp::chrono::mus_point; - - template - using _is_valid_operand = is_time_point_t; - }; - - // time_point parameter value - template <> - struct parameter_value_t - { - using _value_type = time_point; - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value{}, _is_null(true) - { - } - - explicit parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false) - { - } - - parameter_value_t& operator=(const _cpp_value_type& val) - { - _value = val; - _is_null = false; - return *this; - } - - parameter_value_t& operator=(const tvin_t>& t) - { - if (t._is_trivial()) - { - _value = _cpp_value_type{}; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - void set_null() - { - _value = _cpp_value_type{}; - _is_null = true; - } - - bool is_null() const - { - return _is_null; - } - - const _cpp_value_type& value() const - { - return _value; - } - - operator _cpp_value_type() const - { - return _value; - } - - template - void _bind(Target& target, size_t index) const - { - target._bind_date_time_parameter(index, &_value, _is_null); - } - - private: - _cpp_value_type _value; - bool _is_null; - }; - - // time_point expression operators - template - struct expression_operators : public basic_expression_operators - { - template - using _is_valid_operand = is_valid_operand; - }; - - // time_point column operators - template - struct column_operators - { - template - using _is_valid_operand = is_valid_operand; - }; - - // time_point result field - template - struct result_field_t - : public result_field_methods_t> - { - static_assert(std::is_same, time_point>::value, "field type mismatch"); - using _cpp_value_type = typename time_point::_cpp_value_type; - - result_field_t() : _is_valid(false), _is_null(true), _value{} - { - } - - void _invalidate() - { - _is_valid = false; - _is_null = true; - _value = _cpp_value_type{}; - } - - void _validate() - { - _is_valid = true; - } - - bool is_null() const - { - if (not _is_valid) - throw exception("accessing is_null in non-existing row"); - return _is_null; - } - - bool _is_trivial() const - { - if (not _is_valid) - throw exception("accessing is_null in non-existing row"); - - return value() == _cpp_value_type{}; - } - - _cpp_value_type value() const - { - if (not _is_valid) - throw exception("accessing value in non-existing row"); - - if (_is_null) - { - if (enforce_null_result_treatment_t::value and not null_is_trivial_value_t::value) - { - throw exception("accessing value of NULL field"); - } - else - { - return _cpp_value_type{}; - } - } - return _value; - } - - template - void _bind(Target& target, size_t i) - { - target._bind_date_time_result(i, &_value, &_is_null); - } - - private: - bool _is_valid; - bool _is_null; - _cpp_value_type _value; - }; - - template - struct serializer_t> - { - using _serialize_check = consistent_t; - using T = result_field_t; - - static Context& _(const T& t, Context& context) - { - if (t.is_null() and not null_is_trivial_value_t::value) - { - context << "NULL"; - } - else - { - const auto dp = ::date::floor<::date::days>(t.value()); - const auto time = ::date::make_time(t.value() - dp); - const auto ymd = ::date::year_month_day{dp}; - context << ymd << ' ' << time; - } - 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/time_point/column_operators.h b/include/sqlpp11/data_types/time_point/column_operators.h new file mode 100644 index 00000000..12ec8482 --- /dev/null +++ b/include/sqlpp11/data_types/time_point/column_operators.h @@ -0,0 +1,44 @@ +/* + * 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_COLUMN_OPERATOR_H +#define SQLPP_TIME_POINT_COLUMN_OPERATOR_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct column_operators + { + template + using _is_valid_operand = is_valid_operand; + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_point/data_type.h b/include/sqlpp11/data_types/time_point/data_type.h new file mode 100644 index 00000000..f64be70d --- /dev/null +++ b/include/sqlpp11/data_types/time_point/data_type.h @@ -0,0 +1,45 @@ +/* + * 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_DATA_TYPE_H +#define SQLPP_TIME_POINT_DATA_TYPE_H + +#include +#include + +namespace sqlpp +{ + struct time_point + { + using _traits = make_traits; + using _tag = tag::is_date_time; + using _cpp_value_type = ::sqlpp::chrono::mus_point; + + template + using _is_valid_operand = is_time_point_t; + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_point/expression_operators.h b/include/sqlpp11/data_types/time_point/expression_operators.h new file mode 100644 index 00000000..9bcc3674 --- /dev/null +++ b/include/sqlpp11/data_types/time_point/expression_operators.h @@ -0,0 +1,45 @@ +/* + * 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_EXPRESSION_OPERATORS_H +#define SQLPP_TIME_POINT_EXPRESSION_OPERATORS_H + +#include +#include +#include +#include + +namespace sqlpp +{ + // time_point expression operators + template + struct expression_operators : public basic_expression_operators + { + template + using _is_valid_operand = is_valid_operand; + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_point/operand.h b/include/sqlpp11/data_types/time_point/operand.h new file mode 100644 index 00000000..e3b78b57 --- /dev/null +++ b/include/sqlpp11/data_types/time_point/operand.h @@ -0,0 +1,69 @@ +/* + * 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_OPERAND_H +#define SQLPP_TIME_POINT_OPERAND_H + +#include +#include +#include + +namespace sqlpp +{ + struct time_point; + + template + struct time_point_operand : public alias_operators> + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = std::chrono::time_point; + + time_point_operand() : _t{} + { + } + + time_point_operand(_value_t t) : _t(t) + { + } + + time_point_operand(const time_point_operand&) = default; + time_point_operand(time_point_operand&&) = default; + time_point_operand& operator=(const time_point_operand&) = default; + time_point_operand& operator=(time_point_operand&&) = default; + ~time_point_operand() = default; + + bool _is_trivial() const + { + return _t == _value_t{}; + } + + _value_t _t; + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_point/parameter_type.h b/include/sqlpp11/data_types/time_point/parameter_type.h new file mode 100644 index 00000000..5e61b7c6 --- /dev/null +++ b/include/sqlpp11/data_types/time_point/parameter_type.h @@ -0,0 +1,107 @@ +/* + * 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_PARAMETER_TYPE_H +#define SQLPP_TIME_POINT_PARAMETER_TYPE_H + +#include +#include +#include +#include +#include + +namespace sqlpp +{ + // time_point parameter value + template <> + struct parameter_value_t + { + using _value_type = time_point; + using _cpp_value_type = typename _value_type::_cpp_value_type; + + parameter_value_t() : _value{}, _is_null(true) + { + } + + explicit parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false) + { + } + + parameter_value_t& operator=(const _cpp_value_type& val) + { + _value = val; + _is_null = false; + return *this; + } + + parameter_value_t& operator=(const tvin_t>& t) + { + if (t._is_trivial()) + { + _value = _cpp_value_type{}; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + + void set_null() + { + _value = _cpp_value_type{}; + _is_null = true; + } + + bool is_null() const + { + return _is_null; + } + + const _cpp_value_type& value() const + { + return _value; + } + + operator _cpp_value_type() const + { + return _value; + } + + template + void _bind(Target& target, size_t index) const + { + target._bind_date_time_parameter(index, &_value, _is_null); + } + + private: + _cpp_value_type _value; + bool _is_null; + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_point/result_field.h b/include/sqlpp11/data_types/time_point/result_field.h new file mode 100644 index 00000000..edee6be4 --- /dev/null +++ b/include/sqlpp11/data_types/time_point/result_field.h @@ -0,0 +1,109 @@ +/* + * 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_RESULT_FIELD_H +#define SQLPP_TIME_POINT_RESULT_FIELD_H + +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + // time_point result field + template + struct result_field_t + : public result_field_methods_t> + { + static_assert(std::is_same, time_point>::value, "field type mismatch"); + using _cpp_value_type = typename time_point::_cpp_value_type; + + result_field_t() : _is_valid(false), _is_null(true), _value{} + { + } + + void _invalidate() + { + _is_valid = false; + _is_null = true; + _value = _cpp_value_type{}; + } + + void _validate() + { + _is_valid = true; + } + + bool is_null() const + { + if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + return _is_null; + } + + bool _is_trivial() const + { + if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + + return value() == _cpp_value_type{}; + } + + _cpp_value_type value() const + { + if (not _is_valid) + throw exception("accessing value in non-existing row"); + + if (_is_null) + { + if (enforce_null_result_treatment_t::value and not null_is_trivial_value_t::value) + { + throw exception("accessing value of NULL field"); + } + else + { + return _cpp_value_type{}; + } + } + return _value; + } + + template + void _bind(Target& target, size_t i) + { + target._bind_date_time_result(i, &_value, &_is_null); + } + + private: + bool _is_valid; + bool _is_null; + _cpp_value_type _value; + }; +} +#endif diff --git a/include/sqlpp11/data_types/time_point/serialize.h b/include/sqlpp11/data_types/time_point/serialize.h new file mode 100644 index 00000000..a3d0f736 --- /dev/null +++ b/include/sqlpp11/data_types/time_point/serialize.h @@ -0,0 +1,70 @@ +/* + * 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 diff --git a/include/sqlpp11/data_types/time_point/wrap_operand.h b/include/sqlpp11/data_types/time_point/wrap_operand.h new file mode 100644 index 00000000..0e52d46c --- /dev/null +++ b/include/sqlpp11/data_types/time_point/wrap_operand.h @@ -0,0 +1,41 @@ +/* + * 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_WRAP_OPERAND_H +#define SQLPP_TIME_POINT_WRAP_OPERAND_H + +#include +#include + +namespace sqlpp +{ + template + struct wrap_operand, void> + { + using type = time_point_operand; + }; +} +#endif diff --git a/include/sqlpp11/expression_operators.h b/include/sqlpp11/expression_operators.h new file mode 100644 index 00000000..2ead994a --- /dev/null +++ b/include/sqlpp11/expression_operators.h @@ -0,0 +1,41 @@ +/* + * 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_EXPRESSION_OPERATORS_H +#define SQLPP_EXPRESSION_OPERATORS_H + +#include + +namespace sqlpp +{ + template + struct expression_operators + { + static_assert(wrong_t::value, "Missing expression operators for ValueType"); + }; +} + +#endif diff --git a/include/sqlpp11/no_value.h b/include/sqlpp11/no_value.h index 2cdcbc6f..ee5f2715 100644 --- a/include/sqlpp11/no_value.h +++ b/include/sqlpp11/no_value.h @@ -28,7 +28,7 @@ #define SQLPP_NO_VALUE_H #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/value_type_fwd.h b/include/sqlpp11/value_type_fwd.h index 5b105b18..9c3a641b 100644 --- a/include/sqlpp11/value_type_fwd.h +++ b/include/sqlpp11/value_type_fwd.h @@ -27,17 +27,10 @@ #ifndef SQLPP_VALUE_TYPE_FWD_H #define SQLPP_VALUE_TYPE_FWD_H -#include #include namespace sqlpp { - template - struct expression_operators - { - static_assert(wrong_t::value, "Missing expression operators for ValueType"); - }; - template struct is_valid_assignment_operand { diff --git a/include/sqlpp11/wrap_operand.h b/include/sqlpp11/wrap_operand.h index 02edabad..9cbf5929 100644 --- a/include/sqlpp11/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -39,120 +39,4 @@ namespace sqlpp using wrap_operand_t = typename wrap_operand::type; } -#include -#include -#include -#include -#include -#include -#include - -namespace sqlpp -{ - struct integral; - - struct day_point_operand : public alias_operators - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - using _is_aggregate_expression = std::true_type; - - using _value_t = ::sqlpp::chrono::day_point; - - day_point_operand() : _t{} - { - } - - day_point_operand(_value_t t) : _t(t) - { - } - - day_point_operand(const day_point_operand&) = default; - day_point_operand(day_point_operand&&) = default; - day_point_operand& operator=(const day_point_operand&) = default; - day_point_operand& operator=(day_point_operand&&) = default; - ~day_point_operand() = default; - - bool _is_trivial() const - { - return _t == _value_t{}; - } - - _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; - } - }; - - template - struct time_point_operand : public alias_operators> - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - using _is_aggregate_expression = std::true_type; - - using _value_t = std::chrono::time_point; - - time_point_operand() : _t{} - { - } - - time_point_operand(_value_t t) : _t(t) - { - } - - time_point_operand(const time_point_operand&) = default; - time_point_operand(time_point_operand&&) = default; - time_point_operand& operator=(const time_point_operand&) = default; - time_point_operand& operator=(time_point_operand&&) = default; - ~time_point_operand() = default; - - bool _is_trivial() const - { - return _t == _value_t{}; - } - - _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; - } - }; - - template - struct wrap_operand, void> - { - using type = time_point_operand; - }; - - template <> - struct wrap_operand, void> - { - using type = day_point_operand; - }; -} - #endif