From 173d6adbc90660942fd203b7b677c57a95f591d4 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 29 Oct 2015 22:21:46 +0100 Subject: [PATCH 01/30] Moved data types into separate folder, split boolean Each file within data_types/boolean/ is relatively short and easy to grok. --- examples/Sample.h | 2 +- include/sqlpp11/alias_operators.h | 44 +++ include/sqlpp11/any.h | 2 +- include/sqlpp11/basic_expression_operators.h | 13 +- include/sqlpp11/column_types.h | 8 +- include/sqlpp11/count.h | 2 +- include/sqlpp11/data_types.h | 37 +++ include/sqlpp11/data_types/boolean.h | 39 +++ .../boolean/column_operators.h} | 16 +- .../sqlpp11/data_types/boolean/data_type.h | 45 +++ .../data_types/boolean/expression_operators.h | 65 ++++ include/sqlpp11/data_types/boolean/operand.h | 68 ++++ .../data_types/boolean/parameter_type.h | 108 ++++++ .../boolean/result_field.h} | 134 +------- .../sqlpp11/data_types/boolean/serialize.h | 57 ++++ .../sqlpp11/data_types/boolean/wrap_operand.h | 43 +++ include/sqlpp11/data_types/column_operators.h | 41 +++ include/sqlpp11/{ => data_types}/day_point.h | 2 +- .../sqlpp11/{ => data_types}/floating_point.h | 0 include/sqlpp11/{ => data_types}/integral.h | 0 include/sqlpp11/data_types/parameter_value.h | 41 +++ include/sqlpp11/{ => data_types}/text.h | 0 include/sqlpp11/{ => data_types}/time_point.h | 0 include/sqlpp11/data_types/wrap_operand.h | 308 ++++++++++++++++++ include/sqlpp11/exists.h | 2 +- include/sqlpp11/expression.h | 2 +- include/sqlpp11/functions.h | 2 +- include/sqlpp11/in.h | 2 +- include/sqlpp11/is_not_null.h | 2 +- include/sqlpp11/is_null.h | 2 +- include/sqlpp11/like.h | 2 +- include/sqlpp11/no_value.h | 1 + include/sqlpp11/not_in.h | 2 +- include/sqlpp11/result_field_methods.h | 1 + include/sqlpp11/result_row.h | 2 +- include/sqlpp11/some.h | 2 +- include/sqlpp11/sort_order.h | 3 +- include/sqlpp11/sqlpp11.h | 2 +- include/sqlpp11/value_or_null.h | 3 +- include/sqlpp11/value_type_fwd.h | 12 - include/sqlpp11/wrap_operand.h | 70 +--- scripts/ddl2cpp | 2 +- test_static_asserts/AssertTables.h | 2 +- tests/Sample.h | 2 +- 44 files changed, 950 insertions(+), 243 deletions(-) create mode 100644 include/sqlpp11/alias_operators.h create mode 100644 include/sqlpp11/data_types.h create mode 100644 include/sqlpp11/data_types/boolean.h rename include/sqlpp11/{wrap_operand_fwd.h => data_types/boolean/column_operators.h} (85%) create mode 100644 include/sqlpp11/data_types/boolean/data_type.h create mode 100644 include/sqlpp11/data_types/boolean/expression_operators.h create mode 100644 include/sqlpp11/data_types/boolean/operand.h create mode 100644 include/sqlpp11/data_types/boolean/parameter_type.h rename include/sqlpp11/{boolean.h => data_types/boolean/result_field.h} (51%) create mode 100644 include/sqlpp11/data_types/boolean/serialize.h create mode 100644 include/sqlpp11/data_types/boolean/wrap_operand.h create mode 100644 include/sqlpp11/data_types/column_operators.h rename include/sqlpp11/{ => data_types}/day_point.h (99%) rename include/sqlpp11/{ => data_types}/floating_point.h (100%) rename include/sqlpp11/{ => data_types}/integral.h (100%) create mode 100644 include/sqlpp11/data_types/parameter_value.h rename include/sqlpp11/{ => data_types}/text.h (100%) rename include/sqlpp11/{ => data_types}/time_point.h (100%) create mode 100644 include/sqlpp11/data_types/wrap_operand.h diff --git a/examples/Sample.h b/examples/Sample.h index a4512a88..da542f0d 100644 --- a/examples/Sample.h +++ b/examples/Sample.h @@ -2,7 +2,7 @@ #define TEST_SAMPLE_H #include -#include +#include #include // clang-format off diff --git a/include/sqlpp11/alias_operators.h b/include/sqlpp11/alias_operators.h new file mode 100644 index 00000000..0a03eb3f --- /dev/null +++ b/include/sqlpp11/alias_operators.h @@ -0,0 +1,44 @@ +/* + * 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_ALIAS_OPERATORS_H +#define SQLPP_ALIAS_OPERATORS_H + +#include + +namespace sqlpp +{ + template + struct alias_operators + { + template + expression_alias_t as(const alias_provider&) const + { + return {*static_cast(this)}; + } + }; +} +#endif diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h index f7d7885b..d3f125c2 100644 --- a/include/sqlpp11/any.h +++ b/include/sqlpp11/any.h @@ -27,7 +27,7 @@ #ifndef SQLPP_ANY_H #define SQLPP_ANY_H -#include +#include #include #include diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 0f60e025..3b66a8ae 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include namespace sqlpp @@ -219,15 +219,6 @@ namespace sqlpp return {*static_cast(this), wrap_operand_t{t}...}; } }; - - template - struct alias_operators - { - template - expression_alias_t as(const alias_provider&) const - { - return {*static_cast(this)}; - } - }; } + #endif diff --git a/include/sqlpp11/column_types.h b/include/sqlpp11/column_types.h index bfc28128..d9891f71 100644 --- a/include/sqlpp11/column_types.h +++ b/include/sqlpp11/column_types.h @@ -27,11 +27,7 @@ #ifndef SQLPP_COLUMN_TYPES_H #define SQLPP_COLUMN_TYPES_H -#include -#include -#include -#include -#include -#include +#warning column_types.h is deprecated, please include data_types.h instead +#include #endif diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 6c50c599..62e85225 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/data_types.h b/include/sqlpp11/data_types.h new file mode 100644 index 00000000..9e50cf9d --- /dev/null +++ b/include/sqlpp11/data_types.h @@ -0,0 +1,37 @@ +/* + * 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_DATA_TYPES_H +#define SQLPP_DATA_TYPES_H + +#include +#include +#include +#include +#include +#include + +#endif diff --git a/include/sqlpp11/data_types/boolean.h b/include/sqlpp11/data_types/boolean.h new file mode 100644 index 00000000..d80f9134 --- /dev/null +++ b/include/sqlpp11/data_types/boolean.h @@ -0,0 +1,39 @@ +/* + * 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_H +#define SQLPP_BOOLEAN_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/include/sqlpp11/wrap_operand_fwd.h b/include/sqlpp11/data_types/boolean/column_operators.h similarity index 85% rename from include/sqlpp11/wrap_operand_fwd.h rename to include/sqlpp11/data_types/boolean/column_operators.h index 2659c444..d5d37f9c 100644 --- a/include/sqlpp11/wrap_operand_fwd.h +++ b/include/sqlpp11/data_types/boolean/column_operators.h @@ -24,16 +24,18 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_DETAIL_WRAP_OPERAND_FWD_H -#define SQLPP_DETAIL_WRAP_OPERAND_FWD_H +#ifndef SQLPP_BOOLEAN_COLUMN_OPERATORS_H +#define SQLPP_BOOLEAN_COLUMN_OPERATORS_H + +#include namespace sqlpp { - template - struct wrap_operand; + struct boolean; - template - using wrap_operand_t = typename wrap_operand::type; + template + struct column_operators + { + }; } - #endif diff --git a/include/sqlpp11/data_types/boolean/data_type.h b/include/sqlpp11/data_types/boolean/data_type.h new file mode 100644 index 00000000..855bb50e --- /dev/null +++ b/include/sqlpp11/data_types/boolean/data_type.h @@ -0,0 +1,45 @@ +/* + * 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_DATA_TYPE_H +#define SQLPP_BOOLEAN_DATA_TYPE_H + +#include + +namespace sqlpp +{ + struct boolean + { + using _traits = make_traits; + using _tag = tag::is_boolean; + using _cpp_value_type = bool; + + template + using _is_valid_operand = is_boolean_t; + }; +} + +#endif diff --git a/include/sqlpp11/data_types/boolean/expression_operators.h b/include/sqlpp11/data_types/boolean/expression_operators.h new file mode 100644 index 00000000..0ec0f48f --- /dev/null +++ b/include/sqlpp11/data_types/boolean/expression_operators.h @@ -0,0 +1,65 @@ +/* + * 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_EXPRESSION_OPERATORS_H +#define SQLPP_BOOLEAN_EXPRESSION_OPERATORS_H + +#include + +namespace sqlpp +{ + template + struct expression_operators : public basic_expression_operators + { + template + using _is_valid_operand = is_valid_operand; + + template + logical_and_t> operator and(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), rhs{t}}; + } + + template + logical_or_t> operator or(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), rhs{t}}; + } + + logical_not_t operator not() const + { + return {*static_cast(this)}; + } + }; +} + +#endif diff --git a/include/sqlpp11/data_types/boolean/operand.h b/include/sqlpp11/data_types/boolean/operand.h new file mode 100644 index 00000000..14d820b6 --- /dev/null +++ b/include/sqlpp11/data_types/boolean/operand.h @@ -0,0 +1,68 @@ +/* + * 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_OPERAND_H +#define SQLPP_BOOLEAN_OPERAND_H + +#include +#include + +namespace sqlpp +{ + struct boolean; + + struct boolean_operand : public alias_operators + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = bool; + + boolean_operand() : _t{} + { + } + + boolean_operand(_value_t t) : _t(t) + { + } + + boolean_operand(const boolean_operand&) = default; + boolean_operand(boolean_operand&&) = default; + boolean_operand& operator=(const boolean_operand&) = default; + boolean_operand& operator=(boolean_operand&&) = default; + ~boolean_operand() = default; + + bool _is_trivial() const + { + return _t == false; + } + + _value_t _t; + }; +} + +#endif diff --git a/include/sqlpp11/data_types/boolean/parameter_type.h b/include/sqlpp11/data_types/boolean/parameter_type.h new file mode 100644 index 00000000..33d715a6 --- /dev/null +++ b/include/sqlpp11/data_types/boolean/parameter_type.h @@ -0,0 +1,108 @@ +/* + * 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_PARAMETER_TYPE_H +#define SQLPP_BOOLEAN_PARAMETER_TYPE_H + +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t + { + using _value_type = boolean; // FIXME + using _cpp_value_type = typename _value_type::_cpp_value_type; + + parameter_value_t() : _value(false), _is_null(true) + { + } + + 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 = false; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + + parameter_value_t& operator=(const std::nullptr_t&) + { + _value = false; + _is_null = true; + return *this; + } + + bool is_null() const + { + return _is_null; + } + + _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_boolean_parameter(index, &_value, _is_null); + } + + private: + signed char _value; + bool _is_null; + }; +} + +#endif diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/data_types/boolean/result_field.h similarity index 51% rename from include/sqlpp11/boolean.h rename to include/sqlpp11/data_types/boolean/result_field.h index 620c5715..404ecd78 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/data_types/boolean/result_field.h @@ -24,138 +24,18 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_BOOLEAN_H -#define SQLPP_BOOLEAN_H +#ifndef SQLPP_BOOLEAN_RESULT_FIELD_H +#define SQLPP_BOOLEAN_RESULT_FIELD_H -#include -#include #include +#include #include #include -#include #include +#include namespace sqlpp { - // boolean value type - struct boolean - { - using _traits = make_traits; - using _tag = tag::is_boolean; - using _cpp_value_type = bool; - - template - using _is_valid_operand = is_boolean_t; - }; - - // boolean parameter type - template <> - struct parameter_value_t - { - using _value_type = boolean; // FIXME - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value(false), _is_null(true) - { - } - - 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 = false; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - parameter_value_t& operator=(const std::nullptr_t&) - { - _value = false; - _is_null = true; - return *this; - } - - bool is_null() const - { - return _is_null; - } - - _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_boolean_parameter(index, &_value, _is_null); - } - - private: - signed char _value; - bool _is_null; - }; - - // boolean expression operators - template - struct expression_operators : public basic_expression_operators - { - template - using _is_valid_operand = is_valid_operand; - - template - logical_and_t> operator and(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), rhs{t}}; - } - - template - logical_or_t> operator or(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), rhs{t}}; - } - - logical_not_t operator not() const - { - return {*static_cast(this)}; - } - }; - - // boolean column operators - template - struct column_operators - { - }; - - // boolean result field template struct result_field_t : public result_field_methods_t> { @@ -223,11 +103,5 @@ 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 new file mode 100644 index 00000000..85bfc980 --- /dev/null +++ b/include/sqlpp11/data_types/boolean/serialize.h @@ -0,0 +1,57 @@ +/* + * 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/boolean/wrap_operand.h b/include/sqlpp11/data_types/boolean/wrap_operand.h new file mode 100644 index 00000000..ba0ec29e --- /dev/null +++ b/include/sqlpp11/data_types/boolean/wrap_operand.h @@ -0,0 +1,43 @@ +/* + * 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_WRAP_OPERAND_H +#define SQLPP_BOOLEAN_WRAP_OPERAND_H + +#include + +namespace sqlpp +{ + struct boolean_operand; + + template <> + struct wrap_operand + { + using type = boolean_operand; + }; +} + +#endif diff --git a/include/sqlpp11/data_types/column_operators.h b/include/sqlpp11/data_types/column_operators.h new file mode 100644 index 00000000..f57511ae --- /dev/null +++ b/include/sqlpp11/data_types/column_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_COLUMN_OPERATORS_H +#define SQLPP_COLUMN_OPERATORS_H + +#include + +namespace sqlpp +{ + template + struct column_operators + { + static_assert(wrong_t::value, "Missing column operators for ValueType"); + }; +} + +#endif diff --git a/include/sqlpp11/day_point.h b/include/sqlpp11/data_types/day_point.h similarity index 99% rename from include/sqlpp11/day_point.h rename to include/sqlpp11/data_types/day_point.h index 31072a7e..7ca4925b 100644 --- a/include/sqlpp11/day_point.h +++ b/include/sqlpp11/data_types/day_point.h @@ -28,7 +28,7 @@ #define SQLPP_DAY_POINT_H #include -#include +#include #include #include #include diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/data_types/floating_point.h similarity index 100% rename from include/sqlpp11/floating_point.h rename to include/sqlpp11/data_types/floating_point.h diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/data_types/integral.h similarity index 100% rename from include/sqlpp11/integral.h rename to include/sqlpp11/data_types/integral.h diff --git a/include/sqlpp11/data_types/parameter_value.h b/include/sqlpp11/data_types/parameter_value.h new file mode 100644 index 00000000..1fbcc5a7 --- /dev/null +++ b/include/sqlpp11/data_types/parameter_value.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_PARAMETER_VALUE_H +#define SQLPP_PARAMETER_VALUE_H + +#include + +namespace sqlpp +{ + template + struct parameter_value_t + { + static_assert(wrong_t::value, "Missing parameter value type for ValueType"); + }; +} + +#endif diff --git a/include/sqlpp11/text.h b/include/sqlpp11/data_types/text.h similarity index 100% rename from include/sqlpp11/text.h rename to include/sqlpp11/data_types/text.h diff --git a/include/sqlpp11/time_point.h b/include/sqlpp11/data_types/time_point.h similarity index 100% rename from include/sqlpp11/time_point.h rename to include/sqlpp11/data_types/time_point.h diff --git a/include/sqlpp11/data_types/wrap_operand.h b/include/sqlpp11/data_types/wrap_operand.h new file mode 100644 index 00000000..5eee8dc7 --- /dev/null +++ b/include/sqlpp11/data_types/wrap_operand.h @@ -0,0 +1,308 @@ +/* + * 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_DETAIL_WRAP_OPERAND_H +#define SQLPP_DETAIL_WRAP_OPERAND_H + +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + struct integral; + struct floating_point; + struct text; + + 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; + } + }; + + struct integral_operand : public alias_operators + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = int64_t; + + integral_operand() : _t{} + { + } + + integral_operand(_value_t t) : _t(t) + { + } + + integral_operand(const integral_operand&) = default; + integral_operand(integral_operand&&) = default; + integral_operand& operator=(const integral_operand&) = default; + integral_operand& operator=(integral_operand&&) = default; + ~integral_operand() = default; + + bool _is_trivial() const + { + return _t == 0; + } + + _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; + } + }; + + struct floating_point_operand : public alias_operators + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = double; + + floating_point_operand() : _t{} + { + } + + floating_point_operand(_value_t t) : _t(t) + { + } + + floating_point_operand(const floating_point_operand&) = default; + floating_point_operand(floating_point_operand&&) = default; + floating_point_operand& operator=(const floating_point_operand&) = default; + floating_point_operand& operator=(floating_point_operand&&) = default; + ~floating_point_operand() = default; + + bool _is_trivial() const + { + return _t == 0; + } + + _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; + } + }; + + struct text_operand : public alias_operators + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = std::string; + + text_operand() : _t{} + { + } + + text_operand(_value_t t) : _t(t) + { + } + + text_operand(const text_operand&) = default; + text_operand(text_operand&&) = default; + text_operand& operator=(const text_operand&) = default; + text_operand& operator=(text_operand&&) = default; + ~text_operand() = default; + + bool _is_trivial() const + { + return _t.empty(); + } + + _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; + } + }; + + template + struct wrap_operand + { + using type = T; + }; + + template <> + struct wrap_operand + { + using type = boolean_operand; + }; + + template + struct wrap_operand, void> + { + using type = time_point_operand; + }; + + template <> + struct wrap_operand, void> + { + using type = day_point_operand; + }; + + template + struct wrap_operand::value>::type> + { + using type = integral_operand; + }; + + template + struct wrap_operand::value>::type> + { + using type = floating_point_operand; + }; + + template + struct wrap_operand< + T, + typename std::enable_if::value and not is_result_field_t::value>::type> + { + using type = text_operand; + }; +} + +#endif diff --git a/include/sqlpp11/exists.h b/include/sqlpp11/exists.h index 64385328..5cab7395 100644 --- a/include/sqlpp11/exists.h +++ b/include/sqlpp11/exists.h @@ -28,7 +28,7 @@ #define SQLPP_EXISTS_H #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/expression.h b/include/sqlpp11/expression.h index d9435746..a1a611a4 100644 --- a/include/sqlpp11/expression.h +++ b/include/sqlpp11/expression.h @@ -28,7 +28,7 @@ #define SQLPP_EXPRESSION_H #include -#include +#include #include #include #include diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 16d54806..fd9512eb 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/sqlpp11/in.h b/include/sqlpp11/in.h index 70a08b14..1c2bcc87 100644 --- a/include/sqlpp11/in.h +++ b/include/sqlpp11/in.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include diff --git a/include/sqlpp11/is_not_null.h b/include/sqlpp11/is_not_null.h index 384f68f6..1f4b9c33 100644 --- a/include/sqlpp11/is_not_null.h +++ b/include/sqlpp11/is_not_null.h @@ -27,7 +27,7 @@ #ifndef SQLPP_IS_NOT_NULL_H #define SQLPP_IS_NOT_NULL_H -#include +#include #include #include #include diff --git a/include/sqlpp11/is_null.h b/include/sqlpp11/is_null.h index d5c91b67..97fdc047 100644 --- a/include/sqlpp11/is_null.h +++ b/include/sqlpp11/is_null.h @@ -27,7 +27,7 @@ #ifndef SQLPP_IS_NULL_H #define SQLPP_IS_NULL_H -#include +#include #include #include #include diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index 3ba011cf..68b2f84e 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -27,7 +27,7 @@ #ifndef SQLPP_LIKE_H #define SQLPP_LIKE_H -#include +#include #include #include #include diff --git a/include/sqlpp11/no_value.h b/include/sqlpp11/no_value.h index 9bea142d..2cdcbc6f 100644 --- a/include/sqlpp11/no_value.h +++ b/include/sqlpp11/no_value.h @@ -29,6 +29,7 @@ #include #include +#include namespace sqlpp { diff --git a/include/sqlpp11/not_in.h b/include/sqlpp11/not_in.h index b5bf7000..619a6b96 100644 --- a/include/sqlpp11/not_in.h +++ b/include/sqlpp11/not_in.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include diff --git a/include/sqlpp11/result_field_methods.h b/include/sqlpp11/result_field_methods.h index 6a2cb91d..9e82387e 100644 --- a/include/sqlpp11/result_field_methods.h +++ b/include/sqlpp11/result_field_methods.h @@ -29,6 +29,7 @@ #include #include +#include namespace sqlpp { diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 50cd358c..9e6a0ef2 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/some.h b/include/sqlpp11/some.h index 001f4c90..d33a2f20 100644 --- a/include/sqlpp11/some.h +++ b/include/sqlpp11/some.h @@ -27,7 +27,7 @@ #ifndef SQLPP_SOME_H #define SQLPP_SOME_H -#include +#include #include #include diff --git a/include/sqlpp11/sort_order.h b/include/sqlpp11/sort_order.h index 8fb7f034..391898dd 100644 --- a/include/sqlpp11/sort_order.h +++ b/include/sqlpp11/sort_order.h @@ -28,10 +28,11 @@ #define SQLPP_SORT_ORDER_H #include -#include namespace sqlpp { + struct no_value_t; + enum class sort_type { asc, diff --git a/include/sqlpp11/sqlpp11.h b/include/sqlpp11/sqlpp11.h index 9771f6c1..eb8a2d0f 100644 --- a/include/sqlpp11/sqlpp11.h +++ b/include/sqlpp11/sqlpp11.h @@ -28,7 +28,7 @@ #define SQLPP_H #include -#include +#include #include #include #include diff --git a/include/sqlpp11/value_or_null.h b/include/sqlpp11/value_or_null.h index 52d96dec..66536800 100644 --- a/include/sqlpp11/value_or_null.h +++ b/include/sqlpp11/value_or_null.h @@ -27,9 +27,10 @@ #ifndef SQLPP_VALUE_OR_NULL_H #define SQLPP_VALUE_OR_NULL_H +// FIXME: This is very similar to functions.h #include #include -#include +#include #include #include #include diff --git a/include/sqlpp11/value_type_fwd.h b/include/sqlpp11/value_type_fwd.h index 2923d896..8406ea39 100644 --- a/include/sqlpp11/value_type_fwd.h +++ b/include/sqlpp11/value_type_fwd.h @@ -32,18 +32,6 @@ namespace sqlpp { - template - struct parameter_value_t - { - static_assert(wrong_t::value, "Missing parameter value type for ValueType"); - }; - - template - struct column_operators - { - static_assert(wrong_t::value, "Missing column operators for ValueType"); - }; - template struct expression_operators { diff --git a/include/sqlpp11/wrap_operand.h b/include/sqlpp11/wrap_operand.h index 51c6304f..9cc980b9 100644 --- a/include/sqlpp11/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -27,64 +27,32 @@ #ifndef SQLPP_DETAIL_WRAP_OPERAND_H #define SQLPP_DETAIL_WRAP_OPERAND_H +namespace sqlpp +{ + template + struct wrap_operand + { + using type = T; + }; + + template + using wrap_operand_t = typename wrap_operand::type; +} + #include #include #include -#include #include #include #include +#include namespace sqlpp { - struct boolean; struct integral; struct floating_point; struct text; - struct boolean_operand : public alias_operators - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - using _is_aggregate_expression = std::true_type; - - using _value_t = bool; - - boolean_operand() : _t{} - { - } - - boolean_operand(_value_t t) : _t(t) - { - } - - boolean_operand(const boolean_operand&) = default; - boolean_operand(boolean_operand&&) = default; - boolean_operand& operator=(const boolean_operand&) = default; - boolean_operand& operator=(boolean_operand&&) = default; - ~boolean_operand() = default; - - bool _is_trivial() const - { - return _t == false; - } - - _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; - } - }; - struct day_point_operand : public alias_operators { using _traits = make_traits; @@ -305,18 +273,6 @@ namespace sqlpp } }; - template - struct wrap_operand - { - using type = T; - }; - - template <> - struct wrap_operand - { - using type = boolean_operand; - }; - template struct wrap_operand, void> { diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index 6a8c7af2..55df3645 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -121,7 +121,7 @@ print('#ifndef '+get_include_guard_name(namespace, pathToHeader), file=header) print('#define '+get_include_guard_name(namespace, pathToHeader), file=header) print('', file=header) print('#include <' + INCLUDE + '/table.h>', file=header) -print('#include <' + INCLUDE + '/column_types.h>', file=header) +print('#include <' + INCLUDE + '/data_types.h>', file=header) print('#include <' + INCLUDE + '/char_sequence.h>', file=header) print('', file=header) print('namespace ' + namespace, file=header) diff --git a/test_static_asserts/AssertTables.h b/test_static_asserts/AssertTables.h index e002f1b9..a8ea1f8d 100644 --- a/test_static_asserts/AssertTables.h +++ b/test_static_asserts/AssertTables.h @@ -3,7 +3,7 @@ #define TEST_ASSERTTABLES_H #include -#include +#include #include namespace test diff --git a/tests/Sample.h b/tests/Sample.h index adda22db..c95cd98e 100644 --- a/tests/Sample.h +++ b/tests/Sample.h @@ -2,7 +2,7 @@ #define TEST_SAMPLE_H #include -#include +#include #include namespace test From 6702bc8479250489e41328b7c5f4d3a1aee5457c Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 Oct 2015 11:05:46 +0100 Subject: [PATCH 02/30] Split integral.h into several sub files --- .../sqlpp11/data_types/boolean/result_field.h | 4 +- .../sqlpp11/data_types/boolean/serialize.h | 2 +- include/sqlpp11/data_types/integral.h | 304 +----------------- .../data_types/integral/column_operators.h | 80 +++++ .../sqlpp11/data_types/integral/data_type.h | 55 ++++ .../integral/expression_operators.h | 117 +++++++ include/sqlpp11/data_types/integral/operand.h | 68 ++++ .../data_types/integral/parameter_type.h | 106 ++++++ .../data_types/integral/result_field.h | 108 +++++++ .../sqlpp11/data_types/integral/serialize.h | 55 ++++ .../data_types/integral/wrap_operand.h | 43 +++ include/sqlpp11/wrap_operand.h | 49 --- 12 files changed, 643 insertions(+), 348 deletions(-) create mode 100644 include/sqlpp11/data_types/integral/column_operators.h create mode 100644 include/sqlpp11/data_types/integral/data_type.h create mode 100644 include/sqlpp11/data_types/integral/expression_operators.h create mode 100644 include/sqlpp11/data_types/integral/operand.h create mode 100644 include/sqlpp11/data_types/integral/parameter_type.h create mode 100644 include/sqlpp11/data_types/integral/result_field.h create mode 100644 include/sqlpp11/data_types/integral/serialize.h create mode 100644 include/sqlpp11/data_types/integral/wrap_operand.h diff --git a/include/sqlpp11/data_types/boolean/result_field.h b/include/sqlpp11/data_types/boolean/result_field.h index 404ecd78..4041585a 100644 --- a/include/sqlpp11/data_types/boolean/result_field.h +++ b/include/sqlpp11/data_types/boolean/result_field.h @@ -28,10 +28,10 @@ #define SQLPP_BOOLEAN_RESULT_FIELD_H #include -#include -#include #include #include +#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/data_types/boolean/serialize.h b/include/sqlpp11/data_types/boolean/serialize.h index 85bfc980..093fc972 100644 --- a/include/sqlpp11/data_types/boolean/serialize.h +++ b/include/sqlpp11/data_types/boolean/serialize.h @@ -27,7 +27,7 @@ #ifndef SQLPP_BOOLEAN_SERIALIZE_H #define SQLPP_BOOLEAN_SERIALIZE_H -#include +#include #include #include diff --git a/include/sqlpp11/data_types/integral.h b/include/sqlpp11/data_types/integral.h index 39c2ae4b..c224f1c0 100644 --- a/include/sqlpp11/data_types/integral.h +++ b/include/sqlpp11/data_types/integral.h @@ -27,301 +27,13 @@ #ifndef SQLPP_INTEGRAL_H #define SQLPP_INTEGRAL_H -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include -namespace sqlpp -{ - // integral value type - struct integral - { - using _traits = make_traits; - using _tag = tag::is_integral; - using _cpp_value_type = int64_t; - - template - using _is_valid_operand = is_numeric_t; - }; - - // integral parameter value - template <> - struct parameter_value_t - { - using _value_type = integral; - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value(0), _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 = 0; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - void set_null() - { - _value = 0; - _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_integral_parameter(index, &_value, _is_null); - } - - private: - _cpp_value_type _value; - bool _is_null; - }; - - // integral expression operators - template - struct expression_operators : public basic_expression_operators - { - template - using _is_valid_operand = is_valid_operand; - - template - plus_t, wrap_operand_t> operator+(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), {t}}; - } - - template - minus_t, wrap_operand_t> operator-(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), {t}}; - } - - template - multiplies_t, wrap_operand_t> operator*(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), {t}}; - } - - template - divides_t> operator/(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), {t}}; - } - - template - modulus_t> operator%(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), {t}}; - } - - unary_plus_t operator+() const - { - return {*static_cast(this)}; - } - - unary_minus_t operator-() const - { - return {*static_cast(this)}; - } - - template - bitwise_and_t, wrap_operand_t> operator&(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), {t}}; - } - - template - bitwise_or_t, wrap_operand_t> operator|(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), {t}}; - } - }; - - // integral column operators - template - struct column_operators - { - template - using _is_valid_operand = is_valid_operand; - - template - auto operator+=(T t) const -> assignment_t, wrap_operand_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; - } - - template - auto operator-=(T t) const -> assignment_t, wrap_operand_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; - } - - template - auto operator/=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; - } - - template - auto operator*=(T t) const -> assignment_t, wrap_operand_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; - } - }; - - // integral result field - template - struct result_field_t - : public result_field_methods_t> - { - static_assert(std::is_same, integral>::value, "field type mismatch"); - using _cpp_value_type = typename integral::_cpp_value_type; - - result_field_t() : _is_valid(false), _is_null(true), _value(0) - { - } - - void _invalidate() - { - _is_valid = false; - _is_null = true; - _value = 0; - } - - 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() == 0; - } - - _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 0; - } - } - return _value; - } - - template - void _bind(Target& target, size_t i) - { - target._bind_integral_result(i, &_value, &_is_null); - } - - private: - bool _is_valid; - bool _is_null; - _cpp_value_type _value; - }; - - // ostream operator for integral result field - template - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) - { - return serialize(e, os); - } - - using tinyint = integral; - using smallint = integral; - using integer = integral; - using bigint = integral; -} #endif diff --git a/include/sqlpp11/data_types/integral/column_operators.h b/include/sqlpp11/data_types/integral/column_operators.h new file mode 100644 index 00000000..72f30fd2 --- /dev/null +++ b/include/sqlpp11/data_types/integral/column_operators.h @@ -0,0 +1,80 @@ +/* + * 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_COLUMN_OPERATORS_H +#define SQLPP_INTEGRAL_COLUMN_OPERATORS_H + +#include +#include +#include + +namespace sqlpp +{ + template + struct column_operators + { + template + using _is_valid_operand = is_valid_operand; + + template + auto operator+=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; + } + + template + auto operator-=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; + } + + template + auto operator/=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; + } + + template + auto operator*=(T t) const -> assignment_t, wrap_operand_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {{*static_cast(this), rhs{t}}}}; + } + }; +} + +#endif diff --git a/include/sqlpp11/data_types/integral/data_type.h b/include/sqlpp11/data_types/integral/data_type.h new file mode 100644 index 00000000..f029d5a9 --- /dev/null +++ b/include/sqlpp11/data_types/integral/data_type.h @@ -0,0 +1,55 @@ +/* + * 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_DATA_TYPE_H +#define SQLPP_INTEGRAL_DATA_TYPE_H + +#include +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + struct integral + { + using _traits = make_traits; + using _tag = tag::is_integral; + using _cpp_value_type = int64_t; + + template + using _is_valid_operand = is_numeric_t; + }; + + using tinyint = integral; + using smallint = integral; + using integer = integral; + using bigint = integral; +} +#endif diff --git a/include/sqlpp11/data_types/integral/expression_operators.h b/include/sqlpp11/data_types/integral/expression_operators.h new file mode 100644 index 00000000..da18e0a8 --- /dev/null +++ b/include/sqlpp11/data_types/integral/expression_operators.h @@ -0,0 +1,117 @@ +/* + * 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_EXPRESSION_OPERATORS_H +#define SQLPP_INTEGRAL_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; + + template + plus_t, wrap_operand_t> operator+(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), {t}}; + } + + template + minus_t, wrap_operand_t> operator-(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), {t}}; + } + + template + multiplies_t, wrap_operand_t> operator*(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), {t}}; + } + + template + divides_t> operator/(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), {t}}; + } + + template + modulus_t> operator%(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), {t}}; + } + + unary_plus_t operator+() const + { + return {*static_cast(this)}; + } + + unary_minus_t operator-() const + { + return {*static_cast(this)}; + } + + template + bitwise_and_t, wrap_operand_t> operator&(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), {t}}; + } + + template + bitwise_or_t, wrap_operand_t> operator|(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), {t}}; + } + }; +} +#endif diff --git a/include/sqlpp11/data_types/integral/operand.h b/include/sqlpp11/data_types/integral/operand.h new file mode 100644 index 00000000..181087ea --- /dev/null +++ b/include/sqlpp11/data_types/integral/operand.h @@ -0,0 +1,68 @@ +/* + * 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_OPERAND_H +#define SQLPP_INTEGRAL_OPERAND_H + +#include +#include + +namespace sqlpp +{ + struct integral; + + struct integral_operand : public alias_operators + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = int64_t; + + integral_operand() : _t{} + { + } + + integral_operand(_value_t t) : _t(t) + { + } + + integral_operand(const integral_operand&) = default; + integral_operand(integral_operand&&) = default; + integral_operand& operator=(const integral_operand&) = default; + integral_operand& operator=(integral_operand&&) = default; + ~integral_operand() = default; + + bool _is_trivial() const + { + return _t == 0; + } + + _value_t _t; + }; +} + +#endif diff --git a/include/sqlpp11/data_types/integral/parameter_type.h b/include/sqlpp11/data_types/integral/parameter_type.h new file mode 100644 index 00000000..3d256d45 --- /dev/null +++ b/include/sqlpp11/data_types/integral/parameter_type.h @@ -0,0 +1,106 @@ +/* + * 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_PARAMETER_TYPE_H +#define SQLPP_INTEGRAL_PARAMETER_TYPE_H + +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t + { + using _value_type = integral; + using _cpp_value_type = typename _value_type::_cpp_value_type; + + parameter_value_t() : _value(0), _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 = 0; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + + void set_null() + { + _value = 0; + _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_integral_parameter(index, &_value, _is_null); + } + + private: + _cpp_value_type _value; + bool _is_null; + }; +} +#endif diff --git a/include/sqlpp11/data_types/integral/result_field.h b/include/sqlpp11/data_types/integral/result_field.h new file mode 100644 index 00000000..f36eb2da --- /dev/null +++ b/include/sqlpp11/data_types/integral/result_field.h @@ -0,0 +1,108 @@ +/* + * 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_RESULT_FIELD_H +#define SQLPP_INTEGRAL_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, integral>::value, "field type mismatch"); + using _cpp_value_type = typename integral::_cpp_value_type; + + result_field_t() : _is_valid(false), _is_null(true), _value(0) + { + } + + void _invalidate() + { + _is_valid = false; + _is_null = true; + _value = 0; + } + + 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() == 0; + } + + _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 0; + } + } + return _value; + } + + template + void _bind(Target& target, size_t i) + { + target._bind_integral_result(i, &_value, &_is_null); + } + + private: + bool _is_valid; + bool _is_null; + _cpp_value_type _value; + }; +} +#endif diff --git a/include/sqlpp11/data_types/integral/serialize.h b/include/sqlpp11/data_types/integral/serialize.h new file mode 100644 index 00000000..857713b1 --- /dev/null +++ b/include/sqlpp11/data_types/integral/serialize.h @@ -0,0 +1,55 @@ +/* + * 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/integral/wrap_operand.h b/include/sqlpp11/data_types/integral/wrap_operand.h new file mode 100644 index 00000000..9c658bb4 --- /dev/null +++ b/include/sqlpp11/data_types/integral/wrap_operand.h @@ -0,0 +1,43 @@ +/* + * 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_WRAP_OPERAND_H +#define SQLPP_INTEGRAL_WRAP_OPERAND_H + +#include +#include + +namespace sqlpp +{ + struct integral_operand; + + template + struct wrap_operand::value>::type> + { + using type = integral_operand; + }; +} +#endif diff --git a/include/sqlpp11/wrap_operand.h b/include/sqlpp11/wrap_operand.h index 9cc980b9..dfd4b73e 100644 --- a/include/sqlpp11/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -144,49 +144,6 @@ namespace sqlpp } }; - struct integral_operand : public alias_operators - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - using _is_aggregate_expression = std::true_type; - - using _value_t = int64_t; - - integral_operand() : _t{} - { - } - - integral_operand(_value_t t) : _t(t) - { - } - - integral_operand(const integral_operand&) = default; - integral_operand(integral_operand&&) = default; - integral_operand& operator=(const integral_operand&) = default; - integral_operand& operator=(integral_operand&&) = default; - ~integral_operand() = default; - - bool _is_trivial() const - { - return _t == 0; - } - - _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; - } - }; - struct floating_point_operand : public alias_operators { using _traits = make_traits; @@ -285,12 +242,6 @@ namespace sqlpp using type = day_point_operand; }; - template - struct wrap_operand::value>::type> - { - using type = integral_operand; - }; - template struct wrap_operand::value>::type> { From 4ae843b50269c9c96584ce3e8809a9d6c47288b2 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 Oct 2015 16:12:17 +0100 Subject: [PATCH 03/30] Distributed floating point include --- include/sqlpp11/data_types/floating_point.h | 267 +----------------- .../floating_point/column_operators.h | 79 ++++++ .../data_types/floating_point/data_type.h | 44 +++ .../floating_point/expression_operators.h | 88 ++++++ .../data_types/floating_point/operand.h | 65 +++++ .../floating_point/parameter_type.h | 107 +++++++ .../data_types/floating_point/result_field.h | 108 +++++++ .../data_types/floating_point/serialize.h | 55 ++++ .../data_types/floating_point/wrap_operand.h | 43 +++ include/sqlpp11/wrap_operand.h | 50 ---- 10 files changed, 597 insertions(+), 309 deletions(-) create mode 100644 include/sqlpp11/data_types/floating_point/column_operators.h create mode 100644 include/sqlpp11/data_types/floating_point/data_type.h create mode 100644 include/sqlpp11/data_types/floating_point/expression_operators.h create mode 100644 include/sqlpp11/data_types/floating_point/operand.h create mode 100644 include/sqlpp11/data_types/floating_point/parameter_type.h create mode 100644 include/sqlpp11/data_types/floating_point/result_field.h create mode 100644 include/sqlpp11/data_types/floating_point/serialize.h create mode 100644 include/sqlpp11/data_types/floating_point/wrap_operand.h diff --git a/include/sqlpp11/data_types/floating_point.h b/include/sqlpp11/data_types/floating_point.h index 053b624d..e7c53bba 100644 --- a/include/sqlpp11/data_types/floating_point.h +++ b/include/sqlpp11/data_types/floating_point.h @@ -27,264 +27,13 @@ #ifndef SQLPP_FLOATING_POINT_H #define SQLPP_FLOATING_POINT_H -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include -namespace sqlpp -{ - // floating_point value type - struct floating_point - { - using _traits = make_traits; - using _tag = tag::is_floating_point; - using _cpp_value_type = double; - - template - using _is_valid_operand = is_numeric_t; - }; - - // floating_point parameter type - template <> - struct parameter_value_t - { - using _value_type = floating_point; - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value(0), _is_null(true) - { - } - - 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 = 0; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - parameter_value_t& operator=(const std::nullptr_t&) - { - _value = 0; - _is_null = true; - return *this; - } - - 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_floating_point_parameter(index, &_value, _is_null); - } - - private: - _cpp_value_type _value; - bool _is_null; - }; - - // floating_point expression operators - template - struct expression_operators : public basic_expression_operators - { - template - using _is_valid_operand = is_valid_operand; - - template - plus_t> operator+(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), rhs{t}}; - } - - template - minus_t> operator-(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), rhs{t}}; - } - - template - multiplies_t> operator*(T t) const - { - using rhs = wrap_operand_t; - - return {*static_cast(this), rhs{t}}; - } - - template - divides_t> operator/(T t) const - { - using rhs = wrap_operand_t; - - return {*static_cast(this), rhs{t}}; - } - - unary_plus_t operator+() const - { - return {*static_cast(this)}; - } - - unary_minus_t operator-() const - { - return {*static_cast(this)}; - } - }; - - // floating_point column operators - template - struct column_operators - { - template - using _is_valid_operand = is_valid_operand; - - template - auto operator+=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return {*static_cast(this), {*static_cast(this), rhs{t}}}; - } - - template - auto operator-=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return {*static_cast(this), {*static_cast(this), rhs{t}}}; - } - - template - auto operator/=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return {*static_cast(this), {*static_cast(this), rhs{t}}}; - } - - template - auto operator*=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return {*static_cast(this), {*static_cast(this), rhs{t}}}; - } - }; - // floating_point result field - template - struct result_field_t - : public result_field_methods_t> - { - static_assert(std::is_same, floating_point>::value, "field type mismatch"); - using _cpp_value_type = typename floating_point::_cpp_value_type; - - result_field_t() : _is_valid(false), _is_null(true), _value(0) - { - } - - void _validate() - { - _is_valid = true; - } - - void _invalidate() - { - _is_valid = false; - _is_null = true; - _value = 0; - } - - 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() == 0; - } - - _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 0; - } - } - return _value; - } - - template - void _bind(Target& target, size_t i) - { - target._bind_floating_point_result(i, &_value, &_is_null); - } - - private: - bool _is_valid; - 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/column_operators.h b/include/sqlpp11/data_types/floating_point/column_operators.h new file mode 100644 index 00000000..dd3cda2b --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/column_operators.h @@ -0,0 +1,79 @@ +/* + * 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_COLUMN_OPERATORS_H +#define SQLPP_FLOATING_POINT_COLUMN_OPERATORS_H + +#include +#include +#include + +namespace sqlpp +{ + template + struct column_operators + { + template + using _is_valid_operand = is_valid_operand; + + template + auto operator+=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {*static_cast(this), rhs{t}}}; + } + + template + auto operator-=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {*static_cast(this), rhs{t}}}; + } + + template + auto operator/=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {*static_cast(this), rhs{t}}}; + } + + template + auto operator*=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), {*static_cast(this), rhs{t}}}; + } + }; +} +#endif diff --git a/include/sqlpp11/data_types/floating_point/data_type.h b/include/sqlpp11/data_types/floating_point/data_type.h new file mode 100644 index 00000000..d4c43887 --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/data_type.h @@ -0,0 +1,44 @@ +/* + * 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_DATA_TYPE_H +#define SQLPP_FLOATING_POINT_DATA_TYPE_H + +#include + +namespace sqlpp +{ + struct floating_point + { + using _traits = make_traits; + using _tag = tag::is_floating_point; + using _cpp_value_type = double; + + template + using _is_valid_operand = is_numeric_t; + }; +} +#endif diff --git a/include/sqlpp11/data_types/floating_point/expression_operators.h b/include/sqlpp11/data_types/floating_point/expression_operators.h new file mode 100644 index 00000000..773eebca --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/expression_operators.h @@ -0,0 +1,88 @@ +/* + * 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_EXPRESSION_OPERATORS_H +#define SQLPP_FLOATING_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; + + template + plus_t> operator+(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), rhs{t}}; + } + + template + minus_t> operator-(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), rhs{t}}; + } + + template + multiplies_t> operator*(T t) const + { + using rhs = wrap_operand_t; + + return {*static_cast(this), rhs{t}}; + } + + template + divides_t> operator/(T t) const + { + using rhs = wrap_operand_t; + + return {*static_cast(this), rhs{t}}; + } + + unary_plus_t operator+() const + { + return {*static_cast(this)}; + } + + unary_minus_t operator-() const + { + return {*static_cast(this)}; + } + }; +} +#endif diff --git a/include/sqlpp11/data_types/floating_point/operand.h b/include/sqlpp11/data_types/floating_point/operand.h new file mode 100644 index 00000000..e13d890f --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/operand.h @@ -0,0 +1,65 @@ +/* + * 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_OPERAND_H +#define SQLPP_FLOATING_POINT_OPERAND_H + +#include +#include + +namespace sqlpp +{ + struct floating_point_operand : public alias_operators + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = double; + + floating_point_operand() : _t{} + { + } + + floating_point_operand(_value_t t) : _t(t) + { + } + + floating_point_operand(const floating_point_operand&) = default; + floating_point_operand(floating_point_operand&&) = default; + floating_point_operand& operator=(const floating_point_operand&) = default; + floating_point_operand& operator=(floating_point_operand&&) = default; + ~floating_point_operand() = default; + + bool _is_trivial() const + { + return _t == 0; + } + + _value_t _t; + }; +} +#endif diff --git a/include/sqlpp11/data_types/floating_point/parameter_type.h b/include/sqlpp11/data_types/floating_point/parameter_type.h new file mode 100644 index 00000000..9a6b0e97 --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/parameter_type.h @@ -0,0 +1,107 @@ +/* + * 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_PARAMETER_TYPE_H +#define SQLPP_FLOATING_POINT_PARAMETER_TYPE_H + +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t + { + using _value_type = floating_point; + using _cpp_value_type = typename _value_type::_cpp_value_type; + + parameter_value_t() : _value(0), _is_null(true) + { + } + + 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 = 0; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + + parameter_value_t& operator=(const std::nullptr_t&) + { + _value = 0; + _is_null = true; + return *this; + } + + 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_floating_point_parameter(index, &_value, _is_null); + } + + private: + _cpp_value_type _value; + bool _is_null; + }; +} +#endif diff --git a/include/sqlpp11/data_types/floating_point/result_field.h b/include/sqlpp11/data_types/floating_point/result_field.h new file mode 100644 index 00000000..f5e93119 --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/result_field.h @@ -0,0 +1,108 @@ +/* + * 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_RESULT_FIELD_H +#define SQLPP_FLOATING_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, floating_point>::value, "field type mismatch"); + using _cpp_value_type = typename floating_point::_cpp_value_type; + + result_field_t() : _is_valid(false), _is_null(true), _value(0) + { + } + + void _validate() + { + _is_valid = true; + } + + void _invalidate() + { + _is_valid = false; + _is_null = true; + _value = 0; + } + + 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() == 0; + } + + _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 0; + } + } + return _value; + } + + template + void _bind(Target& target, size_t i) + { + target._bind_floating_point_result(i, &_value, &_is_null); + } + + private: + bool _is_valid; + bool _is_null; + _cpp_value_type _value; + }; +} +#endif diff --git a/include/sqlpp11/data_types/floating_point/serialize.h b/include/sqlpp11/data_types/floating_point/serialize.h new file mode 100644 index 00000000..018b6a71 --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/serialize.h @@ -0,0 +1,55 @@ +/* + * 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/floating_point/wrap_operand.h b/include/sqlpp11/data_types/floating_point/wrap_operand.h new file mode 100644 index 00000000..2c38b8ea --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/wrap_operand.h @@ -0,0 +1,43 @@ +/* + * 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_WRAP_OPERAND_H +#define SQLPP_FLOATING_POINT_WRAP_OPERAND_H + +#include +#include + +namespace sqlpp +{ + struct floating_point_operand; + + template + struct wrap_operand::value>::type> + { + using type = floating_point_operand; + }; +} +#endif diff --git a/include/sqlpp11/wrap_operand.h b/include/sqlpp11/wrap_operand.h index dfd4b73e..ac93c00f 100644 --- a/include/sqlpp11/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -50,7 +50,6 @@ namespace sqlpp namespace sqlpp { struct integral; - struct floating_point; struct text; struct day_point_operand : public alias_operators @@ -144,49 +143,6 @@ namespace sqlpp } }; - struct floating_point_operand : public alias_operators - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - using _is_aggregate_expression = std::true_type; - - using _value_t = double; - - floating_point_operand() : _t{} - { - } - - floating_point_operand(_value_t t) : _t(t) - { - } - - floating_point_operand(const floating_point_operand&) = default; - floating_point_operand(floating_point_operand&&) = default; - floating_point_operand& operator=(const floating_point_operand&) = default; - floating_point_operand& operator=(floating_point_operand&&) = default; - ~floating_point_operand() = default; - - bool _is_trivial() const - { - return _t == 0; - } - - _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; - } - }; - struct text_operand : public alias_operators { using _traits = make_traits; @@ -242,12 +198,6 @@ namespace sqlpp using type = day_point_operand; }; - template - struct wrap_operand::value>::type> - { - using type = floating_point_operand; - }; - template struct wrap_operand< T, From 45c3f4b4cc319421c46223eff1d3473a2f927a6a Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 Oct 2015 19:48:53 +0100 Subject: [PATCH 04/30] Split text.h, some fixes and moved like and concat to text --- .../floating_point/column_operators.h | 1 + .../data_types/integral/column_operators.h | 2 + .../sqlpp11/data_types/integral/data_type.h | 6 - .../integral/expression_operators.h | 1 + include/sqlpp11/data_types/text.h | 261 +----------------- .../data_types/text/column_operators.h | 57 ++++ .../sqlpp11/{ => data_types/text}/concat.h | 0 include/sqlpp11/data_types/text/data_type.h | 48 ++++ .../data_types/text/expression_operators.h | 68 +++++ include/sqlpp11/{ => data_types/text}/like.h | 0 include/sqlpp11/data_types/text/operand.h | 67 +++++ .../sqlpp11/data_types/text/parameter_type.h | 107 +++++++ .../sqlpp11/data_types/text/result_field.h | 116 ++++++++ include/sqlpp11/data_types/text/serialize.h | 62 +++++ .../sqlpp11/data_types/text/wrap_operand.h | 46 +++ include/sqlpp11/functions.h | 1 - include/sqlpp11/result_field.h | 5 +- include/sqlpp11/type_traits.h | 9 + include/sqlpp11/value_type_fwd.h | 9 - include/sqlpp11/wrap_operand.h | 52 ---- 20 files changed, 598 insertions(+), 320 deletions(-) create mode 100644 include/sqlpp11/data_types/text/column_operators.h rename include/sqlpp11/{ => data_types/text}/concat.h (100%) create mode 100644 include/sqlpp11/data_types/text/data_type.h create mode 100644 include/sqlpp11/data_types/text/expression_operators.h rename include/sqlpp11/{ => data_types/text}/like.h (100%) create mode 100644 include/sqlpp11/data_types/text/operand.h create mode 100644 include/sqlpp11/data_types/text/parameter_type.h create mode 100644 include/sqlpp11/data_types/text/result_field.h create mode 100644 include/sqlpp11/data_types/text/serialize.h create mode 100644 include/sqlpp11/data_types/text/wrap_operand.h diff --git a/include/sqlpp11/data_types/floating_point/column_operators.h b/include/sqlpp11/data_types/floating_point/column_operators.h index dd3cda2b..6daf5131 100644 --- a/include/sqlpp11/data_types/floating_point/column_operators.h +++ b/include/sqlpp11/data_types/floating_point/column_operators.h @@ -28,6 +28,7 @@ #define SQLPP_FLOATING_POINT_COLUMN_OPERATORS_H #include +#include #include #include diff --git a/include/sqlpp11/data_types/integral/column_operators.h b/include/sqlpp11/data_types/integral/column_operators.h index 72f30fd2..cd447123 100644 --- a/include/sqlpp11/data_types/integral/column_operators.h +++ b/include/sqlpp11/data_types/integral/column_operators.h @@ -28,6 +28,8 @@ #define SQLPP_INTEGRAL_COLUMN_OPERATORS_H #include +#include +#include #include #include diff --git a/include/sqlpp11/data_types/integral/data_type.h b/include/sqlpp11/data_types/integral/data_type.h index f029d5a9..4ffce0c4 100644 --- a/include/sqlpp11/data_types/integral/data_type.h +++ b/include/sqlpp11/data_types/integral/data_type.h @@ -27,13 +27,7 @@ #ifndef SQLPP_INTEGRAL_DATA_TYPE_H #define SQLPP_INTEGRAL_DATA_TYPE_H -#include -#include #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 da18e0a8..5dc1d0af 100644 --- a/include/sqlpp11/data_types/integral/expression_operators.h +++ b/include/sqlpp11/data_types/integral/expression_operators.h @@ -28,6 +28,7 @@ #define SQLPP_INTEGRAL_EXPRESSION_OPERATORS_H #include +#include #include #include #include diff --git a/include/sqlpp11/data_types/text.h b/include/sqlpp11/data_types/text.h index cb6619d5..dcd08b38 100644 --- a/include/sqlpp11/data_types/text.h +++ b/include/sqlpp11/data_types/text.h @@ -27,256 +27,17 @@ #ifndef SQLPP_TEXT_H #define SQLPP_TEXT_H -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include -namespace sqlpp -{ - template - struct concat_t; +// text specific functions +#include +#include - // text value type - struct text - { - using _traits = make_traits; - using _tag = tag::is_text; - using _cpp_value_type = std::string; - - template - using _is_valid_operand = is_text_t; - }; - - // text parameter type - template <> - struct parameter_value_t - { - using _value_type = text; - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value(""), _is_null(true) - { - } - - 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 = ""; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - parameter_value_t& operator=(const std::nullptr_t&) - { - _value = ""; - _is_null = true; - return *this; - } - - bool is_null() const - { - return _is_null; - } - - _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_text_parameter(index, &_value, _is_null); - } - - private: - _cpp_value_type _value; - bool _is_null; - }; - - // text expression operators - template - struct expression_operators : public basic_expression_operators - { - template - using _is_valid_operand = is_valid_operand; - - template - concat_t> operator+(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); - - return {*static_cast(this), {t}}; - } - - template - like_t> like(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid argument for like()"); - - return {*static_cast(this), {t}}; - } - }; - - // text column operators - template - struct column_operators - { - template - using _is_valid_operand = is_valid_operand; - - template - auto operator+=(T t) const -> assignment_t>> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - - return {*static_cast(this), - concat_t>{*static_cast(this), rhs{t}}}; - } - }; - - // text result field - template - struct result_field_t : public result_field_methods_t> - { - static_assert(std::is_same, text>::value, "field type mismatch"); - using _cpp_value_type = typename text::_cpp_value_type; - - result_field_t() : _is_valid(false), _value_ptr(nullptr), _len(0) - { - } - - void _validate() - { - _is_valid = true; - } - - void _invalidate() - { - _is_valid = false; - _value_ptr = nullptr; - _len = 0; - } - - bool operator==(const _cpp_value_type& rhs) const - { - return value() == rhs; - } - bool operator!=(const _cpp_value_type& rhs) const - { - return not operator==(rhs); - } - - bool is_null() const - { - if (not _is_valid) - throw exception("accessing is_null in non-existing row"); - return _value_ptr == nullptr; - } - - bool _is_trivial() const - { - if (not _is_valid) - throw exception("accessing is_null in non-existing row"); - - return value() == ""; - } - - _cpp_value_type value() const - { - if (not _is_valid) - throw exception("accessing value in non-existing row"); - - if (not _value_ptr) - { - if (enforce_null_result_treatment_t::value and not null_is_trivial_value_t::value) - { - throw exception("accessing value of NULL field"); - } - else - { - return ""; - } - } - return std::string(_value_ptr, _value_ptr + _len); - } - - template - void _bind(Target& target, size_t i) - { - target._bind_text_result(i, &_value_ptr, &_len); - } - - private: - bool _is_valid; - const char* _value_ptr; - size_t _len; - }; - - 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 - { - context << '\'' << context.escape(t.value()) << '\''; - } - 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(); - } - } - - using blob = text; - using varchar = text; - using char_ = text; -} #endif diff --git a/include/sqlpp11/data_types/text/column_operators.h b/include/sqlpp11/data_types/text/column_operators.h new file mode 100644 index 00000000..fd2d8695 --- /dev/null +++ b/include/sqlpp11/data_types/text/column_operators.h @@ -0,0 +1,57 @@ +/* + * 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_COLUMN_OPERATORS_H +#define SQLPP_TEXT_COLUMN_OPERATORS_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct concat_t; + + template + struct column_operators + { + template + using _is_valid_operand = is_valid_operand; + + template + auto operator+=(T t) const -> assignment_t>> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + + return {*static_cast(this), + concat_t>{*static_cast(this), rhs{t}}}; + } + }; +} +#endif diff --git a/include/sqlpp11/concat.h b/include/sqlpp11/data_types/text/concat.h similarity index 100% rename from include/sqlpp11/concat.h rename to include/sqlpp11/data_types/text/concat.h diff --git a/include/sqlpp11/data_types/text/data_type.h b/include/sqlpp11/data_types/text/data_type.h new file mode 100644 index 00000000..e9644357 --- /dev/null +++ b/include/sqlpp11/data_types/text/data_type.h @@ -0,0 +1,48 @@ +/* + * 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_DATA_TYPE_H +#define SQLPP_TEXT_DATA_TYPE_H + +#include + +namespace sqlpp +{ + struct text + { + using _traits = make_traits; + using _tag = tag::is_text; + using _cpp_value_type = std::string; + + template + using _is_valid_operand = is_text_t; + }; + + using blob = text; + using varchar = text; + using char_ = text; +} +#endif diff --git a/include/sqlpp11/data_types/text/expression_operators.h b/include/sqlpp11/data_types/text/expression_operators.h new file mode 100644 index 00000000..01d9ccb7 --- /dev/null +++ b/include/sqlpp11/data_types/text/expression_operators.h @@ -0,0 +1,68 @@ +/* + * 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_EXPRESSION_OPERATORS_H +#define SQLPP_TEXT_EXPRESSION_OPERATORS_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct concat_t; + + template + struct like_t; + + template + struct expression_operators : public basic_expression_operators + { + template + using _is_valid_operand = is_valid_operand; + + template + concat_t> operator+(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); + + return {*static_cast(this), {t}}; + } + + template + like_t> like(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid argument for like()"); + + return {*static_cast(this), {t}}; + } + }; +} +#endif diff --git a/include/sqlpp11/like.h b/include/sqlpp11/data_types/text/like.h similarity index 100% rename from include/sqlpp11/like.h rename to include/sqlpp11/data_types/text/like.h diff --git a/include/sqlpp11/data_types/text/operand.h b/include/sqlpp11/data_types/text/operand.h new file mode 100644 index 00000000..a73341e2 --- /dev/null +++ b/include/sqlpp11/data_types/text/operand.h @@ -0,0 +1,67 @@ +/* + * 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_OPERAND_H +#define SQLPP_TEXT_OPERAND_H + +#include +#include + +namespace sqlpp +{ + struct text; + + struct text_operand : public alias_operators + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; + using _is_aggregate_expression = std::true_type; + + using _value_t = std::string; + + text_operand() : _t{} + { + } + + text_operand(_value_t t) : _t(t) + { + } + + text_operand(const text_operand&) = default; + text_operand(text_operand&&) = default; + text_operand& operator=(const text_operand&) = default; + text_operand& operator=(text_operand&&) = default; + ~text_operand() = default; + + bool _is_trivial() const + { + return _t.empty(); + } + + _value_t _t; + }; +} +#endif diff --git a/include/sqlpp11/data_types/text/parameter_type.h b/include/sqlpp11/data_types/text/parameter_type.h new file mode 100644 index 00000000..796b7e29 --- /dev/null +++ b/include/sqlpp11/data_types/text/parameter_type.h @@ -0,0 +1,107 @@ +/* + * 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_PARAMETER_TYPE_H +#define SQLPP_TEXT_PARAMETER_TYPE_H + +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t + { + using _value_type = text; + using _cpp_value_type = typename _value_type::_cpp_value_type; + + parameter_value_t() : _value(""), _is_null(true) + { + } + + 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 = ""; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + + parameter_value_t& operator=(const std::nullptr_t&) + { + _value = ""; + _is_null = true; + return *this; + } + + bool is_null() const + { + return _is_null; + } + + _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_text_parameter(index, &_value, _is_null); + } + + private: + _cpp_value_type _value; + bool _is_null; + }; +} +#endif diff --git a/include/sqlpp11/data_types/text/result_field.h b/include/sqlpp11/data_types/text/result_field.h new file mode 100644 index 00000000..b166c0e8 --- /dev/null +++ b/include/sqlpp11/data_types/text/result_field.h @@ -0,0 +1,116 @@ +/* + * 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_RESULT_FIELD_H +#define SQLPP_TEXT_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, text>::value, "field type mismatch"); + using _cpp_value_type = typename text::_cpp_value_type; + + result_field_t() : _is_valid(false), _value_ptr(nullptr), _len(0) + { + } + + void _validate() + { + _is_valid = true; + } + + void _invalidate() + { + _is_valid = false; + _value_ptr = nullptr; + _len = 0; + } + + bool operator==(const _cpp_value_type& rhs) const + { + return value() == rhs; + } + bool operator!=(const _cpp_value_type& rhs) const + { + return not operator==(rhs); + } + + bool is_null() const + { + if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + return _value_ptr == nullptr; + } + + bool _is_trivial() const + { + if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + + return value() == ""; + } + + _cpp_value_type value() const + { + if (not _is_valid) + throw exception("accessing value in non-existing row"); + + if (not _value_ptr) + { + if (enforce_null_result_treatment_t::value and not null_is_trivial_value_t::value) + { + throw exception("accessing value of NULL field"); + } + else + { + return ""; + } + } + return std::string(_value_ptr, _value_ptr + _len); + } + + template + void _bind(Target& target, size_t i) + { + target._bind_text_result(i, &_value_ptr, &_len); + } + + private: + bool _is_valid; + const char* _value_ptr; + size_t _len; + }; +} +#endif diff --git a/include/sqlpp11/data_types/text/serialize.h b/include/sqlpp11/data_types/text/serialize.h new file mode 100644 index 00000000..41d3d442 --- /dev/null +++ b/include/sqlpp11/data_types/text/serialize.h @@ -0,0 +1,62 @@ +/* + * 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/text/wrap_operand.h b/include/sqlpp11/data_types/text/wrap_operand.h new file mode 100644 index 00000000..f80e26d8 --- /dev/null +++ b/include/sqlpp11/data_types/text/wrap_operand.h @@ -0,0 +1,46 @@ +/* + * 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_WRAP_OPERAND_H +#define SQLPP_TEXT_WRAP_OPERAND_H + +#include +#include +#include + +namespace sqlpp +{ + struct text_operand; + + template + struct wrap_operand< + T, + typename std::enable_if::value and not is_result_field_t::value>::type> + { + using type = text_operand; + }; +} +#endif diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index fd9512eb..916b0a66 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include diff --git a/include/sqlpp11/result_field.h b/include/sqlpp11/result_field.h index 96d98422..821880a8 100644 --- a/include/sqlpp11/result_field.h +++ b/include/sqlpp11/result_field.h @@ -28,7 +28,8 @@ #define SQLPP_RESULT_FIELD_H #include -#include +#include +#include namespace sqlpp { @@ -52,7 +53,7 @@ namespace sqlpp } else { - context << t.value(); + serialize(wrap_operand_t{t}, context); } return context; } diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 98bc1b35..797bec57 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -229,6 +229,15 @@ namespace sqlpp SQLPP_RECURSIVE_TRAIT_GENERATOR(can_be_null) SQLPP_RECURSIVE_TRAIT_GENERATOR(contains_aggregate_function) + template + struct is_valid_operand + { + static constexpr bool value = + is_expression_t::value // expressions are OK + and ValueType::template _is_valid_operand::value // the correct value type is required, of course + ; + }; + namespace detail { template diff --git a/include/sqlpp11/value_type_fwd.h b/include/sqlpp11/value_type_fwd.h index 8406ea39..5b105b18 100644 --- a/include/sqlpp11/value_type_fwd.h +++ b/include/sqlpp11/value_type_fwd.h @@ -38,15 +38,6 @@ namespace sqlpp static_assert(wrong_t::value, "Missing expression operators for ValueType"); }; - template - struct is_valid_operand - { - static constexpr bool value = - is_expression_t::value // expressions are OK - and ValueType::template _is_valid_operand::value // the correct value type is required, of course - ; - }; - template struct is_valid_assignment_operand { diff --git a/include/sqlpp11/wrap_operand.h b/include/sqlpp11/wrap_operand.h index ac93c00f..02edabad 100644 --- a/include/sqlpp11/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -50,7 +50,6 @@ namespace sqlpp namespace sqlpp { struct integral; - struct text; struct day_point_operand : public alias_operators { @@ -143,49 +142,6 @@ namespace sqlpp } }; - struct text_operand : public alias_operators - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; - using _is_aggregate_expression = std::true_type; - - using _value_t = std::string; - - text_operand() : _t{} - { - } - - text_operand(_value_t t) : _t(t) - { - } - - text_operand(const text_operand&) = default; - text_operand(text_operand&&) = default; - text_operand& operator=(const text_operand&) = default; - text_operand& operator=(text_operand&&) = default; - ~text_operand() = default; - - bool _is_trivial() const - { - return _t.empty(); - } - - _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; - } - }; - template struct wrap_operand, void> { @@ -197,14 +153,6 @@ namespace sqlpp { using type = day_point_operand; }; - - template - struct wrap_operand< - T, - typename std::enable_if::value and not is_result_field_t::value>::type> - { - using type = text_operand; - }; } #endif From 37b7966ab238001745e8b6ad77668d2986316880 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 Oct 2015 21:47:31 +0100 Subject: [PATCH 05/30] 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 From f48e807ce5f7072fa6b73848ff29570c270951ca Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 Oct 2015 23:24:42 +0100 Subject: [PATCH 06/30] Started to use parameter_value_base to simplify parameter_value code --- include/sqlpp11/count.h | 2 +- include/sqlpp11/data_types/boolean.h | 4 +- .../data_types/boolean/parameter_type.h | 66 +------------ include/sqlpp11/data_types/day_point.h | 4 +- include/sqlpp11/data_types/floating_point.h | 4 +- include/sqlpp11/data_types/integral.h | 4 +- .../data_types/integral/parameter_type.h | 65 +------------ .../data_types/integral/wrap_operand.h | 2 +- .../sqlpp11/data_types/parameter_value_base.h | 97 +++++++++++++++++++ include/sqlpp11/data_types/text.h | 4 +- include/sqlpp11/data_types/time_point.h | 4 +- 11 files changed, 121 insertions(+), 135 deletions(-) create mode 100644 include/sqlpp11/data_types/parameter_value_base.h diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 62e85225..cc33d1b1 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/data_types/boolean.h b/include/sqlpp11/data_types/boolean.h index d80f9134..dbc2f13a 100644 --- a/include/sqlpp11/data_types/boolean.h +++ b/include/sqlpp11/data_types/boolean.h @@ -28,12 +28,12 @@ #define SQLPP_BOOLEAN_H #include +#include +#include #include #include #include #include -#include -#include #include #endif diff --git a/include/sqlpp11/data_types/boolean/parameter_type.h b/include/sqlpp11/data_types/boolean/parameter_type.h index 33d715a6..2e00b1b3 100644 --- a/include/sqlpp11/data_types/boolean/parameter_type.h +++ b/include/sqlpp11/data_types/boolean/parameter_type.h @@ -28,80 +28,24 @@ #define SQLPP_BOOLEAN_PARAMETER_TYPE_H #include +#include #include -#include -#include #include namespace sqlpp { template <> - struct parameter_value_t + struct parameter_value_t : public base_parameter_value { - using _value_type = boolean; // FIXME - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value(false), _is_null(true) - { - } - - 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 = false; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - parameter_value_t& operator=(const std::nullptr_t&) - { - _value = false; - _is_null = true; - return *this; - } - - bool is_null() const - { - return _is_null; - } - - _cpp_value_type value() const - { - return _value; - } - - operator _cpp_value_type() const - { - return value(); - } + using base = base_parameter_value; + using base::base; + using base::operator=; template void _bind(Target& target, size_t index) const { target._bind_boolean_parameter(index, &_value, _is_null); } - - private: - signed char _value; - bool _is_null; }; } diff --git a/include/sqlpp11/data_types/day_point.h b/include/sqlpp11/data_types/day_point.h index 78f36460..0c6457bd 100644 --- a/include/sqlpp11/data_types/day_point.h +++ b/include/sqlpp11/data_types/day_point.h @@ -28,12 +28,12 @@ #define SQLPP_DAY_POINT_H #include +#include +#include #include #include #include #include -#include -#include #include #endif diff --git a/include/sqlpp11/data_types/floating_point.h b/include/sqlpp11/data_types/floating_point.h index e7c53bba..14731c5e 100644 --- a/include/sqlpp11/data_types/floating_point.h +++ b/include/sqlpp11/data_types/floating_point.h @@ -28,12 +28,12 @@ #define SQLPP_FLOATING_POINT_H #include +#include +#include #include #include #include #include -#include -#include #include #endif diff --git a/include/sqlpp11/data_types/integral.h b/include/sqlpp11/data_types/integral.h index c224f1c0..1aa43498 100644 --- a/include/sqlpp11/data_types/integral.h +++ b/include/sqlpp11/data_types/integral.h @@ -28,12 +28,12 @@ #define SQLPP_INTEGRAL_H #include +#include +#include #include #include #include #include -#include -#include #include #endif diff --git a/include/sqlpp11/data_types/integral/parameter_type.h b/include/sqlpp11/data_types/integral/parameter_type.h index 3d256d45..ba8e1d5d 100644 --- a/include/sqlpp11/data_types/integral/parameter_type.h +++ b/include/sqlpp11/data_types/integral/parameter_type.h @@ -28,79 +28,24 @@ #define SQLPP_INTEGRAL_PARAMETER_TYPE_H #include +#include #include -#include -#include #include namespace sqlpp { template <> - struct parameter_value_t + struct parameter_value_t : public base_parameter_value { - using _value_type = integral; - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value(0), _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 = 0; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - void set_null() - { - _value = 0; - _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; - } + using base = base_parameter_value; + using base::base; + using base::operator=; template void _bind(Target& target, size_t index) const { target._bind_integral_parameter(index, &_value, _is_null); } - - private: - _cpp_value_type _value; - bool _is_null; }; } #endif diff --git a/include/sqlpp11/data_types/integral/wrap_operand.h b/include/sqlpp11/data_types/integral/wrap_operand.h index 9c658bb4..a395b864 100644 --- a/include/sqlpp11/data_types/integral/wrap_operand.h +++ b/include/sqlpp11/data_types/integral/wrap_operand.h @@ -35,7 +35,7 @@ namespace sqlpp struct integral_operand; template - struct wrap_operand::value>::type> + struct wrap_operand::value and not std::is_same::value>::type> { using type = integral_operand; }; diff --git a/include/sqlpp11/data_types/parameter_value_base.h b/include/sqlpp11/data_types/parameter_value_base.h new file mode 100644 index 00000000..2f407498 --- /dev/null +++ b/include/sqlpp11/data_types/parameter_value_base.h @@ -0,0 +1,97 @@ +/* + * 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_PARAMETER_VALUE_BASE_H +#define SQLPP_PARAMETER_VALUE_BASE_H + +#include +#include + +namespace sqlpp +{ + template + struct base_parameter_value + { + using _value_type = DataType; + using _cpp_value_type = typename _value_type::_cpp_value_type; + + base_parameter_value() : _value(0), _is_null(true) + { + } + + explicit base_parameter_value(const _cpp_value_type& val) : _value(val), _is_null(false) + { + } + + base_parameter_value& operator=(const _cpp_value_type& val) + { + _value = val; + _is_null = false; + return *this; + } + + base_parameter_value& operator=(const tvin_t>& t) + { + if (t._is_trivial()) + { + _value = 0; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + + void set_null() + { + _value = 0; + _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; + } + + protected: + _cpp_value_type _value; + bool _is_null; + }; +} +#endif diff --git a/include/sqlpp11/data_types/text.h b/include/sqlpp11/data_types/text.h index dcd08b38..d7099cd4 100644 --- a/include/sqlpp11/data_types/text.h +++ b/include/sqlpp11/data_types/text.h @@ -28,12 +28,12 @@ #define SQLPP_TEXT_H #include +#include +#include #include #include #include #include -#include -#include #include // text specific functions diff --git a/include/sqlpp11/data_types/time_point.h b/include/sqlpp11/data_types/time_point.h index cbf90688..ec982439 100644 --- a/include/sqlpp11/data_types/time_point.h +++ b/include/sqlpp11/data_types/time_point.h @@ -28,12 +28,12 @@ #define SQLPP_TIME_POINT_H #include +#include +#include #include #include #include #include -#include -#include #include #endif From de1e8f27a427dfc02d6f27a16892b3746d30f492 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 Oct 2015 23:48:07 +0100 Subject: [PATCH 07/30] Utilize parameter_value_base for the remaining data types --- .../data_types/day_point/parameter_type.h | 63 ++---------------- .../floating_point/parameter_type.h | 64 ++----------------- .../sqlpp11/data_types/parameter_value_base.h | 6 +- .../sqlpp11/data_types/text/parameter_type.h | 64 ++----------------- .../data_types/time_point/parameter_type.h | 64 ++----------------- 5 files changed, 23 insertions(+), 238 deletions(-) diff --git a/include/sqlpp11/data_types/day_point/parameter_type.h b/include/sqlpp11/data_types/day_point/parameter_type.h index 6ff2ac4c..657bdbcc 100644 --- a/include/sqlpp11/data_types/day_point/parameter_type.h +++ b/include/sqlpp11/data_types/day_point/parameter_type.h @@ -28,6 +28,7 @@ #define SQLPP_DAY_POINT_PARAMETER_TYPE_H #include +#include #include #include #include @@ -36,71 +37,17 @@ namespace sqlpp { template <> - struct parameter_value_t + struct parameter_value_t : public base_parameter_value { - 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; - } + using base = base_parameter_value; + using base::base; + using base::operator=; 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/floating_point/parameter_type.h b/include/sqlpp11/data_types/floating_point/parameter_type.h index 9a6b0e97..d0ff6108 100644 --- a/include/sqlpp11/data_types/floating_point/parameter_type.h +++ b/include/sqlpp11/data_types/floating_point/parameter_type.h @@ -28,6 +28,7 @@ #define SQLPP_FLOATING_POINT_PARAMETER_TYPE_H #include +#include #include #include #include @@ -36,72 +37,17 @@ namespace sqlpp { template <> - struct parameter_value_t + struct parameter_value_t : public base_parameter_value { - using _value_type = floating_point; - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value(0), _is_null(true) - { - } - - 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 = 0; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - parameter_value_t& operator=(const std::nullptr_t&) - { - _value = 0; - _is_null = true; - return *this; - } - - bool is_null() const - { - return _is_null; - } - - const _cpp_value_type& value() const - { - return _value; - } - - operator _cpp_value_type() const - { - return _value; - } + using base = base_parameter_value; + using base::base; + using base::operator=; template void _bind(Target& target, size_t index) const { target._bind_floating_point_parameter(index, &_value, _is_null); } - - private: - _cpp_value_type _value; - bool _is_null; }; } #endif diff --git a/include/sqlpp11/data_types/parameter_value_base.h b/include/sqlpp11/data_types/parameter_value_base.h index 2f407498..6c55be4e 100644 --- a/include/sqlpp11/data_types/parameter_value_base.h +++ b/include/sqlpp11/data_types/parameter_value_base.h @@ -38,7 +38,7 @@ namespace sqlpp using _value_type = DataType; using _cpp_value_type = typename _value_type::_cpp_value_type; - base_parameter_value() : _value(0), _is_null(true) + base_parameter_value() : _value{}, _is_null{true} { } @@ -57,7 +57,7 @@ namespace sqlpp { if (t._is_trivial()) { - _value = 0; + _value = {}; _is_null = true; } else @@ -70,7 +70,7 @@ namespace sqlpp void set_null() { - _value = 0; + _value = {}; _is_null = true; } diff --git a/include/sqlpp11/data_types/text/parameter_type.h b/include/sqlpp11/data_types/text/parameter_type.h index 796b7e29..8358696c 100644 --- a/include/sqlpp11/data_types/text/parameter_type.h +++ b/include/sqlpp11/data_types/text/parameter_type.h @@ -28,6 +28,7 @@ #define SQLPP_TEXT_PARAMETER_TYPE_H #include +#include #include #include #include @@ -36,72 +37,17 @@ namespace sqlpp { template <> - struct parameter_value_t + struct parameter_value_t : public base_parameter_value { - using _value_type = text; - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value(""), _is_null(true) - { - } - - 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 = ""; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - parameter_value_t& operator=(const std::nullptr_t&) - { - _value = ""; - _is_null = true; - return *this; - } - - bool is_null() const - { - return _is_null; - } - - _cpp_value_type value() const - { - return _value; - } - - operator _cpp_value_type() const - { - return value(); - } + using base = base_parameter_value; + using base::base; + using base::operator=; template void _bind(Target& target, size_t index) const { target._bind_text_parameter(index, &_value, _is_null); } - - private: - _cpp_value_type _value; - bool _is_null; }; } #endif diff --git a/include/sqlpp11/data_types/time_point/parameter_type.h b/include/sqlpp11/data_types/time_point/parameter_type.h index 5e61b7c6..5cccac0b 100644 --- a/include/sqlpp11/data_types/time_point/parameter_type.h +++ b/include/sqlpp11/data_types/time_point/parameter_type.h @@ -28,6 +28,7 @@ #define SQLPP_TIME_POINT_PARAMETER_TYPE_H #include +#include #include #include #include @@ -35,73 +36,18 @@ namespace sqlpp { - // time_point parameter value template <> - struct parameter_value_t + struct parameter_value_t : public base_parameter_value { - 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; - } + using base = base_parameter_value; + using base::base; + using base::operator=; 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 From 21d633bdf49f53b7a8f00856137bbe0191469e69 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 31 Oct 2015 10:20:35 +0100 Subject: [PATCH 08/30] 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 From fae1f08d937e188efd7198e0403a2c151b2d26b0 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 31 Oct 2015 11:03:20 +0100 Subject: [PATCH 09/30] Added storage type to parameter_value_base struct This allows to store bool as signed char, the latter being the usual data type in connector libraries afaict --- include/sqlpp11/data_types/boolean/parameter_type.h | 4 ++-- include/sqlpp11/data_types/parameter_value_base.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/sqlpp11/data_types/boolean/parameter_type.h b/include/sqlpp11/data_types/boolean/parameter_type.h index 2e00b1b3..728140d2 100644 --- a/include/sqlpp11/data_types/boolean/parameter_type.h +++ b/include/sqlpp11/data_types/boolean/parameter_type.h @@ -35,9 +35,9 @@ namespace sqlpp { template <> - struct parameter_value_t : public base_parameter_value + struct parameter_value_t : public base_parameter_value { - using base = base_parameter_value; + using base = base_parameter_value; using base::base; using base::operator=; diff --git a/include/sqlpp11/data_types/parameter_value_base.h b/include/sqlpp11/data_types/parameter_value_base.h index 6c55be4e..19785d62 100644 --- a/include/sqlpp11/data_types/parameter_value_base.h +++ b/include/sqlpp11/data_types/parameter_value_base.h @@ -32,11 +32,12 @@ namespace sqlpp { - template + template struct base_parameter_value { using _value_type = DataType; using _cpp_value_type = typename _value_type::_cpp_value_type; + using _cpp_storage_type = StorageType; base_parameter_value() : _value{}, _is_null{true} { @@ -90,7 +91,7 @@ namespace sqlpp } protected: - _cpp_value_type _value; + _cpp_storage_type _value; bool _is_null; }; } From 51fd8c700751a421c9c7ee4e471f670e7eaaa715 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 31 Oct 2015 11:04:30 +0100 Subject: [PATCH 10/30] Removed warning for column_types include --- include/sqlpp11/column_types.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/sqlpp11/column_types.h b/include/sqlpp11/column_types.h index d9891f71..ed779981 100644 --- a/include/sqlpp11/column_types.h +++ b/include/sqlpp11/column_types.h @@ -27,7 +27,6 @@ #ifndef SQLPP_COLUMN_TYPES_H #define SQLPP_COLUMN_TYPES_H -#warning column_types.h is deprecated, please include data_types.h instead #include #endif From f6f8eb0befd2511b023e8b57a409fffa40ee1204 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 31 Oct 2015 18:04:16 +0100 Subject: [PATCH 11/30] Fixed serialization of result fields --- include/sqlpp11/result_field.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sqlpp11/result_field.h b/include/sqlpp11/result_field.h index 821880a8..a277078e 100644 --- a/include/sqlpp11/result_field.h +++ b/include/sqlpp11/result_field.h @@ -53,7 +53,7 @@ namespace sqlpp } else { - serialize(wrap_operand_t{t}, context); + serialize(wrap_operand_t>(t.value()), context); } return context; } From a73572ecbaa2fc8ef4dbaa3b77caf4f82daa0e74 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 31 Oct 2015 18:22:32 +0100 Subject: [PATCH 12/30] Some renaming cleanup --- include/sqlpp11/data_types/boolean.h | 2 +- .../boolean/{parameter_type.h => parameter_value.h} | 8 ++++---- include/sqlpp11/data_types/day_point.h | 2 +- .../day_point/{parameter_type.h => parameter_value.h} | 8 ++++---- include/sqlpp11/data_types/floating_point.h | 2 +- .../{parameter_type.h => parameter_value.h} | 8 ++++---- include/sqlpp11/data_types/integral.h | 2 +- .../integral/{parameter_type.h => parameter_value.h} | 8 ++++---- include/sqlpp11/data_types/parameter_value_base.h | 10 +++++----- include/sqlpp11/data_types/text.h | 2 +- .../text/{parameter_type.h => parameter_value.h} | 8 ++++---- include/sqlpp11/data_types/time_point.h | 2 +- .../time_point/{parameter_type.h => parameter_value.h} | 8 ++++---- 13 files changed, 35 insertions(+), 35 deletions(-) rename include/sqlpp11/data_types/boolean/{parameter_type.h => parameter_value.h} (89%) rename include/sqlpp11/data_types/day_point/{parameter_type.h => parameter_value.h} (89%) rename include/sqlpp11/data_types/floating_point/{parameter_type.h => parameter_value.h} (89%) rename include/sqlpp11/data_types/integral/{parameter_type.h => parameter_value.h} (89%) rename include/sqlpp11/data_types/text/{parameter_type.h => parameter_value.h} (91%) rename include/sqlpp11/data_types/time_point/{parameter_type.h => parameter_value.h} (89%) diff --git a/include/sqlpp11/data_types/boolean.h b/include/sqlpp11/data_types/boolean.h index b08fd5ce..cd865481 100644 --- a/include/sqlpp11/data_types/boolean.h +++ b/include/sqlpp11/data_types/boolean.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #endif diff --git a/include/sqlpp11/data_types/boolean/parameter_type.h b/include/sqlpp11/data_types/boolean/parameter_value.h similarity index 89% rename from include/sqlpp11/data_types/boolean/parameter_type.h rename to include/sqlpp11/data_types/boolean/parameter_value.h index 728140d2..796ef207 100644 --- a/include/sqlpp11/data_types/boolean/parameter_type.h +++ b/include/sqlpp11/data_types/boolean/parameter_value.h @@ -24,8 +24,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_BOOLEAN_PARAMETER_TYPE_H -#define SQLPP_BOOLEAN_PARAMETER_TYPE_H +#ifndef SQLPP_BOOLEAN_PARAMETER_VALUE_H +#define SQLPP_BOOLEAN_PARAMETER_VALUE_H #include #include @@ -35,9 +35,9 @@ namespace sqlpp { template <> - struct parameter_value_t : public base_parameter_value + struct parameter_value_t : public parameter_value_base { - using base = base_parameter_value; + using base = parameter_value_base; using base::base; using base::operator=; diff --git a/include/sqlpp11/data_types/day_point.h b/include/sqlpp11/data_types/day_point.h index 779dffae..5c43f96c 100644 --- a/include/sqlpp11/data_types/day_point.h +++ b/include/sqlpp11/data_types/day_point.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #endif diff --git a/include/sqlpp11/data_types/day_point/parameter_type.h b/include/sqlpp11/data_types/day_point/parameter_value.h similarity index 89% rename from include/sqlpp11/data_types/day_point/parameter_type.h rename to include/sqlpp11/data_types/day_point/parameter_value.h index 657bdbcc..12738827 100644 --- a/include/sqlpp11/data_types/day_point/parameter_type.h +++ b/include/sqlpp11/data_types/day_point/parameter_value.h @@ -24,8 +24,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_DAY_POINT_PARAMETER_TYPE_H -#define SQLPP_DAY_POINT_PARAMETER_TYPE_H +#ifndef SQLPP_DAY_POINT_PARAMETER_VALUE_H +#define SQLPP_DAY_POINT_PARAMETER_VALUE_H #include #include @@ -37,9 +37,9 @@ namespace sqlpp { template <> - struct parameter_value_t : public base_parameter_value + struct parameter_value_t : public parameter_value_base { - using base = base_parameter_value; + using base = parameter_value_base; using base::base; using base::operator=; diff --git a/include/sqlpp11/data_types/floating_point.h b/include/sqlpp11/data_types/floating_point.h index 2be6924a..ff9a6179 100644 --- a/include/sqlpp11/data_types/floating_point.h +++ b/include/sqlpp11/data_types/floating_point.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #endif diff --git a/include/sqlpp11/data_types/floating_point/parameter_type.h b/include/sqlpp11/data_types/floating_point/parameter_value.h similarity index 89% rename from include/sqlpp11/data_types/floating_point/parameter_type.h rename to include/sqlpp11/data_types/floating_point/parameter_value.h index d0ff6108..88c2cd02 100644 --- a/include/sqlpp11/data_types/floating_point/parameter_type.h +++ b/include/sqlpp11/data_types/floating_point/parameter_value.h @@ -24,8 +24,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_FLOATING_POINT_PARAMETER_TYPE_H -#define SQLPP_FLOATING_POINT_PARAMETER_TYPE_H +#ifndef SQLPP_FLOATING_POINT_PARAMETER_VALUE_H +#define SQLPP_FLOATING_POINT_PARAMETER_VALUE_H #include #include @@ -37,9 +37,9 @@ namespace sqlpp { template <> - struct parameter_value_t : public base_parameter_value + struct parameter_value_t : public parameter_value_base { - using base = base_parameter_value; + using base = parameter_value_base; using base::base; using base::operator=; diff --git a/include/sqlpp11/data_types/integral.h b/include/sqlpp11/data_types/integral.h index a4836b23..3b420ff2 100644 --- a/include/sqlpp11/data_types/integral.h +++ b/include/sqlpp11/data_types/integral.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #endif diff --git a/include/sqlpp11/data_types/integral/parameter_type.h b/include/sqlpp11/data_types/integral/parameter_value.h similarity index 89% rename from include/sqlpp11/data_types/integral/parameter_type.h rename to include/sqlpp11/data_types/integral/parameter_value.h index ba8e1d5d..8c29b9fc 100644 --- a/include/sqlpp11/data_types/integral/parameter_type.h +++ b/include/sqlpp11/data_types/integral/parameter_value.h @@ -24,8 +24,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_INTEGRAL_PARAMETER_TYPE_H -#define SQLPP_INTEGRAL_PARAMETER_TYPE_H +#ifndef SQLPP_INTEGRAL_PARAMETER_VALUE_H +#define SQLPP_INTEGRAL_PARAMETER_VALUE_H #include #include @@ -35,9 +35,9 @@ namespace sqlpp { template <> - struct parameter_value_t : public base_parameter_value + struct parameter_value_t : public parameter_value_base { - using base = base_parameter_value; + using base = parameter_value_base; using base::base; using base::operator=; diff --git a/include/sqlpp11/data_types/parameter_value_base.h b/include/sqlpp11/data_types/parameter_value_base.h index 19785d62..491666d4 100644 --- a/include/sqlpp11/data_types/parameter_value_base.h +++ b/include/sqlpp11/data_types/parameter_value_base.h @@ -33,28 +33,28 @@ namespace sqlpp { template - struct base_parameter_value + struct parameter_value_base { using _value_type = DataType; using _cpp_value_type = typename _value_type::_cpp_value_type; using _cpp_storage_type = StorageType; - base_parameter_value() : _value{}, _is_null{true} + parameter_value_base() : _value{}, _is_null{true} { } - explicit base_parameter_value(const _cpp_value_type& val) : _value(val), _is_null(false) + explicit parameter_value_base(const _cpp_value_type& val) : _value(val), _is_null(false) { } - base_parameter_value& operator=(const _cpp_value_type& val) + parameter_value_base& operator=(const _cpp_value_type& val) { _value = val; _is_null = false; return *this; } - base_parameter_value& operator=(const tvin_t>& t) + parameter_value_base& operator=(const tvin_t>& t) { if (t._is_trivial()) { diff --git a/include/sqlpp11/data_types/text.h b/include/sqlpp11/data_types/text.h index c50d4b3f..2c9327c7 100644 --- a/include/sqlpp11/data_types/text.h +++ b/include/sqlpp11/data_types/text.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include // text specific functions diff --git a/include/sqlpp11/data_types/text/parameter_type.h b/include/sqlpp11/data_types/text/parameter_value.h similarity index 91% rename from include/sqlpp11/data_types/text/parameter_type.h rename to include/sqlpp11/data_types/text/parameter_value.h index 8358696c..10d69d06 100644 --- a/include/sqlpp11/data_types/text/parameter_type.h +++ b/include/sqlpp11/data_types/text/parameter_value.h @@ -24,8 +24,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_TEXT_PARAMETER_TYPE_H -#define SQLPP_TEXT_PARAMETER_TYPE_H +#ifndef SQLPP_TEXT_PARAMETER_VALUE_H +#define SQLPP_TEXT_PARAMETER_VALUE_H #include #include @@ -37,9 +37,9 @@ namespace sqlpp { template <> - struct parameter_value_t : public base_parameter_value + struct parameter_value_t : public parameter_value_base { - using base = base_parameter_value; + using base = parameter_value_base; using base::base; using base::operator=; diff --git a/include/sqlpp11/data_types/time_point.h b/include/sqlpp11/data_types/time_point.h index e6f02703..83e481b7 100644 --- a/include/sqlpp11/data_types/time_point.h +++ b/include/sqlpp11/data_types/time_point.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #endif diff --git a/include/sqlpp11/data_types/time_point/parameter_type.h b/include/sqlpp11/data_types/time_point/parameter_value.h similarity index 89% rename from include/sqlpp11/data_types/time_point/parameter_type.h rename to include/sqlpp11/data_types/time_point/parameter_value.h index 5cccac0b..276c6942 100644 --- a/include/sqlpp11/data_types/time_point/parameter_type.h +++ b/include/sqlpp11/data_types/time_point/parameter_value.h @@ -24,8 +24,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SQLPP_TIME_POINT_PARAMETER_TYPE_H -#define SQLPP_TIME_POINT_PARAMETER_TYPE_H +#ifndef SQLPP_TIME_POINT_PARAMETER_VALUE_H +#define SQLPP_TIME_POINT_PARAMETER_VALUE_H #include #include @@ -37,9 +37,9 @@ namespace sqlpp { template <> - struct parameter_value_t : public base_parameter_value + struct parameter_value_t : public parameter_value_base { - using base = base_parameter_value; + using base = parameter_value_base; using base::base; using base::operator=; From 00fb11b2d4893074aa3799c4dcaaa88d08c3a0ad Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 31 Oct 2015 19:26:07 +0100 Subject: [PATCH 13/30] Cleaned up result_field_methods Much less clutter (and fixed null_is_trivial handling, I think) --- include/sqlpp11/result_field_methods.h | 62 ++++++++------------------ 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/include/sqlpp11/result_field_methods.h b/include/sqlpp11/result_field_methods.h index 9e82387e..7f256180 100644 --- a/include/sqlpp11/result_field_methods.h +++ b/include/sqlpp11/result_field_methods.h @@ -33,58 +33,34 @@ namespace sqlpp { - namespace detail - { - template - struct get_field_spec_impl - { - static_assert(wrong_t::value, "Invalid argument for get_field_spec"); - }; - - template