diff --git a/include/sqlpp11/aggregate_functions/max.h b/include/sqlpp11/aggregate_functions/max.h index 7077d06f..5667e4cc 100644 --- a/include/sqlpp11/aggregate_functions/max.h +++ b/include/sqlpp11/aggregate_functions/max.h @@ -32,9 +32,7 @@ namespace sqlpp { template - struct max_t : public expression_operators, value_type_of_t>, - public aggregate_function_operators>, - public alias_operators> + struct max_t { using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _nodes = detail::type_vector; @@ -54,6 +52,12 @@ namespace sqlpp Expr _expr; }; + template + struct value_type_of> + { + using type = sqlpp::force_optional_t>; + }; + template Context& serialize(const max_t& t, Context& context) { diff --git a/include/sqlpp11/alias.h b/include/sqlpp11/alias.h deleted file mode 100644 index 65535596..00000000 --- a/include/sqlpp11/alias.h +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once - -/* - * 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. - */ - -#include - -namespace sqlpp -{ - template - struct expression_alias_t - { - using _traits = make_traits, tag::is_selectable, tag::is_alias>; - using _nodes = detail::type_vector; - -#warning Maybe make constructor of expressions private to force construction in the respective functions? - /* - static_assert(is_expression_t::value, "invalid argument for an expression alias"); - static_assert(not is_alias_t::value, "cannot create an alias of an alias"); - */ - - using _alias_t = typename AliasProvider::_alias_t; - - sqlpp::compat::optional if_(bool condition) const - { - return condition ? sqlpp::compat::make_optional(*this) : sqlpp::compat::nullopt; - } - - expression_alias_t(Expression expression) : _expression(expression) - { - } - - expression_alias_t(const expression_alias_t&) = default; - expression_alias_t(expression_alias_t&&) = default; - expression_alias_t& operator=(const expression_alias_t&) = default; - expression_alias_t& operator=(expression_alias_t&&) = default; - ~expression_alias_t() = default; - - Expression _expression; - }; - - template - struct value_type_of> - { - using type = value_type_of_t; - }; - - template - Context& serialize(const expression_alias_t& t, Context& context) - { - serialize_operand(t._expression, context); - context << " AS "; - context << name_of>::template char_ptr(); - return context; - } -} // namespace sqlpp diff --git a/include/sqlpp11/alias_operators.h b/include/sqlpp11/alias_operators.h index 023a4ec6..dc37f6e5 100644 --- a/include/sqlpp11/alias_operators.h +++ b/include/sqlpp11/alias_operators.h @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include namespace sqlpp { @@ -34,7 +34,7 @@ namespace sqlpp struct alias_operators { template - expression_alias_t as(const alias_provider& /*unused*/) const + as_expression as(const alias_provider& /*unused*/) const { return {*static_cast(this)}; } diff --git a/include/sqlpp11/auto_alias.h b/include/sqlpp11/auto_alias.h index 831ea387..1d03b389 100644 --- a/include/sqlpp11/auto_alias.h +++ b/include/sqlpp11/auto_alias.h @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include namespace sqlpp { @@ -53,7 +53,7 @@ namespace sqlpp template struct auto_alias_impl::value>::type> { - using type = expression_alias_t; + using type = as_expression; }; } // namespace detail diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 8806566b..c4522c84 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index e9158300..005010ea 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include #include @@ -75,7 +75,7 @@ namespace sqlpp } template - expression_alias_t as(const alias_provider& /*unused*/) const + as_expression as(const alias_provider& /*unused*/) const { return {*this}; } diff --git a/include/sqlpp11/comparison_expression.h b/include/sqlpp11/comparison_expression.h deleted file mode 100644 index 8990dc8d..00000000 --- a/include/sqlpp11/comparison_expression.h +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -/* -Copyright (c) 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -#include - -namespace sqlpp -{ - template - struct comparison_expression - { - L l; - R r; - }; - - template - using check_comparison_args = std::enable_if_t::value>; - -#if 0 - template - struct nodes_of> - { - using type = type_vector; - }; - - SQLPP_WRAPPED_STATIC_ASSERT(assert_comparison_operands_are_compatible, - "comparison operands must have compatible value types"); - - template - constexpr auto check_comparison_args() - { - if constexpr (not values_are_compatible_v) - { - return failed{}; - } - else - { - return succeeded{}; - } - } - - template - struct value_type_of_t> - { - using type = bool; - }; - - template - constexpr auto requires_braces_v> = true; - - template - [[nodiscard]] auto to_sql_string(Context& context, const comparison_expression& t) - { - return to_sql_string(context, embrace(t.l)) + Operator::symbol + to_sql_string(context, embrace(t.r)); - } -#endif -} // namespace sqlpp diff --git a/include/sqlpp11/expression.h b/include/sqlpp11/expression.h index 3db047dd..afe7b5d7 100644 --- a/include/sqlpp11/expression.h +++ b/include/sqlpp11/expression.h @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include #include diff --git a/include/sqlpp11/operator.h b/include/sqlpp11/operator.h index 8c9091a0..78e9947e 100644 --- a/include/sqlpp11/operator.h +++ b/include/sqlpp11/operator.h @@ -33,51 +33,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // logical -#include -#include -#include +#include // comparison -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - +#include +#include // arithmetic -#include -#include -#include -#include -#include -#include +#include // binary -#include -#include -#include -#include -#include -#include +#include // assignment -#include +#include // misc -#include +#include -#include -#include -#include +#include -#include -#include - -#include +#include diff --git a/include/sqlpp11/arithmetic_expression.h b/include/sqlpp11/operator/arithmetic_expression.h similarity index 60% rename from include/sqlpp11/arithmetic_expression.h rename to include/sqlpp11/operator/arithmetic_expression.h index 9d44772d..1e1eda5d 100644 --- a/include/sqlpp11/arithmetic_expression.h +++ b/include/sqlpp11/operator/arithmetic_expression.h @@ -68,6 +68,20 @@ namespace sqlpp template using check_arithmetic_args = std::enable_if_t::value and has_numeric_value::value>; +#warning: need to document that this is on purpose (not integral, or unsigned integral, or floating_point) because it is difficult to know for the library to know what the actual result type will be (it is difficult to guess in C++ already, and it is probably different from DB vendor to vendor). + template + struct value_type_of> + : std::conditional>::value or sqlpp::is_optional>::value, + sqlpp::compat::optional, + numeric> {}; + +#warning: As above. + template + struct value_type_of> + : std::conditional>::value, + sqlpp::compat::optional, + numeric> {}; + #if 0 template @@ -104,4 +118,71 @@ namespace sqlpp return to_sql_string(context, t._l) + Operator::symbol + to_sql_string(context, embrace(t._r)); } #endif + struct plus + { + static constexpr auto symbol = " + "; + }; + + template > + constexpr auto operator+(L l, R r) -> arithmetic_expression + { + return {std::move(l), std::move(r)}; + } + struct minus + { + static constexpr auto symbol = " - "; + }; + + template > + constexpr auto operator-(L l, R r) -> arithmetic_expression + { + return {std::move(l), std::move(r)}; + } + struct multiplies + { + static constexpr auto symbol = " * "; + }; + + template > + constexpr auto operator*(L l, R r) -> arithmetic_expression + { + return {std::move(l), std::move(r)}; + } + + struct divides + { + static constexpr auto symbol = " / "; + }; + + template > + constexpr auto operator/(L l, R r) -> arithmetic_expression + { + return {std::move(l), std::move(r)}; + } + + struct negate + { + static constexpr auto symbol = "-"; + }; + + template > + constexpr auto operator-(R r) -> unary_arithmetic_expression + { + return {std::move(r)}; + } + + struct modulus + { + static constexpr auto symbol = " % "; + }; + + template + using check_modulus_args = std::enable_if_t::value and has_integral_value::value>; + + template > + constexpr auto operator%(L l, R r) -> arithmetic_expression + { + return {std::move(l), std::move(r)}; + } + } // namespace sqlpp diff --git a/include/sqlpp11/operator/as.h b/include/sqlpp11/operator/as.h deleted file mode 100644 index 2089f214..00000000 --- a/include/sqlpp11/operator/as.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -#include -#include - -namespace sqlpp -{ - template - using check_as_args = std::enable_if_t< - is_expression_t::value and not is_alias_t::value and has_name::value - >; - - template > - constexpr auto as(Expr expr, const AliasProvider&) -> expression_alias_t - { - return {std::move(expr)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/as_expression.h b/include/sqlpp11/operator/as_expression.h new file mode 100644 index 00000000..5da2d55e --- /dev/null +++ b/include/sqlpp11/operator/as_expression.h @@ -0,0 +1,93 @@ +#pragma once + +/* +Copyright (c) 2017, 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: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. 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. +*/ + +#include + +#include +#include + +namespace sqlpp +{ + template + struct as_expression + { + using _traits = make_traits, tag::is_selectable, tag::is_alias>; + using _nodes = detail::type_vector; + +#warning Maybe make constructor of expressions private to force construction in the respective functions? + /* + static_assert(is_expression_t::value, "invalid argument for an expression alias"); + static_assert(not is_alias_t::value, "cannot create an alias of an alias"); + */ + + using _alias_t = typename AliasProvider::_alias_t; + + sqlpp::compat::optional if_(bool condition) const + { + return condition ? sqlpp::compat::make_optional(*this) : sqlpp::compat::nullopt; + } + + as_expression(Expression expression) : _expression(expression) + { + } + + as_expression(const as_expression&) = default; + as_expression(as_expression&&) = default; + as_expression& operator=(const as_expression&) = default; + as_expression& operator=(as_expression&&) = default; + ~as_expression() = default; + + Expression _expression; + }; + + template + struct value_type_of> + { + using type = value_type_of_t; + }; + + template + Context& serialize(const as_expression& t, Context& context) + { + serialize_operand(t._expression, context); + context << " AS "; + context << name_of>::template char_ptr(); + return context; + } + template + using check_as_args = std::enable_if_t< + is_expression_t::value and not is_alias_t::value and has_name::value + >; + + template > + constexpr auto as(Expr expr, const AliasProvider&) -> as_expression + { + return {std::move(expr)}; + } + +} // namespace sqlpp diff --git a/include/sqlpp11/operator/asc.h b/include/sqlpp11/operator/asc.h deleted file mode 100644 index 71ae28d7..00000000 --- a/include/sqlpp11/operator/asc.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - template > - constexpr auto asc(L l) -> sort_order_expression - { - return {l, sort_order::asc}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/assign.h b/include/sqlpp11/operator/assign_expression.h similarity index 100% rename from include/sqlpp11/operator/assign.h rename to include/sqlpp11/operator/assign_expression.h diff --git a/include/sqlpp11/operator/bit_and.h b/include/sqlpp11/operator/bit_and.h deleted file mode 100644 index 6b74b25e..00000000 --- a/include/sqlpp11/operator/bit_and.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct bit_and - { - static constexpr auto symbol = " & "; - }; - - template > - constexpr auto operator&(L l, R r) -> bit_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/bit_expression.h b/include/sqlpp11/operator/bit_expression.h similarity index 60% rename from include/sqlpp11/bit_expression.h rename to include/sqlpp11/operator/bit_expression.h index 007ab2c1..28c12958 100644 --- a/include/sqlpp11/bit_expression.h +++ b/include/sqlpp11/operator/bit_expression.h @@ -65,6 +65,22 @@ namespace sqlpp R _r; }; + template + struct value_type_of> + : std::conditional>::value or sqlpp::is_optional>::value, + force_optional_t>, + value_type_of_t> + { + }; + + template + struct value_type_of> + : std::conditional>::value, + force_optional_t>, + value_type_of_t> + { + }; + template using check_bit_expression_args = std::enable_if_t::value and has_integral_value::value>; @@ -97,4 +113,70 @@ namespace sqlpp } #endif + struct bit_and + { + static constexpr auto symbol = " & "; + }; + + template > + constexpr auto operator&(L l, R r) -> bit_expression + { + return {std::move(l), std::move(r)}; + } + + struct bit_or + { + static constexpr auto symbol = " | "; + }; + + template > + constexpr auto operator|(L l, R r) -> bit_expression + { + return {std::move(l), std::move(r)}; + } + + struct bit_xor + { + static constexpr auto symbol = " ^ "; + }; + + template > + constexpr auto operator^(L l, R r) -> bit_expression + { + return {std::move(l), std::move(r)}; + } + + struct bit_not + { + static constexpr auto symbol = "~"; + }; + + template > + constexpr auto operator~(R r) -> unary_bit_expression + { + return {std::move(r)}; + } + + struct bit_shift_left + { + static constexpr auto symbol = " << "; + }; + + template > + constexpr auto operator<<(L l, R r) -> bit_expression + { + return {std::move(l), std::move(r)}; + } + + struct bit_shift_right + { + static constexpr auto symbol = " >> "; + }; + + template > + constexpr auto operator>>(L l, R r) -> bit_expression + { + return {std::move(l), std::move(r)}; + } + } // namespace sqlpp diff --git a/include/sqlpp11/operator/bit_not.h b/include/sqlpp11/operator/bit_not.h deleted file mode 100644 index bcfe9be6..00000000 --- a/include/sqlpp11/operator/bit_not.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct bit_not - { - static constexpr auto symbol = "~"; - }; - - template > - constexpr auto operator~(R r) -> unary_bit_expression - { - return {std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/bit_or.h b/include/sqlpp11/operator/bit_or.h deleted file mode 100644 index 2112d739..00000000 --- a/include/sqlpp11/operator/bit_or.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct bit_or - { - static constexpr auto symbol = " | "; - }; - - template > - constexpr auto operator|(L l, R r) -> bit_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/bit_shift_left.h b/include/sqlpp11/operator/bit_shift_left.h deleted file mode 100644 index 5cff1ad9..00000000 --- a/include/sqlpp11/operator/bit_shift_left.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct bit_shift_left - { - static constexpr auto symbol = " << "; - }; - - template > - constexpr auto operator<<(L l, R r) -> bit_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/bit_shift_right.h b/include/sqlpp11/operator/bit_shift_right.h deleted file mode 100644 index 5bc19bbb..00000000 --- a/include/sqlpp11/operator/bit_shift_right.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct bit_shift_right - { - static constexpr auto symbol = " >> "; - }; - - template > - constexpr auto operator>>(L l, R r) -> bit_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/bit_xor.h b/include/sqlpp11/operator/bit_xor.h deleted file mode 100644 index cfcf0c51..00000000 --- a/include/sqlpp11/operator/bit_xor.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct bit_xor - { - static constexpr auto symbol = " ^ "; - }; - - template > - constexpr auto operator^(L l, R r) -> bit_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/comparison_expression.h b/include/sqlpp11/operator/comparison_expression.h new file mode 100644 index 00000000..c88d7436 --- /dev/null +++ b/include/sqlpp11/operator/comparison_expression.h @@ -0,0 +1,236 @@ +#pragma once + +/* +Copyright (c) 2018, 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: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. 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. +*/ + +#include + +#include + +namespace sqlpp +{ + template + struct comparison_expression + { + L l; + R r; + }; + + template + using check_comparison_args = std::enable_if_t::value>; + + template + struct value_type_of> + : std::conditional>::value or sqlpp::is_optional>::value, + sqlpp::compat::optional, + boolean> + { + }; + + struct op_is_null; + struct op_is_not_null; + struct is_distinct_from; + struct is_not_distinct_from; + + template + struct value_type_of> { using type = boolean; }; + + template + struct value_type_of> { using type = boolean; }; + + template + struct value_type_of> { using type = boolean; }; + + template + struct value_type_of> { using type = boolean; }; + + + +#if 0 + template + struct nodes_of> + { + using type = type_vector; + }; + + SQLPP_WRAPPED_STATIC_ASSERT(assert_comparison_operands_are_compatible, + "comparison operands must have compatible value types"); + + template + constexpr auto check_comparison_args() + { + if constexpr (not values_are_compatible_v) + { + return failed{}; + } + else + { + return succeeded{}; + } + } + + template + struct value_type_of_t> + { + using type = bool; + }; + + template + constexpr auto requires_braces_v> = true; + + template + [[nodiscard]] auto to_sql_string(Context& context, const comparison_expression& t) + { + return to_sql_string(context, embrace(t.l)) + Operator::symbol + to_sql_string(context, embrace(t.r)); + } +#endif + + struct less + { + static constexpr auto symbol = " < "; + }; + + template > + constexpr auto operator<(L l, R r) -> comparison_expression + { + return {std::move(l), std::move(r)}; + } + + struct less_equal + { + static constexpr auto symbol = " <= "; + }; + + template > + constexpr auto operator<=(L l, R r) -> comparison_expression + { + return {std::move(l), std::move(r)}; + } + + struct equal_to + { + static constexpr auto symbol = " = "; + }; + + template > + constexpr auto operator==(L l, R r) -> comparison_expression + { + return {l, r}; + } + + struct not_equal_to + { + static constexpr auto symbol = " != "; + }; + + template > + constexpr auto operator!=(L l, R r) -> comparison_expression + { + return {std::move(l), std::move(r)}; + } + + struct greater_equal + { + static constexpr auto symbol = " >= "; + }; + + template > + constexpr auto operator>=(L l, R r) -> comparison_expression + { + return {std::move(l), std::move(r)}; + } + + struct greater + { + static constexpr auto symbol = " > "; + }; + + template > + constexpr auto operator>(L l, R r) -> comparison_expression + { + return {std::move(l), std::move(r)}; + } + + struct op_is_null + { + static constexpr auto symbol = " IS "; + }; + + template + constexpr auto is_null(L l) -> comparison_expression + { + return {l}; + } + + struct op_is_not_null + { + static constexpr auto symbol = " IS NOT "; + }; + + template + constexpr auto is_not_null(L l) -> comparison_expression + { + return {l}; + } + + struct is_distinct_from + { + static constexpr auto symbol = " IS DISTINCT FROM "; // sql standard + // mysql has NULL-safe equal `<=>` which is_null equivalent to `IS NOT DISTINCT FROM` + // sqlite3 has `IS NOT` + }; + + template > + constexpr auto is_distinct_from(L l, R r) -> comparison_expression + { + return {l, r}; + } + + struct is_not_distinct_from + { + static constexpr auto symbol = " IS NOT DISTINCT FROM "; // sql standard + // mysql has NULL-safe equal `<=>` + // sqlite3 has `IS` + }; + + template > + constexpr auto is_not_distinct_from(L l, R r) -> comparison_expression + { + return {l, r}; + } + + struct operator_like + { + static constexpr auto symbol = " LIKE "; + }; + + template > + constexpr auto like(L l, R r) -> comparison_expression + { + return {std::move(l), std::move(r)}; + } + +} // namespace sqlpp diff --git a/include/sqlpp11/operator/desc.h b/include/sqlpp11/operator/desc.h deleted file mode 100644 index b92f4ea2..00000000 --- a/include/sqlpp11/operator/desc.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - template > - constexpr auto desc(L l) -> sort_order_expression - { - return {l, sort_order::desc}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/divides.h b/include/sqlpp11/operator/divides.h deleted file mode 100644 index a19fe50c..00000000 --- a/include/sqlpp11/operator/divides.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -#include - -namespace sqlpp -{ - struct divides - { - static constexpr auto symbol = " / "; - }; - - template > - constexpr auto operator/(L l, R r) -> arithmetic_expression - { - return {std::move(l), std::move(r)}; - } -} // namespace sqlpp diff --git a/include/sqlpp11/operator/equal_to.h b/include/sqlpp11/operator/equal_to.h deleted file mode 100644 index 02e29a90..00000000 --- a/include/sqlpp11/operator/equal_to.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017- 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct equal_to - { - static constexpr auto symbol = " = "; - }; - - template > - constexpr auto operator==(L l, R r) -> comparison_expression - { - return {l, r}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/exists.h b/include/sqlpp11/operator/exists_expression.h similarity index 97% rename from include/sqlpp11/operator/exists.h rename to include/sqlpp11/operator/exists_expression.h index dd055bff..86bf8115 100644 --- a/include/sqlpp11/operator/exists.h +++ b/include/sqlpp11/operator/exists_expression.h @@ -39,6 +39,12 @@ namespace sqlpp template using check_exists_arg = std::enable_if_t::value and has_result_row_t::value>; + template + struct value_type_of> + { + using type = boolean; + }; + #warning: Document that functions dont come with their default alias any more template > constexpr auto exists(SubSelect sub_select) -> exists_t @@ -53,12 +59,6 @@ namespace sqlpp using type = type_vector; }; - template - struct value_type_of_t> - { - using type = bool; - }; - template [[nodiscard]] auto to_sql_string(Context& context, const exists_t& t) { diff --git a/include/sqlpp11/operator/greater.h b/include/sqlpp11/operator/greater.h deleted file mode 100644 index e5f8281e..00000000 --- a/include/sqlpp11/operator/greater.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017- 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct greater - { - static constexpr auto symbol = " > "; - }; - - template > - constexpr auto operator>(L l, R r) -> comparison_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/greater_equal.h b/include/sqlpp11/operator/greater_equal.h deleted file mode 100644 index ee0c5a97..00000000 --- a/include/sqlpp11/operator/greater_equal.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017- 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct greater_equal - { - static constexpr auto symbol = " >= "; - }; - - template > - constexpr auto operator>=(L l, R r) -> comparison_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/in.h b/include/sqlpp11/operator/in.h deleted file mode 100644 index c5cb8de9..00000000 --- a/include/sqlpp11/operator/in.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -/* -Copyright (c) 2024, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include -#include - -#include - -namespace sqlpp -{ - struct operator_in - { - static constexpr auto symbol = " IN "; - }; - -#warning: something.in(select(...)); should be suppported as is - template > - constexpr auto in(L l, std::tuple args) -> in_expression> - { - return {std::move(l), std::move(args)}; - } - - template > - constexpr auto in(L l, Args... args) -> in_expression> - { - return {std::move(l), std::make_tuple(std::move(args)...)}; - } - - template > - constexpr auto in(L l, std::vector args) -> in_expression> - { - return {std::move(l), std::move(args)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/in_expression.h b/include/sqlpp11/operator/in_expression.h new file mode 100644 index 00000000..8f5128f3 --- /dev/null +++ b/include/sqlpp11/operator/in_expression.h @@ -0,0 +1,153 @@ +#pragma once + +/* +Copyright (c) 2024, 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: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. 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. +*/ + +#include +#include + +#include +#include + +namespace sqlpp +{ + template + struct in_expression + { + L l; + Container container; + }; + + template + struct in_expression> + { + L l; + std::tuple args; + }; + + template + using check_in_args = + std::enable_if_t<(sizeof...(Args) != 0) and logic::all_t::value...>::value>; + + template + struct value_type_of>> + : std::conditional>::value or sqlpp::is_optional>::value, + sqlpp::compat::optional, + boolean> + { + }; + + template + struct value_type_of>> + : std::conditional>::value or + logic::any_t>::value...>::value, + sqlpp::compat::optional, + boolean> + { + }; + + /* + + template + struct nodes_of> + { + using type = type_vector; + }; + + template + constexpr auto in(L l, Args... args) + -> std::enable_if_t<((sizeof...(Args) > 0) and ... and values_are_compatible_v), in_t> + { + return in_t{l, std::tuple{args...}}; + } + + template + constexpr auto requires_braces_v> = true; + + template + [[nodiscard]] auto to_sql_string(Context& context, const in_t& t) + { + if constexpr (sizeof...(Args) == 1) + { + return to_sql_string(context, embrace(t.l)) + " IN(" + to_sql_string(context, std::get<0>(t.args)) + ")"; + } + else + { + return to_sql_string(context, embrace(t.l)) + " IN(" + tuple_to_sql_string(context, ", ", t.args) + ")"; + } + } + */ + + struct operator_in + { + static constexpr auto symbol = " IN "; + }; + +#warning: something.in(select(...)); should be suppported as is, need to test + template > + constexpr auto in(L l, std::tuple args) -> in_expression> + { + return {std::move(l), std::move(args)}; + } + + template > + constexpr auto in(L l, Args... args) -> in_expression> + { + return {std::move(l), std::make_tuple(std::move(args)...)}; + } + + template > + constexpr auto in(L l, std::vector args) -> in_expression> + { + return {std::move(l), std::move(args)}; + } + + struct operator_not_in + { + static constexpr auto symbol = " NOT IN "; + }; + +#warning: something.not_in(select(...)); should be suppported as is + template > + constexpr auto not_in(L l, std::tuple args) -> in_expression> + { + return {std::move(l), std::move(args)}; + } + + template > + constexpr auto not_in(L l, Args... args) -> in_expression> + { + return {std::move(l), std::make_tuple(std::move(args)...)}; + } + + template > + constexpr auto not_in(L l, std::vector args) -> in_expression> + { + return {std::move(l), std::move(args)}; + } + + +} // namespace sqlpp diff --git a/include/sqlpp11/operator/is_distinct_from.h b/include/sqlpp11/operator/is_distinct_from.h deleted file mode 100644 index f53d439a..00000000 --- a/include/sqlpp11/operator/is_distinct_from.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017- 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct is_distinct_from - { - static constexpr auto symbol = " IS DISTINCT FROM "; // sql standard - // mysql has NULL-safe equal `<=>` which is equivalent to `IS NOT DISTINCT FROM` - // sqlite3 has `IS NOT` - }; - - template > - constexpr auto is_distinct_from(L l, R r) -> comparison_expression - { - return {l, r}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/is_not_distinct_from.h b/include/sqlpp11/operator/is_not_distinct_from.h deleted file mode 100644 index 0347a0c2..00000000 --- a/include/sqlpp11/operator/is_not_distinct_from.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017- 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct is_not_distinct_from - { - static constexpr auto symbol = " IS NOT DISTINCT FROM "; // sql standard - // mysql has NULL-safe equal `<=>` - // sqlite3 has `IS` - }; - - template > - constexpr auto is_not_distinct_from(L l, R r) -> comparison_expression - { - return {l, r}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/is_not_null.h b/include/sqlpp11/operator/is_not_null.h deleted file mode 100644 index 85f2f02a..00000000 --- a/include/sqlpp11/operator/is_not_null.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct is_not - { - static constexpr auto symbol = " IS NOT "; - }; - - template - constexpr auto is_null(L l) -> comparison_expression - { - return {l}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/is_null.h b/include/sqlpp11/operator/is_null.h deleted file mode 100644 index 60f88769..00000000 --- a/include/sqlpp11/operator/is_null.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct is - { - static constexpr auto symbol = " IS "; - }; - - template - constexpr auto is_null(L l) -> comparison_expression - { - return {l}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/less.h b/include/sqlpp11/operator/less.h deleted file mode 100644 index 6b2fb94e..00000000 --- a/include/sqlpp11/operator/less.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017- 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct less - { - static constexpr auto symbol = " < "; - }; - - template > - constexpr auto operator<(L l, R r) -> comparison_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/less_equal.h b/include/sqlpp11/operator/less_equal.h deleted file mode 100644 index b2a22548..00000000 --- a/include/sqlpp11/operator/less_equal.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017- 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct less_equal - { - static constexpr auto symbol = " <= "; - }; - - template > - constexpr auto operator<=(L l, R r) -> comparison_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/like.h b/include/sqlpp11/operator/like.h deleted file mode 100644 index cd465bbb..00000000 --- a/include/sqlpp11/operator/like.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017- 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct operator_like - { - static constexpr auto symbol = " LIKE "; - }; - - template > - constexpr auto like(L l, R r) -> comparison_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/logical_and.h b/include/sqlpp11/operator/logical_and.h deleted file mode 100644 index 15c22c87..00000000 --- a/include/sqlpp11/operator/logical_and.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct logical_and - { - static constexpr auto symbol = " AND "; - }; - - template > - constexpr auto operator and(L l, R r) -> logical_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/logical_expression.h b/include/sqlpp11/operator/logical_expression.h similarity index 72% rename from include/sqlpp11/logical_expression.h rename to include/sqlpp11/operator/logical_expression.h index 2497bc29..de5ce0da 100644 --- a/include/sqlpp11/logical_expression.h +++ b/include/sqlpp11/operator/logical_expression.h @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include +#include //#include //#include //#include @@ -51,7 +51,7 @@ namespace sqlpp ~logical_expression() = default; template - expression_alias_t as(const alias_provider& /*unused*/) const + as_expression as(const alias_provider& /*unused*/) const { return {*this}; } @@ -60,6 +60,17 @@ namespace sqlpp R _r; }; + template + using check_logical_args = std::enable_if_t::value and has_boolean_value::value>; + + template + struct value_type_of> + : std::conditional>::value or sqlpp::is_optional>::value, + sqlpp::compat::optional, + boolean> + { + }; + template struct unary_logical_expression { @@ -74,7 +85,7 @@ namespace sqlpp ~unary_logical_expression() = default; template - expression_alias_t as(const alias_provider& /*unused*/) const + as_expression as(const alias_provider& /*unused*/) const { return {*this}; } @@ -82,8 +93,13 @@ namespace sqlpp R _r; }; - template - using check_logical_args = std::enable_if_t::value and has_boolean_value::value>; + template + struct value_type_of> + : std::conditional>::value, + sqlpp::compat::optional, + boolean> + { + }; /* template @@ -120,4 +136,37 @@ namespace sqlpp } */ + struct logical_and + { + static constexpr auto symbol = " AND "; + }; + + template > + constexpr auto operator and(L l, R r) -> logical_expression + { + return {std::move(l), std::move(r)}; + } + + struct logical_or + { + static constexpr auto symbol = " OR "; + }; + + template > + constexpr auto operator||(L l, R r) -> logical_expression + { + return {std::move(l), std::move(r)}; + } + + struct logical_not + { + static constexpr auto symbol = "NOT "; + }; + + template > + constexpr auto operator!(R r) -> unary_logical_expression + { + return {std::move(r)}; + } + } // namespace sqlpp diff --git a/include/sqlpp11/operator/logical_not.h b/include/sqlpp11/operator/logical_not.h deleted file mode 100644 index ab7b4539..00000000 --- a/include/sqlpp11/operator/logical_not.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct logical_not - { - static constexpr auto symbol = "NOT "; - }; - - template > - constexpr auto operator!(R r) -> unary_logical_expression - { - return {std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/logical_or.h b/include/sqlpp11/operator/logical_or.h deleted file mode 100644 index 401e637c..00000000 --- a/include/sqlpp11/operator/logical_or.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct logical_or - { - static constexpr auto symbol = " OR "; - }; - - template > - constexpr auto operator||(L l, R r) -> logical_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/minus.h b/include/sqlpp11/operator/minus.h deleted file mode 100644 index e3538b38..00000000 --- a/include/sqlpp11/operator/minus.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -#include - -namespace sqlpp -{ - struct minus - { - static constexpr auto symbol = " - "; - }; - - template > - constexpr auto operator-(L l, R r) -> arithmetic_expression - { - return {std::move(l), std::move(r)}; - } -} // namespace sqlpp diff --git a/include/sqlpp11/operator/modulus.h b/include/sqlpp11/operator/modulus.h deleted file mode 100644 index 872ff242..00000000 --- a/include/sqlpp11/operator/modulus.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -#include -#include - -namespace sqlpp -{ - struct modulus - { - static constexpr auto symbol = " % "; - }; - - template - using check_modulus_args = std::enable_if_t::value and has_integral_value::value>; - - template > - constexpr auto operator%(L l, R r) -> arithmetic_expression - { - return {std::move(l), std::move(r)}; - } -} // namespace sqlpp diff --git a/include/sqlpp11/operator/multiplies.h b/include/sqlpp11/operator/multiplies.h deleted file mode 100644 index c021280b..00000000 --- a/include/sqlpp11/operator/multiplies.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -#include - -namespace sqlpp -{ - struct multiplies - { - static constexpr auto symbol = " * "; - }; - - template > - constexpr auto operator*(L l, R r) -> arithmetic_expression - { - return {std::move(l), std::move(r)}; - } -} // namespace sqlpp diff --git a/include/sqlpp11/operator/negate.h b/include/sqlpp11/operator/negate.h deleted file mode 100644 index 9ce16d0d..00000000 --- a/include/sqlpp11/operator/negate.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -#include - -namespace sqlpp -{ - struct negate - { - static constexpr auto symbol = "-"; - }; - - template > - constexpr auto operator-(R r) -> unary_arithmetic_expression - { - return {std::move(r)}; - } -} // namespace sqlpp diff --git a/include/sqlpp11/operator/not_equal_to.h b/include/sqlpp11/operator/not_equal_to.h deleted file mode 100644 index cfed7b05..00000000 --- a/include/sqlpp11/operator/not_equal_to.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/* -Copyright (c) 2017- 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - struct not_equal_to - { - static constexpr auto symbol = " != "; - }; - - template > - constexpr auto operator!=(L l, R r) -> comparison_expression - { - return {std::move(l), std::move(r)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/not_in.h b/include/sqlpp11/operator/not_in.h deleted file mode 100644 index a789d1d0..00000000 --- a/include/sqlpp11/operator/not_in.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -/* -Copyright (c) 2024, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include -#include - -#include - -namespace sqlpp -{ - struct operator_not_in - { - static constexpr auto symbol = " NOT IN "; - }; - -#warning: something.in(select(...)); should be suppported as is - template > - constexpr auto not_in(L l, std::tuple args) -> in_expression> - { - return {std::move(l), std::move(args)}; - } - - template > - constexpr auto not_in(L l, Args... args) -> in_expression> - { - return {std::move(l), std::make_tuple(std::move(args)...)}; - } - - template > - constexpr auto not_in(L l, std::vector args) -> in_expression> - { - return {std::move(l), std::move(args)}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/order.h b/include/sqlpp11/operator/order.h deleted file mode 100644 index 0e8ba905..00000000 --- a/include/sqlpp11/operator/order.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -/* -Copyright (c) 2024, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -namespace sqlpp -{ - template > - constexpr auto order(L l, sort_order order) -> sort_order_expression - { - return {l, order}; - } - -} // namespace sqlpp diff --git a/include/sqlpp11/operator/plus.h b/include/sqlpp11/operator/plus.h deleted file mode 100644 index d5956acf..00000000 --- a/include/sqlpp11/operator/plus.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -/* -Copyright (c) 2016 - 2018, 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: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. 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. -*/ - -#include - -#include - -namespace sqlpp -{ - struct plus - { - static constexpr auto symbol = " + "; - }; - - template > - constexpr auto operator+(L l, R r) -> arithmetic_expression - { - return {std::move(l), std::move(r)}; - } -} // namespace sqlpp diff --git a/include/sqlpp11/sort_order_expression.h b/include/sqlpp11/operator/sort_order_expression.h similarity index 83% rename from include/sqlpp11/sort_order_expression.h rename to include/sqlpp11/operator/sort_order_expression.h index 7bf06343..3ec321d6 100644 --- a/include/sqlpp11/sort_order_expression.h +++ b/include/sqlpp11/operator/sort_order_expression.h @@ -78,4 +78,22 @@ namespace sqlpp } */ + template > + constexpr auto asc(L l) -> sort_order_expression + { + return {l, sort_order::asc}; + } + + template > + constexpr auto desc(L l) -> sort_order_expression + { + return {l, sort_order::desc}; + } + + template > + constexpr auto order(L l, sort_order order) -> sort_order_expression + { + return {l, order}; + } + } // namespace sqlpp diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index 572a1cb3..bee596d9 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include #include diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index c0ea2abf..fac9f01c 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -74,6 +74,21 @@ namespace sqlpp template using remove_optional_t = typename remove_optional::type; + template + struct force_optional + { + using type = sqlpp::compat::optional; + }; + + template + struct force_optional> + { + using type = sqlpp::compat::optional; + }; + + template + using force_optional_t = typename force_optional::type; + template const T& get_value(const T& t) { @@ -238,9 +253,14 @@ namespace sqlpp { }; + // A generic numeric type which could be (unsigned) integral or floating point. + struct numeric; template struct is_numeric : public std::integral_constant::value or std::is_floating_point::value>{}; + template <> + struct is_numeric : public std::true_type{}; + template <> struct is_numeric : public std::true_type{}; diff --git a/include/sqlpp11/value.h b/include/sqlpp11/value.h index 4c282f97..c35ae240 100644 --- a/include/sqlpp11/value.h +++ b/include/sqlpp11/value.h @@ -36,7 +36,7 @@ namespace sqlpp struct value_t { template - expression_alias_t as(const alias_provider& /*unused*/) const + as_expression as(const alias_provider& /*unused*/) const { return {*this}; } diff --git a/tests/core/types/result_row.cpp b/tests/core/types/result_row.cpp index c82253bb..be0dd214 100644 --- a/tests/core/types/result_row.cpp +++ b/tests/core/types/result_row.cpp @@ -112,27 +112,196 @@ int main() static_assert(sqlpp::has_text_value::value, ""); static_assert(sqlpp::has_numeric_value::value, ""); static_assert(sqlpp::has_numeric_value::value, ""); -#warning: Need to implement value_type_of for expressions - //static_assert(sqlpp::has_boolean_value::value, ""); - //static_assert(sqlpp::has_boolean_value::value, ""); -#if 0 - !bar.boolNn; - (bar.boolNn and bar.boolNn).hansi; - like(bar.textN, "hansi").berti; -#endif - (bar.textN == "hansi").berti; - (-bar.intN).berti; - (bar.intN + 7).berti; - (bar.intN << 7).berti; - assign(bar.intN, sqlpp::compat::nullopt).berti; +#warning: These should be moved into comparison type requirement tests, etc. + // Comparing optional value with non-optional value yields optional boolean. + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same= "hansi")>, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + + // Comparing non-optional value with non-optional value yields non-optional boolean. + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same= "hansi")>, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + + // The first exceptions are the operators is_null and is_not_null which always yield non-optional boolean +#warning: Still need to implement is_distinct_from as member function + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + + // The other exceptions are the operators is_distinct_from and is_not_distinct_from which always yield non-optional boolean +#warning: Still need to implement is_distinct_from as member function + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + + + // LIKE expressions can be NULL is one of their operands can be NULL. + static_assert(std::is_same, sqlpp::compat::optional>::value, ""); + static_assert(std::is_same, sqlpp::compat::optional>::value, ""); + static_assert(std::is_same, sqlpp::boolean>::value, ""); + +#warning: These should be moved into logical type requirement tests, etc. + // Logically combining optional value with non-optional value yields optional boolean. + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + + // Logically combining non-optional value with non-optional value yields non-optional boolean. + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + + // Arithmetically combining optional value with non-optional value yields optional boolean. + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + + // Same with negate. + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + + // Arithmetically combining non-optional value with non-optional value yields optional boolean. + static_assert(std::is_same, + sqlpp::numeric>::value, + ""); + + // Same with negate. + static_assert(std::is_same, + sqlpp::numeric>::value, + ""); + +#warning: Is bit-shifting with NULL "legal"? probably. +#warning: Note that bit-shifting is defined for signed int only + // Bit shifting combining optional value with non-optional value yields optional boolean. + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + + // In expression with and without optional + static_assert(std::is_same, + sqlpp::boolean>::value, + ""); + static_assert(std::is_same{7, 8, 9}))>, + sqlpp::boolean>::value, + ""); + + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same{7, 8, 9}))>, + sqlpp::compat::optional>::value, + ""); + + static_assert(std::is_same, + sqlpp::compat::optional>::value, + ""); + static_assert(std::is_same>{7, 8, 9}))>, + sqlpp::compat::optional>::value, + ""); + + + // assignment is no value + static_assert(std::is_same, sqlpp::no_value_t>::value, ""); #warning: This is not the real thing yet - bar.intN.as(bar.textN).berti; - in(bar.intN, 7, 8, 9).berti; - in(bar.intN, std::vector{7, 8, 9}).berti; - max(bar.intN); - sqlpp::max(7); + // as expressions retain the value type of the real thing + static_assert(std::is_same, sqlpp::value_type_of_t>::value, ""); + + // max can yield NULL if there are no results. + static_assert(std::is_same, sqlpp::compat::optional>::value, ""); + static_assert(std::is_same, sqlpp::compat::optional>::value, ""); + static_assert(std::is_same, sqlpp::compat::optional>::value, ""); #warning: No magic for NULL in operators, e.g. comparison. It might therefore be reasonable to disallow comparison with optoinal values? But then again, columns can also be NULL, failing to compare to anything. In any case, do not translate `a == nullopt` to `a IS NULL`. Same for parameters. @@ -140,6 +309,7 @@ int main() #if 0 + { // result fields are as nullable as the expressions they represent const auto rows = db(select(bar.id, bar.boolNn, bar.intN, seven).from(bar).unconditionally());