mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Give operators a value
This commit is contained in:
parent
08f643460c
commit
2b7e0ee6a5
@ -32,9 +32,7 @@
|
|||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
template <typename Flag, typename Expr>
|
template <typename Flag, typename Expr>
|
||||||
struct max_t : public expression_operators<max_t<Flag, Expr>, value_type_of_t<Expr>>,
|
struct max_t
|
||||||
public aggregate_function_operators<max_t<Flag, Expr>>,
|
|
||||||
public alias_operators<max_t<Flag, Expr>>
|
|
||||||
{
|
{
|
||||||
using _traits = make_traits<value_type_of_t<Expr>, tag::is_expression, tag::is_selectable>;
|
using _traits = make_traits<value_type_of_t<Expr>, tag::is_expression, tag::is_selectable>;
|
||||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||||
@ -54,6 +52,12 @@ namespace sqlpp
|
|||||||
Expr _expr;
|
Expr _expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Flag, typename Expr>
|
||||||
|
struct value_type_of<max_t<Flag, Expr>>
|
||||||
|
{
|
||||||
|
using type = sqlpp::force_optional_t<value_type_of_t<Expr>>;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename Context, typename Flag, typename Expr>
|
template <typename Context, typename Flag, typename Expr>
|
||||||
Context& serialize(const max_t<Flag, Expr>& t, Context& context)
|
Context& serialize(const max_t<Flag, Expr>& t, Context& context)
|
||||||
{
|
{
|
||||||
|
@ -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 <sqlpp11/type_traits.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
template <typename Expression, typename AliasProvider>
|
|
||||||
struct expression_alias_t
|
|
||||||
{
|
|
||||||
using _traits = make_traits<value_type_of_t<Expression>, tag::is_selectable, tag::is_alias>;
|
|
||||||
using _nodes = detail::type_vector<Expression>;
|
|
||||||
|
|
||||||
#warning Maybe make constructor of expressions private to force construction in the respective functions?
|
|
||||||
/*
|
|
||||||
static_assert(is_expression_t<Expression>::value, "invalid argument for an expression alias");
|
|
||||||
static_assert(not is_alias_t<Expression>::value, "cannot create an alias of an alias");
|
|
||||||
*/
|
|
||||||
|
|
||||||
using _alias_t = typename AliasProvider::_alias_t;
|
|
||||||
|
|
||||||
sqlpp::compat::optional<expression_alias_t> 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 <typename Expression, typename AliasProvider>
|
|
||||||
struct value_type_of<expression_alias_t<Expression, AliasProvider>>
|
|
||||||
{
|
|
||||||
using type = value_type_of_t<Expression>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Context, typename Expression, typename AliasProvider>
|
|
||||||
Context& serialize(const expression_alias_t<Expression, AliasProvider>& t, Context& context)
|
|
||||||
{
|
|
||||||
serialize_operand(t._expression, context);
|
|
||||||
context << " AS ";
|
|
||||||
context << name_of<expression_alias_t<Expression, AliasProvider>>::template char_ptr<Context>();
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
} // namespace sqlpp
|
|
@ -26,7 +26,7 @@
|
|||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sqlpp11/alias.h>
|
#include <sqlpp11/operator/as_expression.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -34,7 +34,7 @@ namespace sqlpp
|
|||||||
struct alias_operators
|
struct alias_operators
|
||||||
{
|
{
|
||||||
template <typename alias_provider>
|
template <typename alias_provider>
|
||||||
expression_alias_t<Expr, alias_provider> as(const alias_provider& /*unused*/) const
|
as_expression<Expr, alias_provider> as(const alias_provider& /*unused*/) const
|
||||||
{
|
{
|
||||||
return {*static_cast<const Expr*>(this)};
|
return {*static_cast<const Expr*>(this)};
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sqlpp11/alias.h>
|
#include <sqlpp11/operator/as_expression.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -53,7 +53,7 @@ namespace sqlpp
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct auto_alias_impl<T, typename std::enable_if<has_auto_alias_t<T>::value>::type>
|
struct auto_alias_impl<T, typename std::enable_if<has_auto_alias_t<T>::value>::type>
|
||||||
{
|
{
|
||||||
using type = expression_alias_t<T, typename T::_auto_alias_t>;
|
using type = as_expression<T, typename T::_auto_alias_t>;
|
||||||
};
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
#include <sqlpp11/bad_expression.h>
|
#include <sqlpp11/bad_expression.h>
|
||||||
#include <sqlpp11/portable_static_assert.h>
|
#include <sqlpp11/portable_static_assert.h>
|
||||||
#include <sqlpp11/consistent.h>
|
#include <sqlpp11/consistent.h>
|
||||||
#include <sqlpp11/alias.h>
|
#include <sqlpp11/operator/as_expression.h>
|
||||||
#include <sqlpp11/sort_order.h>
|
#include <sqlpp11/sort_order.h>
|
||||||
#include <sqlpp11/expression_fwd.h>
|
#include <sqlpp11/expression_fwd.h>
|
||||||
#include <sqlpp11/in_fwd.h>
|
#include <sqlpp11/in_fwd.h>
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sqlpp11/alias.h>
|
#include <sqlpp11/operator/as_expression.h>
|
||||||
#include <sqlpp11/column_fwd.h>
|
#include <sqlpp11/column_fwd.h>
|
||||||
#include <sqlpp11/default_value.h>
|
#include <sqlpp11/default_value.h>
|
||||||
#include <sqlpp11/null.h>
|
#include <sqlpp11/null.h>
|
||||||
@ -75,7 +75,7 @@ namespace sqlpp
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename alias_provider>
|
template <typename alias_provider>
|
||||||
expression_alias_t<column_t, alias_provider> as(const alias_provider& /*unused*/) const
|
as_expression<column_t, alias_provider> as(const alias_provider& /*unused*/) const
|
||||||
{
|
{
|
||||||
return {*this};
|
return {*this};
|
||||||
}
|
}
|
||||||
|
@ -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 <utility>
|
|
||||||
|
|
||||||
#include <sqlpp11/type_traits.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
template <typename L, typename Operator, typename R>
|
|
||||||
struct comparison_expression
|
|
||||||
{
|
|
||||||
L l;
|
|
||||||
R r;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R>
|
|
||||||
using check_comparison_args = std::enable_if_t<values_are_comparable<L, R>::value>;
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
template <typename L, typename Operator, typename R>
|
|
||||||
struct nodes_of<comparison_expression<L, Operator, R>>
|
|
||||||
{
|
|
||||||
using type = type_vector<L, R>;
|
|
||||||
};
|
|
||||||
|
|
||||||
SQLPP_WRAPPED_STATIC_ASSERT(assert_comparison_operands_are_compatible,
|
|
||||||
"comparison operands must have compatible value types");
|
|
||||||
|
|
||||||
template <typename L, typename R>
|
|
||||||
constexpr auto check_comparison_args()
|
|
||||||
{
|
|
||||||
if constexpr (not values_are_compatible_v<L, R>)
|
|
||||||
{
|
|
||||||
return failed<assert_comparison_operands_are_compatible>{};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return succeeded{};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename L, typename Operator, typename R>
|
|
||||||
struct value_type_of_t<comparison_expression<L, Operator, R>>
|
|
||||||
{
|
|
||||||
using type = bool;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename Operator, typename R>
|
|
||||||
constexpr auto requires_braces_v<comparison_expression<L, Operator, R>> = true;
|
|
||||||
|
|
||||||
template <typename Context, typename L, typename Operator, typename R>
|
|
||||||
[[nodiscard]] auto to_sql_string(Context& context, const comparison_expression<L, Operator, R>& t)
|
|
||||||
{
|
|
||||||
return to_sql_string(context, embrace(t.l)) + Operator::symbol + to_sql_string(context, embrace(t.r));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} // namespace sqlpp
|
|
@ -26,7 +26,7 @@
|
|||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sqlpp11/alias.h>
|
#include <sqlpp11/operator/as_expression.h>
|
||||||
#include <sqlpp11/data_types/boolean.h>
|
#include <sqlpp11/data_types/boolean.h>
|
||||||
#include <sqlpp11/expression_fwd.h>
|
#include <sqlpp11/expression_fwd.h>
|
||||||
#include <sqlpp11/noop.h>
|
#include <sqlpp11/noop.h>
|
||||||
|
@ -33,51 +33,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// logical
|
// logical
|
||||||
#include <sqlpp11/operator/logical_and.h>
|
#include <sqlpp11/operator/logical_expression.h>
|
||||||
#include <sqlpp11/operator/logical_not.h>
|
|
||||||
#include <sqlpp11/operator/logical_or.h>
|
|
||||||
|
|
||||||
// comparison
|
// comparison
|
||||||
#include <sqlpp11/operator/equal_to.h>
|
#include <sqlpp11/operator/comparison_expression.h>
|
||||||
#include <sqlpp11/operator/greater.h>
|
#include <sqlpp11/operator/in_expression.h>
|
||||||
#include <sqlpp11/operator/greater_equal.h>
|
|
||||||
#include <sqlpp11/operator/less.h>
|
|
||||||
#include <sqlpp11/operator/less_equal.h>
|
|
||||||
#include <sqlpp11/operator/like.h>
|
|
||||||
#include <sqlpp11/operator/not_equal_to.h>
|
|
||||||
#include <sqlpp11/operator/is_distinct_from.h>
|
|
||||||
#include <sqlpp11/operator/is_not_distinct_from.h>
|
|
||||||
#include <sqlpp11/operator/is_not_null.h>
|
|
||||||
#include <sqlpp11/operator/is_null.h>
|
|
||||||
|
|
||||||
|
|
||||||
// arithmetic
|
// arithmetic
|
||||||
#include <sqlpp11/operator/divides.h>
|
#include <sqlpp11/operator/arithmetic_expression.h>
|
||||||
#include <sqlpp11/operator/minus.h>
|
|
||||||
#include <sqlpp11/operator/modulus.h>
|
|
||||||
#include <sqlpp11/operator/multiplies.h>
|
|
||||||
#include <sqlpp11/operator/negate.h>
|
|
||||||
#include <sqlpp11/operator/plus.h>
|
|
||||||
|
|
||||||
// binary
|
// binary
|
||||||
#include <sqlpp11/operator/bit_and.h>
|
#include <sqlpp11/operator/bit_expression.h>
|
||||||
#include <sqlpp11/operator/bit_not.h>
|
|
||||||
#include <sqlpp11/operator/bit_or.h>
|
|
||||||
#include <sqlpp11/operator/bit_shift_left.h>
|
|
||||||
#include <sqlpp11/operator/bit_shift_right.h>
|
|
||||||
#include <sqlpp11/operator/bit_xor.h>
|
|
||||||
|
|
||||||
// assignment
|
// assignment
|
||||||
#include <sqlpp11/operator/assign.h>
|
#include <sqlpp11/operator/assign_expression.h>
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
#include <sqlpp11/operator/as.h>
|
#include <sqlpp11/operator/as_expression.h>
|
||||||
|
|
||||||
#include <sqlpp11/operator/asc.h>
|
#include <sqlpp11/operator/sort_order_expression.h>
|
||||||
#include <sqlpp11/operator/desc.h>
|
|
||||||
#include <sqlpp11/operator/order.h>
|
|
||||||
|
|
||||||
#include <sqlpp11/operator/in.h>
|
#include <sqlpp11/operator/exists_expression.h>
|
||||||
#include <sqlpp11/operator/not_in.h>
|
|
||||||
|
|
||||||
#include <sqlpp11/operator/exists.h>
|
|
||||||
|
@ -68,6 +68,20 @@ namespace sqlpp
|
|||||||
template <typename L, typename R>
|
template <typename L, typename R>
|
||||||
using check_arithmetic_args = std::enable_if_t<has_numeric_value<L>::value and has_numeric_value<R>::value>;
|
using check_arithmetic_args = std::enable_if_t<has_numeric_value<L>::value and has_numeric_value<R>::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 <typename L, typename Operator, typename R>
|
||||||
|
struct value_type_of<arithmetic_expression<L, Operator, R>>
|
||||||
|
: std::conditional<sqlpp::is_optional<value_type_of_t<L>>::value or sqlpp::is_optional<value_type_of_t<R>>::value,
|
||||||
|
sqlpp::compat::optional<numeric>,
|
||||||
|
numeric> {};
|
||||||
|
|
||||||
|
#warning: As above.
|
||||||
|
template <typename Operator, typename R>
|
||||||
|
struct value_type_of<unary_arithmetic_expression<Operator, R>>
|
||||||
|
: std::conditional<sqlpp::is_optional<value_type_of_t<R>>::value,
|
||||||
|
sqlpp::compat::optional<numeric>,
|
||||||
|
numeric> {};
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
template <typename L, typename Operator, typename R>
|
template <typename L, typename Operator, typename R>
|
||||||
@ -104,4 +118,71 @@ namespace sqlpp
|
|||||||
return to_sql_string(context, t._l) + Operator::symbol + to_sql_string(context, embrace(t._r));
|
return to_sql_string(context, t._l) + Operator::symbol + to_sql_string(context, embrace(t._r));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
struct plus
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " + ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_arithmetic_args<L, R>>
|
||||||
|
constexpr auto operator+(L l, R r) -> arithmetic_expression<L, plus, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
struct minus
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " - ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_arithmetic_args<L, R>>
|
||||||
|
constexpr auto operator-(L l, R r) -> arithmetic_expression<L, minus, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
struct multiplies
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " * ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_arithmetic_args<L, R>>
|
||||||
|
constexpr auto operator*(L l, R r) -> arithmetic_expression<L, multiplies, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct divides
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " / ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_arithmetic_args<L, R>>
|
||||||
|
constexpr auto operator/(L l, R r) -> arithmetic_expression<L, divides, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct negate
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = "-";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename R, typename = check_arithmetic_args<R, R>>
|
||||||
|
constexpr auto operator-(R r) -> unary_arithmetic_expression<divides, R>
|
||||||
|
{
|
||||||
|
return {std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct modulus
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " % ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R>
|
||||||
|
using check_modulus_args = std::enable_if_t<has_integral_value<L>::value and has_integral_value<R>::value>;
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_modulus_args<L, R>>
|
||||||
|
constexpr auto operator%(L l, R r) -> arithmetic_expression<L, modulus, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
@ -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 <type_traits>
|
|
||||||
|
|
||||||
#include <sqlpp11/alias.h>
|
|
||||||
#include <sqlpp11/type_traits.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
template <typename Expr, typename AliasProvider>
|
|
||||||
using check_as_args = std::enable_if_t<
|
|
||||||
is_expression_t<Expr>::value and not is_alias_t<Expr>::value and has_name<AliasProvider>::value
|
|
||||||
>;
|
|
||||||
|
|
||||||
template <typename Expr, typename AliasProvider, typename = check_as_args<Expr, AliasProvider>>
|
|
||||||
constexpr auto as(Expr expr, const AliasProvider&) -> expression_alias_t<Expr, AliasProvider>
|
|
||||||
{
|
|
||||||
return {std::move(expr)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
93
include/sqlpp11/operator/as_expression.h
Normal file
93
include/sqlpp11/operator/as_expression.h
Normal file
@ -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 <type_traits>
|
||||||
|
|
||||||
|
#include <sqlpp11/operator/as_expression.h>
|
||||||
|
#include <sqlpp11/type_traits.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
template <typename Expression, typename AliasProvider>
|
||||||
|
struct as_expression
|
||||||
|
{
|
||||||
|
using _traits = make_traits<value_type_of_t<Expression>, tag::is_selectable, tag::is_alias>;
|
||||||
|
using _nodes = detail::type_vector<Expression>;
|
||||||
|
|
||||||
|
#warning Maybe make constructor of expressions private to force construction in the respective functions?
|
||||||
|
/*
|
||||||
|
static_assert(is_expression_t<Expression>::value, "invalid argument for an expression alias");
|
||||||
|
static_assert(not is_alias_t<Expression>::value, "cannot create an alias of an alias");
|
||||||
|
*/
|
||||||
|
|
||||||
|
using _alias_t = typename AliasProvider::_alias_t;
|
||||||
|
|
||||||
|
sqlpp::compat::optional<as_expression> 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 <typename Expression, typename AliasProvider>
|
||||||
|
struct value_type_of<as_expression<Expression, AliasProvider>>
|
||||||
|
{
|
||||||
|
using type = value_type_of_t<Expression>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Context, typename Expression, typename AliasProvider>
|
||||||
|
Context& serialize(const as_expression<Expression, AliasProvider>& t, Context& context)
|
||||||
|
{
|
||||||
|
serialize_operand(t._expression, context);
|
||||||
|
context << " AS ";
|
||||||
|
context << name_of<as_expression<Expression, AliasProvider>>::template char_ptr<Context>();
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
template <typename Expr, typename AliasProvider>
|
||||||
|
using check_as_args = std::enable_if_t<
|
||||||
|
is_expression_t<Expr>::value and not is_alias_t<Expr>::value and has_name<AliasProvider>::value
|
||||||
|
>;
|
||||||
|
|
||||||
|
template <typename Expr, typename AliasProvider, typename = check_as_args<Expr, AliasProvider>>
|
||||||
|
constexpr auto as(Expr expr, const AliasProvider&) -> as_expression<Expr, AliasProvider>
|
||||||
|
{
|
||||||
|
return {std::move(expr)};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sqlpp
|
@ -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 <sqlpp11/sort_order_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
template <typename L, typename = check_sort_order_args<L>>
|
|
||||||
constexpr auto asc(L l) -> sort_order_expression<L>
|
|
||||||
{
|
|
||||||
return {l, sort_order::asc};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/bit_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct bit_and
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " & ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_bit_expression_args<L, R>>
|
|
||||||
constexpr auto operator&(L l, R r) -> bit_expression<L, bit_and, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -65,6 +65,22 @@ namespace sqlpp
|
|||||||
R _r;
|
R _r;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename L, typename Operator, typename R>
|
||||||
|
struct value_type_of<bit_expression<L, Operator, R>>
|
||||||
|
: std::conditional<sqlpp::is_optional<value_type_of_t<L>>::value or sqlpp::is_optional<value_type_of_t<R>>::value,
|
||||||
|
force_optional_t<value_type_of_t<L>>,
|
||||||
|
value_type_of_t<L>>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Operator, typename R>
|
||||||
|
struct value_type_of<unary_bit_expression<Operator, R>>
|
||||||
|
: std::conditional<sqlpp::is_optional<value_type_of_t<R>>::value,
|
||||||
|
force_optional_t<value_type_of_t<R>>,
|
||||||
|
value_type_of_t<R>>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
template <typename L, typename R>
|
template <typename L, typename R>
|
||||||
using check_bit_expression_args = std::enable_if_t<has_integral_value<L>::value and has_integral_value<R>::value>;
|
using check_bit_expression_args = std::enable_if_t<has_integral_value<L>::value and has_integral_value<R>::value>;
|
||||||
|
|
||||||
@ -97,4 +113,70 @@ namespace sqlpp
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct bit_and
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " & ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_bit_expression_args<L, R>>
|
||||||
|
constexpr auto operator&(L l, R r) -> bit_expression<L, bit_and, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct bit_or
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " | ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_bit_expression_args<L, R>>
|
||||||
|
constexpr auto operator|(L l, R r) -> bit_expression<L, bit_or, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct bit_xor
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " ^ ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_bit_expression_args<L, R>>
|
||||||
|
constexpr auto operator^(L l, R r) -> bit_expression<L, bit_xor, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct bit_not
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = "~";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename R, typename = check_bit_expression_args<R, R>>
|
||||||
|
constexpr auto operator~(R r) -> unary_bit_expression<bit_not, R>
|
||||||
|
{
|
||||||
|
return {std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct bit_shift_left
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " << ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_bit_expression_args<L, R>>
|
||||||
|
constexpr auto operator<<(L l, R r) -> bit_expression<L, bit_shift_left, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct bit_shift_right
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " >> ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_bit_expression_args<L, R>>
|
||||||
|
constexpr auto operator>>(L l, R r) -> bit_expression<L, bit_shift_right, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
@ -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 <sqlpp11/bit_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct bit_not
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = "~";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename R, typename = check_bit_expression_args<R, R>>
|
|
||||||
constexpr auto operator~(R r) -> unary_bit_expression<bit_not, R>
|
|
||||||
{
|
|
||||||
return {std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/bit_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct bit_or
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " | ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_bit_expression_args<L, R>>
|
|
||||||
constexpr auto operator|(L l, R r) -> bit_expression<L, bit_or, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/bit_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct bit_shift_left
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " << ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_bit_expression_args<L, R>>
|
|
||||||
constexpr auto operator<<(L l, R r) -> bit_expression<L, bit_shift_left, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/bit_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct bit_shift_right
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " >> ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_bit_expression_args<L, R>>
|
|
||||||
constexpr auto operator>>(L l, R r) -> bit_expression<L, bit_shift_right, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/bit_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct bit_xor
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " ^ ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_bit_expression_args<L, R>>
|
|
||||||
constexpr auto operator^(L l, R r) -> bit_expression<L, bit_xor, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
236
include/sqlpp11/operator/comparison_expression.h
Normal file
236
include/sqlpp11/operator/comparison_expression.h
Normal file
@ -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 <utility>
|
||||||
|
|
||||||
|
#include <sqlpp11/type_traits.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
template <typename L, typename Operator, typename R>
|
||||||
|
struct comparison_expression
|
||||||
|
{
|
||||||
|
L l;
|
||||||
|
R r;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R>
|
||||||
|
using check_comparison_args = std::enable_if_t<values_are_comparable<L, R>::value>;
|
||||||
|
|
||||||
|
template <typename L, typename Operator, typename R>
|
||||||
|
struct value_type_of<comparison_expression<L, Operator, R>>
|
||||||
|
: std::conditional<sqlpp::is_optional<value_type_of_t<L>>::value or sqlpp::is_optional<value_type_of_t<R>>::value,
|
||||||
|
sqlpp::compat::optional<boolean>,
|
||||||
|
boolean>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
struct op_is_null;
|
||||||
|
struct op_is_not_null;
|
||||||
|
struct is_distinct_from;
|
||||||
|
struct is_not_distinct_from;
|
||||||
|
|
||||||
|
template <typename L>
|
||||||
|
struct value_type_of<comparison_expression<L, op_is_null, sqlpp::compat::nullopt_t>> { using type = boolean; };
|
||||||
|
|
||||||
|
template <typename L>
|
||||||
|
struct value_type_of<comparison_expression<L, op_is_not_null, sqlpp::compat::nullopt_t>> { using type = boolean; };
|
||||||
|
|
||||||
|
template <typename L, typename R>
|
||||||
|
struct value_type_of<comparison_expression<L, is_distinct_from, R>> { using type = boolean; };
|
||||||
|
|
||||||
|
template <typename L, typename R>
|
||||||
|
struct value_type_of<comparison_expression<L, is_not_distinct_from, R>> { using type = boolean; };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
template <typename L, typename Operator, typename R>
|
||||||
|
struct nodes_of<comparison_expression<L, Operator, R>>
|
||||||
|
{
|
||||||
|
using type = type_vector<L, R>;
|
||||||
|
};
|
||||||
|
|
||||||
|
SQLPP_WRAPPED_STATIC_ASSERT(assert_comparison_operands_are_compatible,
|
||||||
|
"comparison operands must have compatible value types");
|
||||||
|
|
||||||
|
template <typename L, typename R>
|
||||||
|
constexpr auto check_comparison_args()
|
||||||
|
{
|
||||||
|
if constexpr (not values_are_compatible_v<L, R>)
|
||||||
|
{
|
||||||
|
return failed<assert_comparison_operands_are_compatible>{};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return succeeded{};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename L, typename Operator, typename R>
|
||||||
|
struct value_type_of_t<comparison_expression<L, Operator, R>>
|
||||||
|
{
|
||||||
|
using type = bool;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename Operator, typename R>
|
||||||
|
constexpr auto requires_braces_v<comparison_expression<L, Operator, R>> = true;
|
||||||
|
|
||||||
|
template <typename Context, typename L, typename Operator, typename R>
|
||||||
|
[[nodiscard]] auto to_sql_string(Context& context, const comparison_expression<L, Operator, R>& 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 <typename L, typename R, typename = check_comparison_args<L, R>>
|
||||||
|
constexpr auto operator<(L l, R r) -> comparison_expression<L, less, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct less_equal
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " <= ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
||||||
|
constexpr auto operator<=(L l, R r) -> comparison_expression<L, less_equal, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct equal_to
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " = ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
||||||
|
constexpr auto operator==(L l, R r) -> comparison_expression<L, equal_to, R>
|
||||||
|
{
|
||||||
|
return {l, r};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct not_equal_to
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " != ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
||||||
|
constexpr auto operator!=(L l, R r) -> comparison_expression<L, not_equal_to, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct greater_equal
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " >= ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
||||||
|
constexpr auto operator>=(L l, R r) -> comparison_expression<L, greater_equal, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct greater
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " > ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
||||||
|
constexpr auto operator>(L l, R r) -> comparison_expression<L, greater, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct op_is_null
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " IS ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L>
|
||||||
|
constexpr auto is_null(L l) -> comparison_expression<L, op_is_null, sqlpp::compat::nullopt_t>
|
||||||
|
{
|
||||||
|
return {l};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct op_is_not_null
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " IS NOT ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L>
|
||||||
|
constexpr auto is_not_null(L l) -> comparison_expression<L, op_is_not_null, sqlpp::compat::nullopt_t>
|
||||||
|
{
|
||||||
|
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 <typename L, typename R, typename = check_comparison_args<L, R>>
|
||||||
|
constexpr auto is_distinct_from(L l, R r) -> comparison_expression<L, is_distinct_from, R>
|
||||||
|
{
|
||||||
|
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 <typename L, typename R, typename = check_comparison_args<L, R>>
|
||||||
|
constexpr auto is_not_distinct_from(L l, R r) -> comparison_expression<L, is_not_distinct_from, R>
|
||||||
|
{
|
||||||
|
return {l, r};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct operator_like
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " LIKE ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
||||||
|
constexpr auto like(L l, R r) -> comparison_expression<L, operator_like, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sqlpp
|
@ -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 <sqlpp11/sort_order_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
template <typename L, typename = check_sort_order_args<L>>
|
|
||||||
constexpr auto desc(L l) -> sort_order_expression<L>
|
|
||||||
{
|
|
||||||
return {l, sort_order::desc};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <utility>
|
|
||||||
|
|
||||||
#include <sqlpp11/arithmetic_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct divides
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " / ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_arithmetic_args<L, R>>
|
|
||||||
constexpr auto operator/(L l, R r) -> arithmetic_expression<L, divides, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct equal_to
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " = ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
|
||||||
constexpr auto operator==(L l, R r) -> comparison_expression<L, equal_to, R>
|
|
||||||
{
|
|
||||||
return {l, r};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -39,6 +39,12 @@ namespace sqlpp
|
|||||||
template <typename SubSelect>
|
template <typename SubSelect>
|
||||||
using check_exists_arg = std::enable_if_t<is_statement_t<SubSelect>::value and has_result_row_t<SubSelect>::value>;
|
using check_exists_arg = std::enable_if_t<is_statement_t<SubSelect>::value and has_result_row_t<SubSelect>::value>;
|
||||||
|
|
||||||
|
template <typename SubSelect>
|
||||||
|
struct value_type_of<exists_t<SubSelect>>
|
||||||
|
{
|
||||||
|
using type = boolean;
|
||||||
|
};
|
||||||
|
|
||||||
#warning: Document that functions dont come with their default alias any more
|
#warning: Document that functions dont come with their default alias any more
|
||||||
template <typename SubSelect, typename = check_exists_arg<SubSelect>>
|
template <typename SubSelect, typename = check_exists_arg<SubSelect>>
|
||||||
constexpr auto exists(SubSelect sub_select) -> exists_t<SubSelect>
|
constexpr auto exists(SubSelect sub_select) -> exists_t<SubSelect>
|
||||||
@ -53,12 +59,6 @@ namespace sqlpp
|
|||||||
using type = type_vector<SubSelect>;
|
using type = type_vector<SubSelect>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename SubSelect>
|
|
||||||
struct value_type_of_t<exists_t<SubSelect>>
|
|
||||||
{
|
|
||||||
using type = bool;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Context, typename SubSelect>
|
template <typename Context, typename SubSelect>
|
||||||
[[nodiscard]] auto to_sql_string(Context& context, const exists_t<SubSelect>& t)
|
[[nodiscard]] auto to_sql_string(Context& context, const exists_t<SubSelect>& t)
|
||||||
{
|
{
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct greater
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " > ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
|
||||||
constexpr auto operator>(L l, R r) -> comparison_expression<L, greater, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct greater_equal
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " >= ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
|
||||||
constexpr auto operator>=(L l, R r) -> comparison_expression<L, greater_equal, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <tuple>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <sqlpp11/in_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct operator_in
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " IN ";
|
|
||||||
};
|
|
||||||
|
|
||||||
#warning: something.in(select(...)); should be suppported as is
|
|
||||||
template <typename L, typename... Args, typename = check_in_args<L, Args...>>
|
|
||||||
constexpr auto in(L l, std::tuple<Args...> args) -> in_expression<L, operator_in, std::tuple<Args...>>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(args)};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename L, typename... Args, typename = check_in_args<L, Args...>>
|
|
||||||
constexpr auto in(L l, Args... args) -> in_expression<L, operator_in, std::tuple<Args...>>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::make_tuple(std::move(args)...)};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename L, typename Arg, typename = check_in_args<L, Arg>>
|
|
||||||
constexpr auto in(L l, std::vector<Arg> args) -> in_expression<L, operator_in, std::vector<Arg>>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(args)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
153
include/sqlpp11/operator/in_expression.h
Normal file
153
include/sqlpp11/operator/in_expression.h
Normal file
@ -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 <tuple>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <sqlpp11/type_traits.h>
|
||||||
|
#include <sqlpp11/logic.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
template<typename L, typename Operator, typename Container>
|
||||||
|
struct in_expression
|
||||||
|
{
|
||||||
|
L l;
|
||||||
|
Container container;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename Operator, typename... Args>
|
||||||
|
struct in_expression<L, Operator, std::tuple<Args...>>
|
||||||
|
{
|
||||||
|
L l;
|
||||||
|
std::tuple<Args...> args;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename... Args>
|
||||||
|
using check_in_args =
|
||||||
|
std::enable_if_t<(sizeof...(Args) != 0) and logic::all_t<values_are_comparable<L, Args>::value...>::value>;
|
||||||
|
|
||||||
|
template <typename L, typename Operator, typename R>
|
||||||
|
struct value_type_of<in_expression<L, Operator, std::vector<R>>>
|
||||||
|
: std::conditional<sqlpp::is_optional<value_type_of_t<L>>::value or sqlpp::is_optional<value_type_of_t<R>>::value,
|
||||||
|
sqlpp::compat::optional<boolean>,
|
||||||
|
boolean>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename Operator, typename... Args>
|
||||||
|
struct value_type_of<in_expression<L, Operator, std::tuple<Args...>>>
|
||||||
|
: std::conditional<sqlpp::is_optional<value_type_of_t<L>>::value or
|
||||||
|
logic::any_t<sqlpp::is_optional<value_type_of_t<Args>>::value...>::value,
|
||||||
|
sqlpp::compat::optional<boolean>,
|
||||||
|
boolean>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
template <typename L, typename... Args>
|
||||||
|
struct nodes_of<in_t<L, Args...>>
|
||||||
|
{
|
||||||
|
using type = type_vector<L, Args...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename... Args>
|
||||||
|
constexpr auto in(L l, Args... args)
|
||||||
|
-> std::enable_if_t<((sizeof...(Args) > 0) and ... and values_are_compatible_v<L, Args>), in_t<L, Args...>>
|
||||||
|
{
|
||||||
|
return in_t<L, Args...>{l, std::tuple{args...}};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename L, typename... Args>
|
||||||
|
constexpr auto requires_braces_v<in_t<L, Args...>> = true;
|
||||||
|
|
||||||
|
template <typename Context, typename L, typename... Args>
|
||||||
|
[[nodiscard]] auto to_sql_string(Context& context, const in_t<L, Args...>& 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 <typename L, typename... Args, typename = check_in_args<L, Args...>>
|
||||||
|
constexpr auto in(L l, std::tuple<Args...> args) -> in_expression<L, operator_in, std::tuple<Args...>>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(args)};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename L, typename... Args, typename = check_in_args<L, Args...>>
|
||||||
|
constexpr auto in(L l, Args... args) -> in_expression<L, operator_in, std::tuple<Args...>>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::make_tuple(std::move(args)...)};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename L, typename Arg, typename = check_in_args<L, Arg>>
|
||||||
|
constexpr auto in(L l, std::vector<Arg> args) -> in_expression<L, operator_in, std::vector<Arg>>
|
||||||
|
{
|
||||||
|
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 <typename L, typename... Args, typename = check_in_args<L, Args...>>
|
||||||
|
constexpr auto not_in(L l, std::tuple<Args...> args) -> in_expression<L, operator_not_in, std::tuple<Args...>>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(args)};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename L, typename... Args, typename = check_in_args<L, Args...>>
|
||||||
|
constexpr auto not_in(L l, Args... args) -> in_expression<L, operator_not_in, std::tuple<Args...>>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::make_tuple(std::move(args)...)};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename L, typename Arg, typename = check_in_args<L, Arg>>
|
||||||
|
constexpr auto not_in(L l, std::vector<Arg> args) -> in_expression<L, operator_not_in, std::vector<Arg>>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(args)};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace sqlpp
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
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 <typename L, typename R, typename = check_comparison_args<L, R>>
|
|
||||||
constexpr auto is_distinct_from(L l, R r) -> comparison_expression<L, is_distinct_from, R>
|
|
||||||
{
|
|
||||||
return {l, r};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
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 <typename L, typename R, typename = check_comparison_args<L, R>>
|
|
||||||
constexpr auto is_not_distinct_from(L l, R r) -> comparison_expression<L, is_not_distinct_from, R>
|
|
||||||
{
|
|
||||||
return {l, r};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct is_not
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " IS NOT ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L>
|
|
||||||
constexpr auto is_null(L l) -> comparison_expression<L, is_not, sqlpp::compat::nullopt_t>
|
|
||||||
{
|
|
||||||
return {l};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct is
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " IS ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L>
|
|
||||||
constexpr auto is_null(L l) -> comparison_expression<L, is, sqlpp::compat::nullopt_t>
|
|
||||||
{
|
|
||||||
return {l};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct less
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " < ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
|
||||||
constexpr auto operator<(L l, R r) -> comparison_expression<L, less, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct less_equal
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " <= ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
|
||||||
constexpr auto operator<=(L l, R r) -> comparison_expression<L, less_equal, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct operator_like
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " LIKE ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
|
||||||
constexpr auto like(L l, R r) -> comparison_expression<L, operator_like, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/logical_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct logical_and
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " AND ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_logical_args<L, R>>
|
|
||||||
constexpr auto operator and(L l, R r) -> logical_expression<L, logical_and, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <sqlpp11/alias.h>
|
#include <sqlpp11/operator/as_expression.h>
|
||||||
//#include <sqlpp11/bad_expression.h>
|
//#include <sqlpp11/bad_expression.h>
|
||||||
//#include <sqlpp11/embrace.h>
|
//#include <sqlpp11/embrace.h>
|
||||||
//#include <sqlpp11/to_sql_string.h>
|
//#include <sqlpp11/to_sql_string.h>
|
||||||
@ -51,7 +51,7 @@ namespace sqlpp
|
|||||||
~logical_expression() = default;
|
~logical_expression() = default;
|
||||||
|
|
||||||
template <typename alias_provider>
|
template <typename alias_provider>
|
||||||
expression_alias_t<logical_expression, alias_provider> as(const alias_provider& /*unused*/) const
|
as_expression<logical_expression, alias_provider> as(const alias_provider& /*unused*/) const
|
||||||
{
|
{
|
||||||
return {*this};
|
return {*this};
|
||||||
}
|
}
|
||||||
@ -60,6 +60,17 @@ namespace sqlpp
|
|||||||
R _r;
|
R _r;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R>
|
||||||
|
using check_logical_args = std::enable_if_t<has_boolean_value<L>::value and has_boolean_value<R>::value>;
|
||||||
|
|
||||||
|
template <typename L, typename Operator, typename R>
|
||||||
|
struct value_type_of<logical_expression<L, Operator, R>>
|
||||||
|
: std::conditional<sqlpp::is_optional<value_type_of_t<L>>::value or sqlpp::is_optional<value_type_of_t<R>>::value,
|
||||||
|
sqlpp::compat::optional<boolean>,
|
||||||
|
boolean>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
template <typename Operator, typename R>
|
template <typename Operator, typename R>
|
||||||
struct unary_logical_expression
|
struct unary_logical_expression
|
||||||
{
|
{
|
||||||
@ -74,7 +85,7 @@ namespace sqlpp
|
|||||||
~unary_logical_expression() = default;
|
~unary_logical_expression() = default;
|
||||||
|
|
||||||
template <typename alias_provider>
|
template <typename alias_provider>
|
||||||
expression_alias_t<unary_logical_expression, alias_provider> as(const alias_provider& /*unused*/) const
|
as_expression<unary_logical_expression, alias_provider> as(const alias_provider& /*unused*/) const
|
||||||
{
|
{
|
||||||
return {*this};
|
return {*this};
|
||||||
}
|
}
|
||||||
@ -82,8 +93,13 @@ namespace sqlpp
|
|||||||
R _r;
|
R _r;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename L, typename R>
|
template <typename Operator, typename R>
|
||||||
using check_logical_args = std::enable_if_t<has_boolean_value<L>::value and has_boolean_value<R>::value>;
|
struct value_type_of<unary_logical_expression<Operator, R>>
|
||||||
|
: std::conditional<sqlpp::is_optional<value_type_of_t<R>>::value,
|
||||||
|
sqlpp::compat::optional<boolean>,
|
||||||
|
boolean>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
template <typename L, typename Operator, typename R>
|
template <typename L, typename Operator, typename R>
|
||||||
@ -120,4 +136,37 @@ namespace sqlpp
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
struct logical_and
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " AND ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_logical_args<L, R>>
|
||||||
|
constexpr auto operator and(L l, R r) -> logical_expression<L, logical_and, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct logical_or
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = " OR ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename L, typename R, typename = check_logical_args<L, R>>
|
||||||
|
constexpr auto operator||(L l, R r) -> logical_expression<L, logical_or, R>
|
||||||
|
{
|
||||||
|
return {std::move(l), std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct logical_not
|
||||||
|
{
|
||||||
|
static constexpr auto symbol = "NOT ";
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename R, typename = check_logical_args<R, R>>
|
||||||
|
constexpr auto operator!(R r) -> unary_logical_expression<logical_not, R>
|
||||||
|
{
|
||||||
|
return {std::move(r)};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
@ -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 <sqlpp11/logical_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct logical_not
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = "NOT ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename R, typename = check_logical_args<R, R>>
|
|
||||||
constexpr auto operator!(R r) -> unary_logical_expression<logical_not, R>
|
|
||||||
{
|
|
||||||
return {std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/logical_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct logical_or
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " OR ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_logical_args<L, R>>
|
|
||||||
constexpr auto operator||(L l, R r) -> logical_expression<L, logical_or, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <utility>
|
|
||||||
|
|
||||||
#include <sqlpp11/arithmetic_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct minus
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " - ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_arithmetic_args<L, R>>
|
|
||||||
constexpr auto operator-(L l, R r) -> arithmetic_expression<L, minus, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <utility>
|
|
||||||
|
|
||||||
#include <sqlpp11/arithmetic_expression.h>
|
|
||||||
#include <sqlpp11/type_traits.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct modulus
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " % ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R>
|
|
||||||
using check_modulus_args = std::enable_if_t<has_integral_value<L>::value and has_integral_value<R>::value>;
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_modulus_args<L, R>>
|
|
||||||
constexpr auto operator%(L l, R r) -> arithmetic_expression<L, modulus, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <utility>
|
|
||||||
|
|
||||||
#include <sqlpp11/arithmetic_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct multiplies
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " * ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_arithmetic_args<L, R>>
|
|
||||||
constexpr auto operator*(L l, R r) -> arithmetic_expression<L, multiplies, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <utility>
|
|
||||||
|
|
||||||
#include <sqlpp11/arithmetic_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct negate
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = "-";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename R, typename = check_arithmetic_args<R, R>>
|
|
||||||
constexpr auto operator-(R r) -> unary_arithmetic_expression<divides, R>
|
|
||||||
{
|
|
||||||
return {std::move(r)};
|
|
||||||
}
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/comparison_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct not_equal_to
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " != ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_comparison_args<L, R>>
|
|
||||||
constexpr auto operator!=(L l, R r) -> comparison_expression<L, not_equal_to, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <tuple>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <sqlpp11/in_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct operator_not_in
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " NOT IN ";
|
|
||||||
};
|
|
||||||
|
|
||||||
#warning: something.in(select(...)); should be suppported as is
|
|
||||||
template <typename L, typename... Args, typename = check_in_args<L, Args...>>
|
|
||||||
constexpr auto not_in(L l, std::tuple<Args...> args) -> in_expression<L, operator_not_in, std::tuple<Args...>>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(args)};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename L, typename... Args, typename = check_in_args<L, Args...>>
|
|
||||||
constexpr auto not_in(L l, Args... args) -> in_expression<L, operator_not_in, std::tuple<Args...>>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::make_tuple(std::move(args)...)};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename L, typename Arg, typename = check_in_args<L, Arg>>
|
|
||||||
constexpr auto not_in(L l, std::vector<Arg> args) -> in_expression<L, operator_not_in, std::vector<Arg>>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(args)};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <sqlpp11/sort_order_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
template <typename L, typename = check_sort_order_args<L>>
|
|
||||||
constexpr auto order(L l, sort_order order) -> sort_order_expression<L>
|
|
||||||
{
|
|
||||||
return {l, order};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sqlpp
|
|
@ -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 <utility>
|
|
||||||
|
|
||||||
#include <sqlpp11/arithmetic_expression.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct plus
|
|
||||||
{
|
|
||||||
static constexpr auto symbol = " + ";
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_arithmetic_args<L, R>>
|
|
||||||
constexpr auto operator+(L l, R r) -> arithmetic_expression<L, plus, R>
|
|
||||||
{
|
|
||||||
return {std::move(l), std::move(r)};
|
|
||||||
}
|
|
||||||
} // namespace sqlpp
|
|
@ -78,4 +78,22 @@ namespace sqlpp
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
template <typename L, typename = check_sort_order_args<L>>
|
||||||
|
constexpr auto asc(L l) -> sort_order_expression<L>
|
||||||
|
{
|
||||||
|
return {l, sort_order::asc};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename L, typename = check_sort_order_args<L>>
|
||||||
|
constexpr auto desc(L l) -> sort_order_expression<L>
|
||||||
|
{
|
||||||
|
return {l, sort_order::desc};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename L, typename = check_sort_order_args<L>>
|
||||||
|
constexpr auto order(L l, sort_order order) -> sort_order_expression<L>
|
||||||
|
{
|
||||||
|
return {l, order};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
@ -26,7 +26,7 @@
|
|||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sqlpp11/alias.h>
|
#include <sqlpp11/operator/as_expression.h>
|
||||||
#include <sqlpp11/column_fwd.h>
|
#include <sqlpp11/column_fwd.h>
|
||||||
#include <sqlpp11/detail/type_set.h>
|
#include <sqlpp11/detail/type_set.h>
|
||||||
#include <sqlpp11/serialize.h>
|
#include <sqlpp11/serialize.h>
|
||||||
|
@ -74,6 +74,21 @@ namespace sqlpp
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
using remove_optional_t = typename remove_optional<T>::type;
|
using remove_optional_t = typename remove_optional<T>::type;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct force_optional
|
||||||
|
{
|
||||||
|
using type = sqlpp::compat::optional<T>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct force_optional<sqlpp::compat::optional<T>>
|
||||||
|
{
|
||||||
|
using type = sqlpp::compat::optional<T>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using force_optional_t = typename force_optional<T>::type;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T& get_value(const T& t)
|
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 <typename T>
|
template <typename T>
|
||||||
struct is_numeric : public std::integral_constant<bool, is_integral<T>::value or std::is_floating_point<T>::value>{};
|
struct is_numeric : public std::integral_constant<bool, is_integral<T>::value or std::is_floating_point<T>::value>{};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct is_numeric<numeric> : public std::true_type{};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct is_numeric<sqlpp::compat::nullopt_t> : public std::true_type{};
|
struct is_numeric<sqlpp::compat::nullopt_t> : public std::true_type{};
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ namespace sqlpp
|
|||||||
struct value_t
|
struct value_t
|
||||||
{
|
{
|
||||||
template <typename alias_provider>
|
template <typename alias_provider>
|
||||||
expression_alias_t<value_t, alias_provider> as(const alias_provider& /*unused*/) const
|
as_expression<value_t, alias_provider> as(const alias_provider& /*unused*/) const
|
||||||
{
|
{
|
||||||
return {*this};
|
return {*this};
|
||||||
}
|
}
|
||||||
|
@ -112,27 +112,196 @@ int main()
|
|||||||
static_assert(sqlpp::has_text_value<std::string>::value, "");
|
static_assert(sqlpp::has_text_value<std::string>::value, "");
|
||||||
static_assert(sqlpp::has_numeric_value<int>::value, "");
|
static_assert(sqlpp::has_numeric_value<int>::value, "");
|
||||||
static_assert(sqlpp::has_numeric_value<decltype(bar.intN)>::value, "");
|
static_assert(sqlpp::has_numeric_value<decltype(bar.intN)>::value, "");
|
||||||
#warning: Need to implement value_type_of for expressions
|
|
||||||
//static_assert(sqlpp::has_boolean_value<decltype(!bar.boolNn)>::value, "");
|
|
||||||
//static_assert(sqlpp::has_boolean_value<decltype(bar.boolNn and bar.boolNn)>::value, "");
|
|
||||||
#if 0
|
|
||||||
!bar.boolNn;
|
|
||||||
(bar.boolNn and bar.boolNn).hansi;
|
|
||||||
like(bar.textN, "hansi").berti;
|
|
||||||
|
|
||||||
#endif
|
#warning: These should be moved into comparison type requirement tests, etc.
|
||||||
(bar.textN == "hansi").berti;
|
// Comparing optional value with non-optional value yields optional boolean.
|
||||||
(-bar.intN).berti;
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.textN < "hansi")>,
|
||||||
(bar.intN + 7).berti;
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
(bar.intN << 7).berti;
|
"");
|
||||||
assign(bar.intN, sqlpp::compat::nullopt).berti;
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.textN <= "hansi")>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.textN == "hansi")>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.textN != "hansi")>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.textN >= "hansi")>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.textN < "hansi")>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
// Comparing non-optional value with non-optional value yields non-optional boolean.
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(foo.textNnD < "hansi")>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(foo.textNnD <= "hansi")>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(foo.textNnD == "hansi")>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(foo.textNnD != "hansi")>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(foo.textNnD >= "hansi")>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(foo.textNnD < "hansi")>,
|
||||||
|
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::value_type_of_t<decltype(is_null(bar.textN))>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(is_null(foo.textNnD))>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(is_not_null(bar.textN))>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(is_not_null(foo.textNnD))>,
|
||||||
|
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::value_type_of_t<decltype(is_distinct_from(bar.textN, "hansi"))>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(is_distinct_from(foo.textNnD, "hansi"))>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(is_not_distinct_from(bar.textN, sqlpp::compat::make_optional("hansi")))>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(is_not_distinct_from(foo.textNnD, sqlpp::compat::make_optional("hansi")))>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
|
||||||
|
// LIKE expressions can be NULL is one of their operands can be NULL.
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(like(bar.textN, "hansi"))>, sqlpp::compat::optional<sqlpp::boolean>>::value, "");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(like(foo.textNnD, sqlpp::compat::make_optional("hansi")))>, sqlpp::compat::optional<sqlpp::boolean>>::value, "");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(like(foo.textNnD, "hansi"))>, 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::value_type_of_t<decltype(sqlpp::compat::make_optional(bar.boolNn) and true)>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(sqlpp::compat::make_optional(bar.boolNn) or true)>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(sqlpp::compat::make_optional(bar.boolNn) and
|
||||||
|
sqlpp::compat::make_optional(true))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(sqlpp::compat::make_optional(bar.boolNn) or
|
||||||
|
sqlpp::compat::make_optional(true))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.boolNn and sqlpp::compat::make_optional(true))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.boolNn or sqlpp::compat::make_optional(true))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(not sqlpp::compat::make_optional(bar.boolNn))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
// Logically combining non-optional value with non-optional value yields non-optional boolean.
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.boolNn and true)>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.boolNn or true)>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(not bar.boolNn)>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
// Arithmetically combining optional value with non-optional value yields optional boolean.
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(sqlpp::value(sqlpp::compat::make_optional(7)) + 8)>,
|
||||||
|
sqlpp::compat::optional<sqlpp::numeric>>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(sqlpp::value(8) - sqlpp::compat::make_optional(7))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::numeric>>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(sqlpp::value(sqlpp::compat::make_optional(7)) / sqlpp::compat::make_optional(7))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::numeric>>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
// Same with negate.
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(-sqlpp::value(sqlpp::compat::make_optional(7)))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::numeric>>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
// Arithmetically combining non-optional value with non-optional value yields optional boolean.
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(sqlpp::value(7) + 8)>,
|
||||||
|
sqlpp::numeric>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
// Same with negate.
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(-sqlpp::value(7))>,
|
||||||
|
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::value_type_of_t<decltype(sqlpp::value(sqlpp::compat::make_optional(7)) << 8)>,
|
||||||
|
sqlpp::compat::optional<sqlpp::integral>>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(sqlpp::value(8) << sqlpp::compat::make_optional(7))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::integral>>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
// In expression with and without optional
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(in(sqlpp::value(7), 7, 8, 9))>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(in(sqlpp::value(7), std::vector<int>{7, 8, 9}))>,
|
||||||
|
sqlpp::boolean>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(in(sqlpp::value(sqlpp::compat::make_optional(7)), 7, 8, 9))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(in(sqlpp::value(sqlpp::compat::make_optional(7)), std::vector<int>{7, 8, 9}))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(in(sqlpp::value(7), sqlpp::compat::make_optional(7), 8, 9))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(in(sqlpp::value(7), std::vector<sqlpp::compat::optional<int>>{7, 8, 9}))>,
|
||||||
|
sqlpp::compat::optional<sqlpp::boolean>>::value,
|
||||||
|
"");
|
||||||
|
|
||||||
|
|
||||||
|
// assignment is no value
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(assign(bar.intN, sqlpp::compat::nullopt))>, sqlpp::no_value_t>::value, "");
|
||||||
#warning: This is not the real thing yet
|
#warning: This is not the real thing yet
|
||||||
bar.intN.as(bar.textN).berti;
|
|
||||||
|
|
||||||
in(bar.intN, 7, 8, 9).berti;
|
// as expressions retain the value type of the real thing
|
||||||
in(bar.intN, std::vector<int>{7, 8, 9}).berti;
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(bar.intN.as(bar.textN))>, sqlpp::value_type_of_t<decltype(bar.intN)>>::value, "");
|
||||||
max(bar.intN);
|
|
||||||
sqlpp::max(7);
|
// max can yield NULL if there are no results.
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(max(bar.intN))>, sqlpp::compat::optional<sqlpp::integral>>::value, "");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(max(foo.textNnD))>, sqlpp::compat::optional<sqlpp::text>>::value, "");
|
||||||
|
static_assert(std::is_same<sqlpp::value_type_of_t<decltype(sqlpp::max(7))>, sqlpp::compat::optional<sqlpp::integral>>::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.
|
#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
|
#if 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// result fields are as nullable as the expressions they represent
|
// 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());
|
const auto rows = db(select(bar.id, bar.boolNn, bar.intN, seven).from(bar).unconditionally());
|
||||||
|
Loading…
Reference in New Issue
Block a user