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/aggregate_functions.h b/include/sqlpp11/aggregate_functions.h new file mode 100644 index 00000000..4d250a77 --- /dev/null +++ b/include/sqlpp11/aggregate_functions.h @@ -0,0 +1,36 @@ +/* + * 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_AGGREGATE_FUNCTIONS_H +#define SQLPP_AGGREGATE_FUNCTIONS_H + +#include +#include +#include +#include +#include + +#endif diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/aggregate_functions/avg.h similarity index 99% rename from include/sqlpp11/avg.h rename to include/sqlpp11/aggregate_functions/avg.h index 1c7913d3..4d274d46 100644 --- a/include/sqlpp11/avg.h +++ b/include/sqlpp11/aggregate_functions/avg.h @@ -60,6 +60,7 @@ namespace sqlpp { using _traits = make_traits; using _nodes = detail::type_vector; + using _can_be_null = std::true_type; using _is_aggregate_expression = std::true_type; static_assert(is_noop::value or std::is_same::value, diff --git a/include/sqlpp11/count.h b/include/sqlpp11/aggregate_functions/count.h similarity index 98% rename from include/sqlpp11/count.h rename to include/sqlpp11/aggregate_functions/count.h index 6c50c599..225aa6a5 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/aggregate_functions/count.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { @@ -62,8 +62,8 @@ namespace sqlpp using _traits = make_traits; using _nodes = detail::type_vector; - using _is_aggregate_expression = std::true_type; using _can_be_null = std::false_type; + using _is_aggregate_expression = std::true_type; static_assert(is_noop::value or std::is_same::value, "count() used with flag other than 'distinct'"); diff --git a/include/sqlpp11/max.h b/include/sqlpp11/aggregate_functions/max.h similarity index 98% rename from include/sqlpp11/max.h rename to include/sqlpp11/aggregate_functions/max.h index 27792def..abe29d6a 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/aggregate_functions/max.h @@ -59,6 +59,7 @@ namespace sqlpp { using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _nodes = detail::type_vector; + using _can_be_null = std::true_type; using _is_aggregate_expression = std::true_type; using _auto_alias_t = max_alias_t; diff --git a/include/sqlpp11/min.h b/include/sqlpp11/aggregate_functions/min.h similarity index 98% rename from include/sqlpp11/min.h rename to include/sqlpp11/aggregate_functions/min.h index ea398289..a82bf9c7 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/aggregate_functions/min.h @@ -59,6 +59,7 @@ namespace sqlpp { using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _nodes = detail::type_vector; + using _can_be_null = std::true_type; using _is_aggregate_expression = std::true_type; using _auto_alias_t = min_alias_t; diff --git a/include/sqlpp11/sum.h b/include/sqlpp11/aggregate_functions/sum.h similarity index 99% rename from include/sqlpp11/sum.h rename to include/sqlpp11/aggregate_functions/sum.h index cc963789..cee32aed 100644 --- a/include/sqlpp11/sum.h +++ b/include/sqlpp11/aggregate_functions/sum.h @@ -60,6 +60,7 @@ namespace sqlpp { using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _nodes = detail::type_vector; + using _can_be_null = std::true_type; using _is_aggregate_expression = std::true_type; static_assert(is_noop::value or std::is_same::value, 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/bad_expression.h b/include/sqlpp11/bad_expression.h new file mode 100644 index 00000000..3aa43f0c --- /dev/null +++ b/include/sqlpp11/bad_expression.h @@ -0,0 +1,58 @@ +/* + * 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_BAD_EXPRESSION_H +#define SQLPP_BAD_EXPRESSION_H + +#include +#include + +namespace sqlpp +{ + SQLPP_PORTABLE_STATIC_ASSERT(assert_valid_operands, "Invalid operand(s)"); + + template + struct bad_expression + { + template + bad_expression(T&&...) + { + } + using _traits = make_traits; + using _nodes = detail::type_vector<>; + }; + + template + struct serializer_t> + { + using _serialize_check = assert_valid_operands; + using T = bad_expression; + + static Context& _(const T&, Context&); + }; +} + +#endif diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 0f60e025..9ab73977 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 @@ -218,16 +218,91 @@ namespace sqlpp check_rhs_in_arguments_t...>::_(); return {*static_cast(this), wrap_operand_t{t}...}; } - }; - template - struct alias_operators - { - template - expression_alias_t as(const alias_provider&) const + template + auto operator not() const -> return_type_not_t { + return_type_not::check::_(); + return {*static_cast(this)}; + } + + template + auto operator and(const R& r) const -> return_type_and_t + { + return_type_and::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator&(const R& r) const -> return_type_bitwise_and_t + { + return_type_bitwise_and::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator|(const R& r) const -> return_type_bitwise_or_t + { + return_type_bitwise_or::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator or(const R& r) const -> return_type_or_t + { + return_type_or::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator+(const R& r) const -> return_type_plus_t + { + return_type_plus::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator-(const R& r) const -> return_type_minus_t + { + return_type_minus::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator*(const R& r) const -> return_type_multiplies_t + { + return_type_multiplies::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator/(const R& r) const -> return_type_divides_t + { + return_type_divides::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator%(const R& r) const -> return_type_modulus_t + { + return_type_modulus::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + + template + auto operator+() const -> return_type_unary_plus_t + { + return_type_unary_plus::check::_(); + return {*static_cast(this)}; + } + + template + auto operator-() const -> return_type_unary_minus_t + { + return_type_unary_minus::check::_(); return {*static_cast(this)}; } }; } + #endif diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h deleted file mode 100644 index 620c5715..00000000 --- a/include/sqlpp11/boolean.h +++ /dev/null @@ -1,233 +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_H -#define SQLPP_BOOLEAN_H - -#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> - { - static_assert(std::is_same, boolean>::value, "field type mismatch"); - using _cpp_value_type = typename boolean::_cpp_value_type; - - result_field_t() : _is_valid(false), _is_null(true), _value(false) - { - } - - 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() == false; - } - - _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 false; - } - } - return _value; - } - - template - void _bind(Target& target, size_t i) - { - target._bind_boolean_result(i, &_value, &_is_null); - } - - private: - bool _is_valid; - 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/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/column.h b/include/sqlpp11/column.h index 22842dcc..6e4ef346 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -60,8 +60,6 @@ namespace sqlpp using _table = Table; using _alias_t = typename _spec_t::_alias_t; - template - using _is_valid_operand = is_valid_operand, T>; template using _is_valid_assignment_operand = is_valid_assignment_operand, T>; diff --git a/include/sqlpp11/column_types.h b/include/sqlpp11/column_types.h index bfc28128..ed779981 100644 --- a/include/sqlpp11/column_types.h +++ b/include/sqlpp11/column_types.h @@ -27,11 +27,6 @@ #ifndef SQLPP_COLUMN_TYPES_H #define SQLPP_COLUMN_TYPES_H -#include -#include -#include -#include -#include -#include +#include #endif 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..cd865481 --- /dev/null +++ b/include/sqlpp11/data_types/boolean.h @@ -0,0 +1,38 @@ +/* + * 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 + +#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..7ae416be 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..66528c63 --- /dev/null +++ b/include/sqlpp11/data_types/boolean/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_BOOLEAN_DATA_TYPE_H +#define SQLPP_BOOLEAN_DATA_TYPE_H + +#include + +namespace sqlpp +{ + struct boolean + { + using _traits = make_traits; + 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..41b946bd --- /dev/null +++ b/include/sqlpp11/data_types/boolean/expression_operators.h @@ -0,0 +1,64 @@ +/* + * 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 +#include +#include +#include + +namespace sqlpp +{ + template + struct expression_operators : public basic_expression_operators + { + }; + + template + struct return_type_and> + { + using check = consistent_t; + using type = logical_and_t, wrap_operand_t>; + }; + + template + struct return_type_or> + { + using check = consistent_t; + using type = logical_or_t, wrap_operand_t>; + }; + + template + struct return_type_not> + { + using check = consistent_t; + using type = logical_not_t>; + }; +} + +#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..68301c6b --- /dev/null +++ b/include/sqlpp11/data_types/boolean/operand.h @@ -0,0 +1,82 @@ +/* + * 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 +#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; + }; + + 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/parameter_value.h b/include/sqlpp11/data_types/boolean/parameter_value.h new file mode 100644 index 00000000..796ef207 --- /dev/null +++ b/include/sqlpp11/data_types/boolean/parameter_value.h @@ -0,0 +1,52 @@ +/* + * 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_VALUE_H +#define SQLPP_BOOLEAN_PARAMETER_VALUE_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t : public parameter_value_base + { + using base = parameter_value_base; + using base::base; + using base::operator=; + + template + void _bind(Target& target, size_t index) const + { + target._bind_boolean_parameter(index, &_value, _is_null); + } + }; +} + +#endif diff --git a/include/sqlpp11/data_types/boolean/result_field.h b/include/sqlpp11/data_types/boolean/result_field.h new file mode 100644 index 00000000..16ae9f4a --- /dev/null +++ b/include/sqlpp11/data_types/boolean/result_field.h @@ -0,0 +1,50 @@ +/* + * 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_RESULT_FIELD_H +#define SQLPP_BOOLEAN_RESULT_FIELD_H + +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct result_field_t> + : public result_field_base, signed char> + { + template + void _bind(Target& target, size_t index) + { + target._bind_boolean_result(index, &this->_value, &this->_is_null); + } + }; +} + +#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/data_types/day_point.h b/include/sqlpp11/data_types/day_point.h new file mode 100644 index 00000000..5c43f96c --- /dev/null +++ b/include/sqlpp11/data_types/day_point.h @@ -0,0 +1,38 @@ +/* + * 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_H +#define SQLPP_DAY_POINT_H + +#include +#include +#include +#include +#include +#include +#include + +#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..540264af --- /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..a589e752 --- /dev/null +++ b/include/sqlpp11/data_types/day_point/data_type.h @@ -0,0 +1,46 @@ +/* + * 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 _cpp_value_type = ::sqlpp::chrono::day_point; + + template + using _is_valid_operand = is_day_or_time_point_t; + template + using _is_valid_assignment_operand = is_day_point_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..b9475f59 --- /dev/null +++ b/include/sqlpp11/data_types/day_point/expression_operators.h @@ -0,0 +1,42 @@ +/* + * 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 + { + }; +} +#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..a7f714c8 --- /dev/null +++ b/include/sqlpp11/data_types/day_point/operand.h @@ -0,0 +1,84 @@ +/* + * 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 +#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; + }; + + 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/parameter_value.h b/include/sqlpp11/data_types/day_point/parameter_value.h new file mode 100644 index 00000000..12738827 --- /dev/null +++ b/include/sqlpp11/data_types/day_point/parameter_value.h @@ -0,0 +1,53 @@ +/* + * 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_VALUE_H +#define SQLPP_DAY_POINT_PARAMETER_VALUE_H + +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t : public parameter_value_base + { + using base = parameter_value_base; + using base::base; + using base::operator=; + + template + void _bind(Target& target, size_t index) const + { + target._bind_date_parameter(index, &_value, _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..bd3f7550 --- /dev/null +++ b/include/sqlpp11/data_types/day_point/result_field.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_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_base> + { + template + void _bind(Target& target, size_t index) + { + target._bind_date_result(index, &this->_value, &this->_is_null); + } + }; + + template + inline std::ostream& operator<<( + std::ostream& os, const result_field_t>& e) + { + if (e.is_null() and not NullIsTrivialValue) + { + 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.h b/include/sqlpp11/data_types/floating_point.h new file mode 100644 index 00000000..ff9a6179 --- /dev/null +++ b/include/sqlpp11/data_types/floating_point.h @@ -0,0 +1,38 @@ +/* + * 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_H +#define SQLPP_FLOATING_POINT_H + +#include +#include +#include +#include +#include +#include +#include + +#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..6daf5131 --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/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_FLOATING_POINT_COLUMN_OPERATORS_H +#define SQLPP_FLOATING_POINT_COLUMN_OPERATORS_H + +#include +#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..6c7e6a2f --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/data_type.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_DATA_TYPE_H +#define SQLPP_FLOATING_POINT_DATA_TYPE_H + +#include + +namespace sqlpp +{ + struct floating_point + { + using _traits = make_traits; + 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..1546b56c --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/expression_operators.h @@ -0,0 +1,86 @@ +/* + * 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 +#include +#include + +namespace sqlpp +{ + template + struct expression_operators : public basic_expression_operators + { + }; + + template + struct return_type_plus> + { + using check = consistent_t; + using type = plus_t, floating_point, wrap_operand_t>; + }; + + template + struct return_type_minus> + { + using check = consistent_t; + using type = minus_t, floating_point, wrap_operand_t>; + }; + + template + struct return_type_multiplies> + { + using check = consistent_t; + using type = multiplies_t, floating_point, wrap_operand_t>; + }; + + template + struct return_type_divides> + { + using check = consistent_t; + using type = divides_t, wrap_operand_t>; + }; + + template + struct return_type_unary_plus> + { + using check = consistent_t; + using type = unary_plus_t>; + }; + + template + struct return_type_unary_minus> + { + using check = consistent_t; + using type = unary_minus_t>; + }; +} +#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..ed53764c --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/operand.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_OPERAND_H +#define SQLPP_FLOATING_POINT_OPERAND_H + +#include +#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; + }; + + 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/parameter_value.h b/include/sqlpp11/data_types/floating_point/parameter_value.h new file mode 100644 index 00000000..88c2cd02 --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/parameter_value.h @@ -0,0 +1,53 @@ +/* + * 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_VALUE_H +#define SQLPP_FLOATING_POINT_PARAMETER_VALUE_H + +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t : public parameter_value_base + { + using base = parameter_value_base; + using base::base; + using base::operator=; + + template + void _bind(Target& target, size_t index) const + { + target._bind_floating_point_parameter(index, &_value, _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..e0e8aaf6 --- /dev/null +++ b/include/sqlpp11/data_types/floating_point/result_field.h @@ -0,0 +1,51 @@ +/* + * 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 +#include + +namespace sqlpp +{ + template + struct result_field_t> + : public result_field_base> + { + template + void _bind(Target& target, size_t index) + { + target._bind_floating_point_result(index, &this->_value, &this->_is_null); + } + }; +} +#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/data_types/integral.h b/include/sqlpp11/data_types/integral.h new file mode 100644 index 00000000..3b420ff2 --- /dev/null +++ b/include/sqlpp11/data_types/integral.h @@ -0,0 +1,38 @@ +/* + * 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_H +#define SQLPP_INTEGRAL_H + +#include +#include +#include +#include +#include +#include +#include + +#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..ee271fd7 --- /dev/null +++ b/include/sqlpp11/data_types/integral/column_operators.h @@ -0,0 +1,82 @@ +/* + * 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 +#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..cc60e273 --- /dev/null +++ b/include/sqlpp11/data_types/integral/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_INTEGRAL_DATA_TYPE_H +#define SQLPP_INTEGRAL_DATA_TYPE_H + +#include + +namespace sqlpp +{ + struct integral + { + using _traits = make_traits; + 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..6d2ab170 --- /dev/null +++ b/include/sqlpp11/data_types/integral/expression_operators.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_EXPRESSION_OPERATORS_H +#define SQLPP_INTEGRAL_EXPRESSION_OPERATORS_H + +#include +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct expression_operators : public basic_expression_operators + { + }; + + template + struct return_type_plus> + { + using check = consistent_t; + using type = plus_t, value_type_of>, wrap_operand_t>; + }; + + template + struct return_type_minus> + { + using check = consistent_t; + using type = minus_t, value_type_of>, wrap_operand_t>; + }; + + template + struct return_type_multiplies> + { + using check = consistent_t; + using type = multiplies_t, value_type_of>, wrap_operand_t>; + }; + + template + struct return_type_divides> + { + using check = consistent_t; + using type = divides_t, wrap_operand_t>; + }; + + template + struct return_type_modulus> + { + using check = consistent_t; + using type = modulus_t, wrap_operand_t>; + }; + + template + struct return_type_unary_plus> + { + using check = consistent_t; + using type = unary_plus_t>; + }; + + template + struct return_type_unary_minus> + { + using check = consistent_t; + using type = unary_minus_t>; + }; + + template + struct return_type_bitwise_and> + { + using check = consistent_t; + using type = bitwise_and_t, integral, wrap_operand_t>; + }; + + template + struct return_type_bitwise_or> + { + using check = consistent_t; + using type = bitwise_or_t, integral, wrap_operand_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..4625f06b --- /dev/null +++ b/include/sqlpp11/data_types/integral/operand.h @@ -0,0 +1,82 @@ +/* + * 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 +#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; + }; + + 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/parameter_value.h b/include/sqlpp11/data_types/integral/parameter_value.h new file mode 100644 index 00000000..8c29b9fc --- /dev/null +++ b/include/sqlpp11/data_types/integral/parameter_value.h @@ -0,0 +1,51 @@ +/* + * 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_VALUE_H +#define SQLPP_INTEGRAL_PARAMETER_VALUE_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t : public parameter_value_base + { + using base = parameter_value_base; + using base::base; + using base::operator=; + + template + void _bind(Target& target, size_t index) const + { + target._bind_integral_parameter(index, &_value, _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..9699ef05 --- /dev/null +++ b/include/sqlpp11/data_types/integral/result_field.h @@ -0,0 +1,49 @@ +/* + * 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 + +namespace sqlpp +{ + template + struct result_field_t> + : public result_field_base> + { + template + void _bind(Target& target, size_t index) + { + target._bind_integral_result(index, &this->_value, &this->_is_null); + } + }; +} +#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..a395b864 --- /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 and not std::is_same::value>::type> + { + using type = integral_operand; + }; +} +#endif 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/data_types/parameter_value_base.h b/include/sqlpp11/data_types/parameter_value_base.h new file mode 100644 index 00000000..491666d4 --- /dev/null +++ b/include/sqlpp11/data_types/parameter_value_base.h @@ -0,0 +1,98 @@ +/* + * 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 parameter_value_base + { + using _value_type = DataType; + using _cpp_value_type = typename _value_type::_cpp_value_type; + using _cpp_storage_type = StorageType; + + parameter_value_base() : _value{}, _is_null{true} + { + } + + explicit parameter_value_base(const _cpp_value_type& val) : _value(val), _is_null(false) + { + } + + parameter_value_base& operator=(const _cpp_value_type& val) + { + _value = val; + _is_null = false; + return *this; + } + + parameter_value_base& operator=(const tvin_t>& t) + { + if (t._is_trivial()) + { + _value = {}; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + + void set_null() + { + _value = {}; + _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_storage_type _value; + bool _is_null; + }; +} +#endif diff --git a/include/sqlpp11/data_types/text.h b/include/sqlpp11/data_types/text.h new file mode 100644 index 00000000..2c9327c7 --- /dev/null +++ b/include/sqlpp11/data_types/text.h @@ -0,0 +1,42 @@ +/* + * 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_H +#define SQLPP_TEXT_H + +#include +#include +#include +#include +#include +#include +#include + +// text specific functions +#include +#include + +#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..fdafacb3 --- /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 96% rename from include/sqlpp11/concat.h rename to include/sqlpp11/data_types/text/concat.h index dba4cddc..25164882 100644 --- a/include/sqlpp11/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/data_type.h b/include/sqlpp11/data_types/text/data_type.h new file mode 100644 index 00000000..7b90b5e0 --- /dev/null +++ b/include/sqlpp11/data_types/text/data_type.h @@ -0,0 +1,47 @@ +/* + * 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 _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..07a21318 --- /dev/null +++ b/include/sqlpp11/data_types/text/expression_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_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 return_type_like + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_like_t = typename return_type_like::type; + + template + struct return_type_like> + { + using check = consistent_t; + using type = like_t, wrap_operand_t>; + }; + + template + struct expression_operators : public basic_expression_operators + { + template + using _is_valid_operand = is_valid_operand; + + template + auto like(const R& r) const -> return_type_like_t + { + return_type_like::check::_(); + return {*static_cast(this), wrap_operand_t{r}}; + } + }; + + template + struct return_type_plus> + { + using check = consistent_t; + using type = concat_t, wrap_operand_t>; + }; +} +#endif diff --git a/include/sqlpp11/like.h b/include/sqlpp11/data_types/text/like.h similarity index 96% rename from include/sqlpp11/like.h rename to include/sqlpp11/data_types/text/like.h index 3ba011cf..dc86f211 100644 --- a/include/sqlpp11/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 new file mode 100644 index 00000000..d67a938e --- /dev/null +++ b/include/sqlpp11/data_types/text/operand.h @@ -0,0 +1,82 @@ +/* + * 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 +#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; + }; + + 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/parameter_value.h b/include/sqlpp11/data_types/text/parameter_value.h new file mode 100644 index 00000000..10d69d06 --- /dev/null +++ b/include/sqlpp11/data_types/text/parameter_value.h @@ -0,0 +1,53 @@ +/* + * 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_VALUE_H +#define SQLPP_TEXT_PARAMETER_VALUE_H + +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t : public parameter_value_base + { + using base = parameter_value_base; + using base::base; + using base::operator=; + + template + void _bind(Target& target, size_t index) const + { + target._bind_text_parameter(index, &_value, _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..447db5a5 --- /dev/null +++ b/include/sqlpp11/data_types/text/result_field.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_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_base> + { + template + void _bind(Target& target, size_t index) + { + const char* text{nullptr}; + size_t len{}; + target._bind_text_result(index, &text, &len); + this->_value = {text, len}; + this->_is_null = (len == 0); + } + }; + + template + inline std::ostream& operator<<( + std::ostream& os, const result_field_t>& e) + { + if (e.is_null() and not NullIsTrivialValue) + { + 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/data_types/time_point.h b/include/sqlpp11/data_types/time_point.h new file mode 100644 index 00000000..83e481b7 --- /dev/null +++ b/include/sqlpp11/data_types/time_point.h @@ -0,0 +1,38 @@ +/* + * 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_H +#define SQLPP_TIME_POINT_H + +#include +#include +#include +#include +#include +#include +#include + +#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..c59d7869 --- /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..f4507a03 --- /dev/null +++ b/include/sqlpp11/data_types/time_point/data_type.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_DATA_TYPE_H +#define SQLPP_TIME_POINT_DATA_TYPE_H + +#include +#include + +namespace sqlpp +{ + struct time_point + { + using _traits = make_traits; + using _cpp_value_type = ::sqlpp::chrono::mus_point; + + template + using _is_valid_operand = is_day_or_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..91baacd3 --- /dev/null +++ b/include/sqlpp11/data_types/time_point/expression_operators.h @@ -0,0 +1,43 @@ +/* + * 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 + { + }; +} +#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..2ff97840 --- /dev/null +++ b/include/sqlpp11/data_types/time_point/operand.h @@ -0,0 +1,87 @@ +/* + * 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 +#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; + }; + + 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/parameter_value.h b/include/sqlpp11/data_types/time_point/parameter_value.h new file mode 100644 index 00000000..276c6942 --- /dev/null +++ b/include/sqlpp11/data_types/time_point/parameter_value.h @@ -0,0 +1,53 @@ +/* + * 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_VALUE_H +#define SQLPP_TIME_POINT_PARAMETER_VALUE_H + +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template <> + struct parameter_value_t : public parameter_value_base + { + using base = parameter_value_base; + using base::base; + using base::operator=; + + template + void _bind(Target& target, size_t index) const + { + target._bind_date_time_parameter(index, &_value, _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..49e6283c --- /dev/null +++ b/include/sqlpp11/data_types/time_point/result_field.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_TIME_POINT_RESULT_FIELD_H +#define SQLPP_TIME_POINT_RESULT_FIELD_H + +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct result_field_t> + : public result_field_base> + { + template + void _bind(Target& target, size_t i) + { + target._bind_date_time_result(i, &this->_value, &this->_is_null); + } + }; + + template + inline std::ostream& operator<<( + std::ostream& os, const result_field_t>& e) + { + if (e.is_null() and not NullIsTrivialValue) + { + 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/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/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/day_point.h b/include/sqlpp11/day_point.h deleted file mode 100644 index 31072a7e..00000000 --- a/include/sqlpp11/day_point.h +++ /dev/null @@ -1,236 +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_H -#define SQLPP_DAY_POINT_H - -#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/detail/enable_if.h b/include/sqlpp11/detail/enable_if.h new file mode 100644 index 00000000..4f4cead7 --- /dev/null +++ b/include/sqlpp11/detail/enable_if.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_DETAIL_ENABLE_IF_H +#define SQLPP_DETAIL_ENABLE_IF_H + +#include + +namespace sqlpp +{ + namespace detail + { + template + using enable_if_t = typename std::enable_if::type; + } +} + +#endif diff --git a/include/sqlpp11/detail/void.h b/include/sqlpp11/detail/void.h new file mode 100644 index 00000000..10d48199 --- /dev/null +++ b/include/sqlpp11/detail/void.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_DETAIL_VOID_H +#define SQLPP_DETAIL_VOID_H + +namespace sqlpp +{ + namespace detail + { + template + struct void_impl + { + using type = void; + }; + + template + using void_t = typename void_impl::type; + } +} + +#endif diff --git a/include/sqlpp11/eval.h b/include/sqlpp11/eval.h index 2206e347..26760bf5 100644 --- a/include/sqlpp11/eval.h +++ b/include/sqlpp11/eval.h @@ -45,7 +45,7 @@ namespace sqlpp using _name_type = alias::a_t::_alias_t; using _value_type = value_type_of; using _field_spec = field_spec_t<_name_type, _value_type, true, false>; - using type = result_field_t<_value_type, Db, _field_spec>; + using type = result_field_t; }; template -#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/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/expression_return_types.h b/include/sqlpp11/expression_return_types.h new file mode 100644 index 00000000..589a2839 --- /dev/null +++ b/include/sqlpp11/expression_return_types.h @@ -0,0 +1,143 @@ +/* + * 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_RETURN_TYPES_H +#define SQLPP_EXPRESSION_RETURN_TYPES_H + +#include + +namespace sqlpp +{ + template + struct return_type_and + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_and_t = typename return_type_and::type; + + template + struct return_type_bitwise_and + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_bitwise_and_t = typename return_type_bitwise_and::type; + + template + struct return_type_or + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_or_t = typename return_type_or::type; + + template + struct return_type_bitwise_or + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_bitwise_or_t = typename return_type_bitwise_or::type; + + template + struct return_type_not + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_not_t = typename return_type_not::type; + + template + struct return_type_plus + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_plus_t = typename return_type_plus::type; + + template + struct return_type_minus + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_minus_t = typename return_type_minus::type; + + template + struct return_type_multiplies + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_multiplies_t = typename return_type_multiplies::type; + + template + struct return_type_divides + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_divides_t = typename return_type_divides::type; + + template + struct return_type_modulus + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_modulus_t = typename return_type_modulus::type; + + template + struct return_type_unary_plus + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_unary_plus_t = typename return_type_unary_plus::type; + + template + struct return_type_unary_minus + { + using check = assert_valid_operands; + using type = bad_expression; + }; + template + using return_type_unary_minus_t = typename return_type_unary_minus::type; +} + +#endif diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h deleted file mode 100644 index 053b624d..00000000 --- a/include/sqlpp11/floating_point.h +++ /dev/null @@ -1,290 +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_H -#define SQLPP_FLOATING_POINT_H - -#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/functions.h b/include/sqlpp11/functions.h index 16d54806..2f5925f4 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -29,20 +29,15 @@ #include #include -#include +#include +#include #include #include #include #include #include #include -#include #include -#include -#include -#include -#include -#include #include #include // Csaba Csoma suggests: unsafe_sql instead of verbatim #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/insert_value_list.h b/include/sqlpp11/insert_value_list.h index ae7be67f..059356bb 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h deleted file mode 100644 index 39c2ae4b..00000000 --- a/include/sqlpp11/integral.h +++ /dev/null @@ -1,327 +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_H -#define SQLPP_INTEGRAL_H - -#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/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/no_name.h b/include/sqlpp11/no_name.h new file mode 100644 index 00000000..2ba2e9e2 --- /dev/null +++ b/include/sqlpp11/no_name.h @@ -0,0 +1,36 @@ +/* + * 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_NO_NAME_H +#define SQLPP_NO_NAME_H + +namespace sqlpp +{ + struct no_name_t + { + }; +} +#endif diff --git a/include/sqlpp11/no_value.h b/include/sqlpp11/no_value.h index 9bea142d..68c842dc 100644 --- a/include/sqlpp11/no_value.h +++ b/include/sqlpp11/no_value.h @@ -28,13 +28,14 @@ #define SQLPP_NO_VALUE_H #include -#include +#include +#include namespace sqlpp { struct no_value_t { - using _tag = void; + using _traits = make_traits; }; template 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/operand_check.h b/include/sqlpp11/operand_check.h new file mode 100644 index 00000000..45df1cfb --- /dev/null +++ b/include/sqlpp11/operand_check.h @@ -0,0 +1,72 @@ +/* + * 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_OPERAND_CHECK_H +#define SQLPP_OPERAND_CHECK_H + +#include +#include + +namespace sqlpp +{ + template class Pred, typename Enable = void> + struct unary_operand_check + { + }; + + template class Pred> + struct unary_operand_check>::value>> + { + using type = void; + }; + + template class Pred> + using unary_operand_check_t = typename unary_operand_check::type; + + template class LPred, + typename R, + template class RPred, + typename Enable = void> + struct binary_operand_check + { + }; + + template class LPred, typename R, template class RPred> + struct binary_operand_check>::value and RPred>::value>> + { + using type = void; + }; + + template class LPred, typename R, template class RPred> + using binary_operand_check_t = typename binary_operand_check::type; +} + +#endif diff --git a/include/sqlpp11/operators.h b/include/sqlpp11/operators.h new file mode 100644 index 00000000..9a32c6ca --- /dev/null +++ b/include/sqlpp11/operators.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_OPERATORS_H +#define SQLPP_OPERATORS_H + +#include +#include + +namespace sqlpp +{ + template + auto operator and(const L& l, const R& r) -> return_type_and_t + { + return_type_and::check::_(); + return {wrap_operand_t{l}, wrap_operand_t{r}}; + } + template + auto operator or(const L& l, const R& r) -> return_type_or_t + { + return_type_or::check::_(); + return {wrap_operand_t{l}, wrap_operand_t{r}}; + } + template + auto operator not(const T& t) -> return_type_not_t + { + return_type_not::check::_(); + return {wrap_operand_t{t}}; + } +} + +#endif diff --git a/include/sqlpp11/result_field.h b/include/sqlpp11/result_field.h index 96d98422..f7ad360b 100644 --- a/include/sqlpp11/result_field.h +++ b/include/sqlpp11/result_field.h @@ -27,22 +27,25 @@ #ifndef SQLPP_RESULT_FIELD_H #define SQLPP_RESULT_FIELD_H +#include #include -#include +#include +#include namespace sqlpp { - template + template struct result_field_t { + using X = typename FieldSpec::incorrect; static_assert(wrong_t::value, "Missing specialization for result_field_t"); }; - template - struct serializer_t> + template + struct serializer_t> { using _serialize_check = consistent_t; - using T = result_field_t; + using T = result_field_t; static Context& _(const T& t, Context& context) { @@ -52,10 +55,16 @@ namespace sqlpp } else { - context << t.value(); + serialize(wrap_operand_t>(t.value()), context); } return context; } }; + + template + inline std::ostream& operator<<(std::ostream& os, const result_field_t& rf) + { + return serialize(rf, os); + } } #endif diff --git a/include/sqlpp11/result_field_base.h b/include/sqlpp11/result_field_base.h new file mode 100644 index 00000000..6d33ae35 --- /dev/null +++ b/include/sqlpp11/result_field_base.h @@ -0,0 +1,128 @@ +/* + * 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_RESULT_FIELD_BASE_H +#define SQLPP_RESULT_FIELD_BASE_H + +#include +#include +#include +#include +#include +#include + +namespace sqlpp +{ + template ::_cpp_value_type> + struct result_field_base + { + using _db_t = Db; + using _field_spec_t = FieldSpec; + using _cpp_value_type = typename value_type_of::_cpp_value_type; + using _cpp_storage_type = StorageType; + + static constexpr bool _null_is_trivial = + column_spec_can_be_null_t<_field_spec_t>::value and + (null_is_trivial_value_t<_field_spec_t>::value or not enforce_null_result_treatment_t<_db_t>::value); + using _traits = make_traits, + tag::is_result_field, + tag::is_expression, + tag_if>; + + using _nodes = detail::type_vector<>; + using _can_be_null = column_spec_can_be_null_t<_field_spec_t>; + + result_field_base() : _is_valid{false}, _is_null{true}, _value{} + { + } + + bool operator==(const _cpp_value_type& rhs) const + { + return value() == rhs; + } + + bool operator!=(const _cpp_value_type& rhs) const + { + return not operator==(rhs); + } + + void _validate() + { + _is_valid = true; + } + + void _invalidate() + { + _is_valid = false; + _is_null = true; + _value = {}; + } + + 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_storage_type{}; + } + + _cpp_value_type value() const + { + if (not _is_valid) + throw exception("accessing value in non-existing row"); + + if (_is_null) + { + if (not _null_is_trivial) + { + throw exception("accessing value of NULL field"); + } + else + { + return {}; + } + } + return _value; + } + + operator _cpp_value_type() const + { + return value(); + } + + bool _is_valid; + bool _is_null; + _cpp_storage_type _value; + }; +} +#endif diff --git a/include/sqlpp11/result_field_methods.h b/include/sqlpp11/result_field_methods.h deleted file mode 100644 index 6a2cb91d..00000000 --- a/include/sqlpp11/result_field_methods.h +++ /dev/null @@ -1,89 +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_RESULT_FIELD_METHODS_H -#define SQLPP_RESULT_FIELD_METHODS_H - -#include -#include - -namespace sqlpp -{ - namespace detail - { - template - struct get_field_spec_impl - { - static_assert(wrong_t::value, "Invalid argument for get_field_spec"); - }; - - template