0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Started to remove operand wrapping

This commit is contained in:
Roland Bock 2024-07-05 09:59:38 +02:00
parent 6eb791430a
commit 4baede7434
82 changed files with 2735 additions and 395 deletions

View File

@ -31,40 +31,16 @@
namespace sqlpp
{
struct max_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "max_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T max;
T& operator()()
{
return max;
}
const T& operator()() const
{
return max;
}
};
};
};
template <typename Flag, typename Expr>
struct max_t : public expression_operators<max_t<Flag, Expr>, value_type_of<Expr>>,
struct max_t : public expression_operators<max_t<Flag, Expr>, value_type_of_t<Expr>>,
public aggregate_function_operators<max_t<Flag, Expr>>,
public alias_operators<max_t<Flag, Expr>>
{
using _traits = make_traits<value_type_of<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 _can_be_null = std::true_type;
using _is_aggregate_expression = std::true_type;
using _auto_alias_t = max_alias_t;
max_t(Expr expr) : _expr(expr)
{
}
@ -93,20 +69,18 @@ namespace sqlpp
}
template <typename T>
auto max(T t) -> max_t<noop, wrap_operand_t<T>>
using check_max_arg =
std::enable_if_t<values_are_comparable<T, T>::value and not contains_aggregate_function_t<T>::value>;
template <typename T, typename = check_max_arg<T>>
auto max(T t) -> max_t<noop, T>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"max() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "max() requires an expression as argument");
return {t};
return {std::move(t)};
}
template <typename T>
auto max(const distinct_t& /*unused*/, T t) -> max_t<distinct_t, wrap_operand_t<T>>
template <typename T, typename = check_max_arg<T>>
auto max(const distinct_t& /*unused*/, T t) -> max_t<distinct_t, T>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"max() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "max() requires an expression as argument");
return {t};
return {std::move(t)};
}
} // namespace sqlpp

View File

@ -54,11 +54,11 @@ namespace sqlpp
};
template <typename Flag, typename Expr>
struct min_t : public expression_operators<min_t<Flag, Expr>, value_type_of<Expr>>,
struct min_t : public expression_operators<min_t<Flag, Expr>, value_type_of_t<Expr>>,
public aggregate_function_operators<min_t<Flag, Expr>>,
public alias_operators<min_t<Flag, Expr>>
{
using _traits = make_traits<value_type_of<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 _can_be_null = std::true_type;
using _is_aggregate_expression = std::true_type;

View File

@ -54,11 +54,11 @@ namespace sqlpp
};
template <typename Flag, typename Expr>
struct sum_t : public expression_operators<sum_t<Flag, Expr>, value_type_of<Expr>>,
struct sum_t : public expression_operators<sum_t<Flag, Expr>, value_type_of_t<Expr>>,
public aggregate_function_operators<sum_t<Flag, Expr>>,
public alias_operators<sum_t<Flag, Expr>>
{
using _traits = make_traits<value_type_of<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 _can_be_null = std::true_type;
using _is_aggregate_expression = std::true_type;

View File

@ -33,11 +33,14 @@ namespace sqlpp
template <typename Expression, typename AliasProvider>
struct expression_alias_t
{
using _traits = make_traits<value_type_of<Expression>, tag::is_selectable, tag::is_alias>;
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;
@ -59,6 +62,12 @@ namespace sqlpp
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)
{

View File

@ -35,7 +35,7 @@ namespace sqlpp
template <typename Select>
struct any_t
{
using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>;
using _traits = make_traits<value_type_of_t<Select>, tag::is_multi_expression>;
using _nodes = detail::type_vector<Select>;
any_t(Select select) : _select(select)

View File

@ -0,0 +1,107 @@
#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 arithmetic_expression
{
arithmetic_expression() = delete;
constexpr arithmetic_expression(L l, R r) : _l(l), _r(r)
{
}
arithmetic_expression(const arithmetic_expression&) = default;
arithmetic_expression(arithmetic_expression&&) = default;
arithmetic_expression& operator=(const arithmetic_expression&) = default;
arithmetic_expression& operator=(arithmetic_expression&&) = default;
~arithmetic_expression() = default;
L _l;
R _r;
};
template <typename Operator, typename R>
struct unary_arithmetic_expression
{
unary_arithmetic_expression() = delete;
constexpr unary_arithmetic_expression(R r) : _r(r)
{
}
unary_arithmetic_expression(const unary_arithmetic_expression&) = default;
unary_arithmetic_expression(unary_arithmetic_expression&&) = default;
unary_arithmetic_expression& operator=(const unary_arithmetic_expression&) = default;
unary_arithmetic_expression& operator=(unary_arithmetic_expression&&) = default;
~unary_arithmetic_expression() = default;
R _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>;
#if 0
template <typename L, typename Operator, typename R>
struct nodes_of<arithmetic_expression<L, Operator, R>>
{
using type = type_vector<L, R>;
};
template <typename L, typename Operator, typename R>
struct value_type_of_t<arithmetic_expression<L, Operator, R>>
{
using type = numeric_t;
};
template <typename L, typename Operator, typename R>
constexpr auto requires_braces_v<arithmetic_expression<L, Operator, R>> = true;
template <typename Context, typename L, typename Operator, typename R>
[[nodiscard]] auto to_sql_string(Context& context, const arithmetic_expression<L, Operator, R>& t)
{
return to_sql_string(context, embrace(t._l)) + Operator::symbol + to_sql_string(context, embrace(t._r));
}
template <typename Context, typename Operator, typename R>
[[nodiscard]] auto to_sql_string(Context& context, const arithmetic_expression<none_t, Operator, R>& t)
{
return Operator::symbol + to_sql_string(context, embrace(t._r));
}
template <typename Context, typename L1, typename Operator, typename R1, typename R2>
[[nodiscard]] auto to_sql_string(Context& context,
const arithmetic_expression<arithmetic_expression<L1, Operator, R1>, Operator, R2>& t)
{
return to_sql_string(context, t._l) + Operator::symbol + to_sql_string(context, embrace(t._r));
}
#endif
} // namespace sqlpp

View File

@ -50,7 +50,7 @@ namespace sqlpp
using check_comparison_impl = static_combined_check_t<
static_check_t<logic::any_t<is_expression_t<RhsType>::value, is_multi_expression_t<RhsType>::value>::value,
assert_comparison_rhs_is_expression_t>,
static_check_t<value_type_of<LhsType>::template _is_valid_operand<RhsType>::value,
static_check_t<value_type_of_t<LhsType>::template _is_valid_operand<RhsType>::value,
assert_comparison_rhs_is_valid_operand_t>,
static_check_t<not std::is_same<LhsType, RhsType>::value, assert_comparison_lhs_rhs_differ_t>>;
@ -60,7 +60,7 @@ namespace sqlpp
template <typename LhsType, typename... RhsType>
using check_in_impl = static_combined_check_t<
static_check_t<logic::all_t<is_expression_t<RhsType>::value...>::value, assert_comparison_rhs_is_expression_t>,
static_check_t<logic::all_t<value_type_of<LhsType>::template _is_valid_operand<RhsType>::value...>::value,
static_check_t<logic::all_t<value_type_of_t<LhsType>::template _is_valid_operand<RhsType>::value...>::value,
assert_comparison_rhs_is_valid_operand_t>,
static_check_t<logic::none_t<std::is_same<LhsType, RhsType>::value...>::value,
assert_comparison_lhs_rhs_differ_t>>;
@ -122,6 +122,7 @@ namespace sqlpp
using type = in_expression_t<_check, NewExpr, Expr, wrap_operand_t<T>...>;
};
#if 0
template <typename T>
auto operator==(T t) const -> _new_binary_expression_t<equal_to_t, T>
{
@ -214,7 +215,9 @@ namespace sqlpp
check_in_t<Expr, wrap_operand_t<T>...>::verify();
return {*static_cast<const Expr*>(this), typename wrap_operand<T>::type{t}...};
}
#endif
/*
template <typename Defer = void>
auto operator not() const -> return_type_not_t<Expr, Defer>
{
@ -229,6 +232,16 @@ namespace sqlpp
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator or(const R& r) const -> return_type_or_t<Expr, R>
{
return_type_or<Expr, R>::check::verify();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
*/
/*
template <typename R>
auto operator&(const R& r) const -> return_type_bitwise_and_t<Expr, R>
{
@ -242,14 +255,9 @@ namespace sqlpp
return_type_bitwise_or<Expr, R>::check::verify();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
*/
template <typename R>
auto operator or(const R& r) const -> return_type_or_t<Expr, R>
{
return_type_or<Expr, R>::check::verify();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
/*
template <typename R>
auto operator+(const R& r) const -> return_type_plus_t<Expr, R>
{
@ -284,6 +292,7 @@ namespace sqlpp
return_type_modulus<Expr, R>::check::verify();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
*/
template <typename Defer = void>
auto operator+() const -> return_type_unary_plus_t<Expr, Defer>
@ -292,6 +301,7 @@ namespace sqlpp
return {*static_cast<const Expr*>(this)};
}
/*
template <typename Defer = void>
auto operator-() const -> return_type_unary_minus_t<Expr, Defer>
{
@ -312,5 +322,6 @@ namespace sqlpp
return_type_shift_right<Expr, R>::check::verify();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
*/
};
} // namespace sqlpp

View File

@ -0,0 +1,100 @@
#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 <type_traits>
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
template <typename L, typename Operator, typename R>
struct bit_expression
{
bit_expression() = delete;
constexpr bit_expression(L l, R r) : _l(l), _r(r)
{
}
bit_expression(const bit_expression&) = default;
bit_expression(bit_expression&&) = default;
bit_expression& operator=(const bit_expression&) = default;
bit_expression& operator=(bit_expression&&) = default;
~bit_expression() = default;
L _l;
R _r;
};
template <typename Operator, typename R>
struct unary_bit_expression
{
unary_bit_expression() = delete;
explicit constexpr unary_bit_expression(R r) : _r(r)
{
}
unary_bit_expression(const unary_bit_expression&) = default;
unary_bit_expression(unary_bit_expression&&) = default;
unary_bit_expression& operator=(const unary_bit_expression&) = default;
unary_bit_expression& operator=(unary_bit_expression&&) = default;
~unary_bit_expression() = default;
R _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>;
#if 0
template <typename L, typename Operator, typename R>
struct nodes_of<binary_t<L, Operator, R>>
{
using type = type_vector<L, R>;
};
template <typename L, typename Operator, typename R>
struct value_type_of_t<binary_t<L, Operator, R>>
{
using type = integral_t;
};
template <typename L, typename Operator, typename R>
constexpr auto requires_braces_v<binary_t<L, Operator, R>> = true;
template <typename Context, typename L, typename Operator, typename R>
[[nodiscard]] auto to_sql_string(Context& context, const binary_t<L, Operator, R>& t)
{
return to_sql_string(context, embrace(t._l)) + Operator::symbol + to_sql_string(context, embrace(t._r));
}
template <typename Context, typename Operator, typename R>
[[nodiscard]] auto to_sql_string(Context& context, const binary_t<none_t, Operator, R>& t)
{
return Operator::symbol + to_sql_string(context, embrace(t._r));
}
#endif
} // namespace sqlpp

View File

@ -42,7 +42,7 @@ namespace sqlpp
static_check_t<is_expression_t<wrap_operand_t<Else>>::value, assert_case_else_expression_t>,
static_check_t<logic::any_t<is_sql_null_t<Then>::value,
is_sql_null_t<wrap_operand_t<Else>>::value,
std::is_same<value_type_of<Then>, value_type_of<wrap_operand_t<Else>>>::value>::value,
std::is_same<value_type_of_t<Then>, value_type_of_t<wrap_operand_t<Else>>>::value>::value,
assert_case_then_else_same_type_t>>;
SQLPP_PORTABLE_STATIC_ASSERT(assert_case_then_expression_t, "argument is not a value expression in then()");
@ -61,10 +61,10 @@ namespace sqlpp
struct case_t
: public expression_operators<
case_t<When, Then, Else>,
typename std::conditional<is_sql_null_t<Then>::value, value_type_of<Else>, value_type_of<Then>>::type>,
typename std::conditional<is_sql_null_t<Then>::value, value_type_of_t<Else>, value_type_of_t<Then>>::type>,
public alias_operators<case_t<When, Then, Else>>
{
using _traits = make_traits<value_type_of<Then>, tag::is_expression>;
using _traits = make_traits<value_type_of_t<Then>, tag::is_expression>;
using _nodes = detail::type_vector<When, Then, Else>;
case_t(When when, Then then, Else else_) : _when(when), _then(then), _else(else_)

View File

@ -39,13 +39,14 @@
namespace sqlpp
{
#warning: need to reactivate column operators?
template <typename Table, typename ColumnSpec>
struct column_t : public expression_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>,
public column_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>
struct column_t// : public expression_operators<column_t<Table, ColumnSpec>, typename ColumnSpec::value_type>,
// public column_operators<column_t<Table, ColumnSpec>, typename ColumnSpec::value_type>
{
struct _traits
{
using _value_type = value_type_of<ColumnSpec>;
using _value_type = typename ColumnSpec::value_type;
using _tags = detail::make_joined_set_t<detail::type_set<tag::is_column, tag::is_expression, tag::is_selectable>,
typename ColumnSpec::_traits::_tags>;
};
@ -59,12 +60,7 @@ namespace sqlpp
using _alias_t = typename _spec_t::_alias_t;
template <typename T>
using _is_valid_assignment_operand = is_valid_assignment_operand<value_type_of<ColumnSpec>, T>;
// disambiguation for C++20 / clang
// (see https://bugs.llvm.org/show_bug.cgi?id=46508)
using expression_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>::operator==;
using expression_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>::operator!=;
using _is_valid_assignment_operand = is_valid_assignment_operand<typename ColumnSpec::value_type, T>;
column_t() = default;
column_t(const column_t&) = default;
@ -112,6 +108,12 @@ namespace sqlpp
}
};
template<typename Table, typename ColumnSpec>
struct value_type_of<column_t<Table, ColumnSpec>>
{
using type = typename ColumnSpec::value_type;
};
template <typename Context, typename Table, typename ColumnSpec>
Context& serialize(const column_t<Table, ColumnSpec>&, Context& context)
{

View File

@ -0,0 +1,83 @@
#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

View File

@ -94,9 +94,7 @@ namespace sqlpp
{
using _alias_t = typename FieldSpec::_alias_t;
using _traits = make_traits<value_type_of<FieldSpec>,
tag::must_not_insert,
tag::must_not_update,
using _traits = make_traits<value_type_of_t<FieldSpec>,
tag_if<tag::can_be_null, column_spec_can_be_null_t<FieldSpec>::value>>;
};

View File

@ -38,6 +38,7 @@ namespace sqlpp
{
};
/*
template <typename L, typename R>
struct return_type_and<L, R, unwrapped_binary_operand_check_t<L, is_boolean_t, R, is_boolean_t>>
{
@ -58,4 +59,5 @@ namespace sqlpp
using check = consistent_t;
using type = logical_not_t<wrap_operand_t<T>>;
};
*/
} // namespace sqlpp

View File

@ -45,7 +45,7 @@ namespace sqlpp
struct return_type_plus<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_not_unsigned_t>>
{
using check = consistent_t;
using type = plus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
using type = plus_t<wrap_operand_t<L>, value_type_of_t<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
template <typename L, typename R>
@ -59,7 +59,7 @@ namespace sqlpp
struct return_type_minus<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_not_unsigned_t>>
{
using check = consistent_t;
using type = minus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
using type = minus_t<wrap_operand_t<L>, value_type_of_t<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
template <typename L, typename R>
@ -73,7 +73,7 @@ namespace sqlpp
struct return_type_multiplies<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_not_unsigned_t>>
{
using check = consistent_t;
using type = multiplies_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
using type = multiplies_t<wrap_operand_t<L>, value_type_of_t<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
template <typename L, typename R>

View File

@ -58,10 +58,50 @@ namespace sqlpp
_value_t _t;
};
struct optional_integral_operand : public alias_operators<optional_integral_operand>
{
using _traits = make_traits<integral, tag::is_expression, tag::is_wrapped_value>;
using _nodes = detail::type_vector<>;
using _is_literal_expression = std::true_type;
using _value_t = sqlpp::compat::optional<int64_t>;
using _can_be_null = std::true_type;
optional_integral_operand() : _t{}
{
}
optional_integral_operand(_value_t t) : _t(t)
{
}
optional_integral_operand(const optional_integral_operand&) = default;
optional_integral_operand(optional_integral_operand&&) = default;
optional_integral_operand& operator=(const optional_integral_operand&) = default;
optional_integral_operand& operator=(optional_integral_operand&&) = default;
~optional_integral_operand() = default;
_value_t _t;
};
template <typename Context>
Context& serialize(const integral_operand& t, Context& context)
{
context << t._t;
return context;
}
template <typename Context>
Context& serialize(const optional_integral_operand& t, Context& context)
{
if (t._t.has_value())
{
context << t._t.value();
}
else
{
context << "NULL";
}
return context;
}
} // namespace sqlpp

View File

@ -32,6 +32,7 @@
namespace sqlpp
{
struct integral_operand;
struct optional_integral_operand;
template <typename T>
struct wrap_operand<T,
@ -40,4 +41,12 @@ namespace sqlpp
{
using type = integral_operand;
};
template <typename T>
struct wrap_operand<sqlpp::compat::optional<T>,
typename std::enable_if<std::is_integral<T>::value and not std::is_same<bool, T>::value and
not std::is_unsigned<T>::value>::type>
{
using type = optional_integral_operand;
};
} // namespace sqlpp

View File

@ -52,13 +52,6 @@ namespace sqlpp
{
template <typename T>
using _is_valid_operand = is_valid_operand<text, T>;
template <typename R>
auto like(const R& r) const -> return_type_like_t<Expression, R>
{
return_type_like<Expression, R>::check::verify();
return {*static_cast<const Expression*>(this), wrap_operand_t<R>{r}};
}
};
template <typename L, typename R>

View File

@ -47,14 +47,14 @@ namespace sqlpp
struct return_type_plus<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = plus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
using type = plus_t<wrap_operand_t<L>, value_type_of_t<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_minus<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_numeric_not_unsigned_t>>
{
using check = consistent_t;
using type = minus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
using type = minus_t<wrap_operand_t<L>, value_type_of_t<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
template <typename L, typename R>
@ -68,7 +68,7 @@ namespace sqlpp
struct return_type_multiplies<L, R, binary_operand_check_t<L, is_unsigned_integral_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = multiplies_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
using type = multiplies_t<wrap_operand_t<L>, value_type_of_t<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
template <typename L, typename R>

View File

@ -42,7 +42,7 @@ namespace sqlpp
static_assert(required_tables_of<Expr>::size::value == 0,
"Expression cannot be used in eval because it requires tables");
using _name_type = alias::a_t::_alias_t;
using _value_type = value_type_of<Expr>;
using _value_type = value_type_of_t<Expr>;
using _field_spec = field_spec_t<_name_type, _value_type, true>;
using type = typename _field_spec::cpp_type;
};

View File

@ -1,94 +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/char_sequence.h>
#include <sqlpp11/data_types/boolean.h>
namespace sqlpp
{
struct exists_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "exists_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T exists;
T& operator()()
{
return exists;
}
const T& operator()() const
{
return exists;
}
};
};
};
template <typename Select>
struct exists_t : public expression_operators<exists_t<Select>, boolean>, public alias_operators<exists_t<Select>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Select>;
using _can_be_null = std::false_type;
static_assert(is_select_t<Select>::value, "exists() requires a select expression as argument");
using _auto_alias_t = exists_alias_t;
exists_t(Select select) : _select(select)
{
}
exists_t(const exists_t&) = default;
exists_t(exists_t&&) = default;
exists_t& operator=(const exists_t&) = default;
exists_t& operator=(exists_t&&) = default;
~exists_t() = default;
Select _select;
};
template <typename Context, typename Select>
Context& serialize(const exists_t<Select>& t, Context& context)
{
context << "EXISTS";
serialize_operand(t._select, context);
return context;
}
template <typename T>
auto exists(T t) -> exists_t<wrap_operand_t<T>>
{
static_assert(is_select_t<wrap_operand_t<T>>::value, "exists() requires a select expression as argument");
return {t};
}
} // namespace sqlpp

View File

@ -137,10 +137,10 @@ namespace sqlpp
}
template <typename Lhs, typename O, typename Rhs>
struct binary_expression_t : public expression_operators<binary_expression_t<Lhs, O, Rhs>, value_type_of<O>>,
struct binary_expression_t : public expression_operators<binary_expression_t<Lhs, O, Rhs>, value_type_of_t<O>>,
public alias_operators<binary_expression_t<Lhs, O, Rhs>>
{
using _traits = make_traits<value_type_of<O>, tag::is_expression>;
using _traits = make_traits<value_type_of_t<O>, tag::is_expression>;
using _nodes = detail::type_vector<Lhs, Rhs>;
binary_expression_t(Lhs lhs, Rhs rhs) : _lhs(lhs), _rhs(rhs)
@ -169,10 +169,10 @@ namespace sqlpp
}
template <typename O, typename Rhs>
struct unary_expression_t : public expression_operators<unary_expression_t<O, Rhs>, value_type_of<O>>,
struct unary_expression_t : public expression_operators<unary_expression_t<O, Rhs>, value_type_of_t<O>>,
public alias_operators<unary_expression_t<O, Rhs>>
{
using _traits = make_traits<value_type_of<O>, tag::is_expression>;
using _traits = make_traits<value_type_of_t<O>, tag::is_expression>;
using _nodes = detail::type_vector<Rhs>;
unary_expression_t(Rhs rhs) : _rhs(rhs)

View File

@ -97,7 +97,7 @@ namespace sqlpp
struct return_type_plus
{
using check = assert_valid_operands;
using type = bad_expression<value_type_of<L>>;
using type = bad_expression<value_type_of_t<L>>;
};
template <typename L, typename R>
using return_type_plus_t = typename return_type_plus<L, R>::type;
@ -106,7 +106,7 @@ namespace sqlpp
struct return_type_minus
{
using check = assert_valid_operands;
using type = bad_expression<value_type_of<L>>;
using type = bad_expression<value_type_of_t<L>>;
};
template <typename L, typename R>
using return_type_minus_t = typename return_type_minus<L, R>::type;
@ -115,7 +115,7 @@ namespace sqlpp
struct return_type_multiplies
{
using check = assert_valid_operands;
using type = bad_expression<value_type_of<L>>;
using type = bad_expression<value_type_of_t<L>>;
};
template <typename L, typename R>
using return_type_multiplies_t = typename return_type_multiplies<L, R>::type;
@ -124,7 +124,7 @@ namespace sqlpp
struct return_type_divides
{
using check = assert_valid_operands;
using type = bad_expression<value_type_of<L>>;
using type = bad_expression<value_type_of_t<L>>;
};
template <typename L, typename R>
using return_type_divides_t = typename return_type_divides<L, R>::type;
@ -133,7 +133,7 @@ namespace sqlpp
struct return_type_modulus
{
using check = assert_valid_operands;
using type = bad_expression<value_type_of<L>>;
using type = bad_expression<value_type_of_t<L>>;
};
template <typename L, typename R>
using return_type_modulus_t = typename return_type_modulus<L, R>::type;
@ -142,7 +142,7 @@ namespace sqlpp
struct return_type_unary_plus
{
using check = assert_valid_operands;
using type = bad_expression<value_type_of<T>>;
using type = bad_expression<value_type_of_t<T>>;
};
template <typename T, typename Defer>
using return_type_unary_plus_t = typename return_type_unary_plus<T, Defer>::type;
@ -151,7 +151,7 @@ namespace sqlpp
struct return_type_unary_minus
{
using check = assert_valid_operands;
using type = bad_expression<value_type_of<T>>;
using type = bad_expression<value_type_of_t<T>>;
};
template <typename T, typename Defer>
using return_type_unary_minus_t = typename return_type_unary_minus<T, Defer>::type;

View File

@ -37,11 +37,6 @@ namespace sqlpp
template <typename NameType, typename ValueType, bool CanBeNull>
struct field_spec_t
{
using _traits = make_traits<ValueType,
tag::is_noop,
tag_if<tag::can_be_null, CanBeNull>>;
using _nodes = detail::type_vector<>;
using _alias_t = NameType;
using cpp_type = typename std::conditional<CanBeNull,
@ -77,13 +72,14 @@ namespace sqlpp
struct make_field_spec_impl
{
using RawNamedExpr = remove_optional_t<NamedExpr>;
static constexpr bool _can_be_null = is_optional<NamedExpr>::value or can_be_null_t<RawNamedExpr>::value;
using ValueType = value_type_of_t<RawNamedExpr>;
static constexpr bool _can_be_null = is_optional<ValueType>::value or is_optional<NamedExpr>::value;
static constexpr bool _depends_on_outer_table =
detail::make_intersect_set_t<required_tables_of<RawNamedExpr>,
typename Select::_used_outer_tables>::size::value > 0;
using type = field_spec_t<typename RawNamedExpr::_alias_t,
value_type_of<RawNamedExpr>,
remove_optional_t<ValueType>,
logic::any_t<_can_be_null, _depends_on_outer_table>::value>;
};
} // namespace detail

View File

@ -39,7 +39,6 @@
#include <sqlpp11/not_in.h>
#include <sqlpp11/is_null.h>
#include <sqlpp11/is_not_null.h>
#include <sqlpp11/exists.h>
#include <sqlpp11/any.h>
#include <sqlpp11/some.h>
#include <sqlpp11/value_type.h>
@ -54,7 +53,7 @@
namespace sqlpp
{
template <typename Expression, typename Db>
auto flatten(const Expression& exp, Db& db) -> verbatim_t<value_type_of<Expression>>
auto flatten(const Expression& exp, Db& db) -> verbatim_t<value_type_of_t<Expression>>
{
static_assert(not make_parameter_list_t<Expression>::size::value,
"parameters are not allowed in flattened expressions");

View File

@ -58,7 +58,7 @@ namespace sqlpp
{
using _is_insert_value = std::true_type;
using _column_t = Column;
using _pure_value_t = typename value_type_of<Column>::_cpp_value_type;
using _pure_value_t = typename value_type_of_t<Column>::_cpp_value_type;
using _wrapped_value_t = wrap_operand_t<_pure_value_t>;
using _value_or_null_t = value_or_null_t<typename Column::_traits::_value_type>;

View File

@ -138,8 +138,6 @@ namespace sqlpp
SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_set_assignments_t, "at least one argument is not an assignment in set()");
SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_set_no_duplicates_t, "at least one duplicate column detected in set()");
SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_set_allowed_t,
"at least one assignment is prohibited by its column definition in set()");
SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_set_single_table_t,
"set() arguments contain assignments from more than one table");
SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_static_set_count_args_t,
@ -149,31 +147,12 @@ namespace sqlpp
SQLPP_PORTABLE_STATIC_ASSERT(assert_insert_dynamic_set_statement_dynamic_t,
"dynamic_set must not be called in a static statement");
// workaround for msvc bugs https://connect.microsoft.com/VisualStudio/Feedback/Details/2173269 &
// https://connect.microsoft.com/VisualStudio/Feedback/Details/2173198
// template <typename... Assignments>
// using check_insert_set_t = static_combined_check_t<
// static_check_t<logic::all_t<is_assignment_t<Assignments>::value...>::value, assert_insert_set_assignments_t>,
// static_check_t<not detail::has_duplicates<lhs_t<Assignments>...>::value, assert_insert_set_no_duplicates_t>,
// static_check_t<logic::none_t<must_not_insert_t<lhs_t<Assignments>>::value...>::value,
// assert_insert_set_allowed_t>,
// static_check_t<sizeof...(Assignments) == 0 or
// detail::make_joined_set_t<required_tables_of<lhs_t<Assignments>>...>::size::value == 1,
// assert_insert_set_single_table_t>>;
template <typename Expr>
struct must_not_insert
{
static const bool value = must_not_insert_t<lhs_t<Expr>>::value;
};
template <typename... Assignments>
using check_insert_set_t = static_combined_check_t<
static_check_t<logic::all_t<detail::is_assignment_impl<Assignments>::type::value...>::value,
assert_insert_set_assignments_t>,
static_check_t<not detail::has_duplicates<typename lhs<Assignments>::type...>::value,
assert_insert_set_no_duplicates_t>,
static_check_t<logic::none_t<must_not_insert<Assignments>::value...>::value, assert_insert_set_allowed_t>,
static_check_t<sizeof...(Assignments) == 0 or detail::make_joined_set_t<required_tables_of<
typename lhs<Assignments>::type>...>::size::value == 1,
assert_insert_set_single_table_t>>;
@ -382,8 +361,6 @@ namespace sqlpp
{
static_assert(not detail::has_duplicates<Columns...>::value,
"at least one duplicate argument detected in columns()");
static_assert(logic::none_t<must_not_insert_t<Columns>::value...>::value,
"at least one column argument has a must_not_insert tag in its definition");
using _column_required_tables = detail::make_joined_set_t<required_tables_of<Columns>...>;
static_assert(_column_required_tables::size::value == 1, "columns() contains columns from several tables");

View File

@ -68,7 +68,7 @@ namespace sqlpp
{
static_assert(is_expression_t<Expr>::value,
"is_equal_to_or_null() is to be called an expression (e.g. a column) and a value_or_null expression");
static_assert(std::is_same<value_type_of<Expr>, ValueType>::value,
static_assert(std::is_same<value_type_of_t<Expr>, ValueType>::value,
"is_equal_to_or_null() arguments need to have the same value type");
return {expr, value};
}

View File

@ -0,0 +1,123 @@
#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 <type_traits>
#include <sqlpp11/alias.h>
//#include <sqlpp11/bad_expression.h>
//#include <sqlpp11/embrace.h>
//#include <sqlpp11/to_sql_string.h>
#include <sqlpp11/type_traits.h>
//#include <sqlpp11/wrapped_static_assert.h>
namespace sqlpp
{
template <typename L, typename Operator, typename R>
struct logical_expression
{
logical_expression() = delete;
constexpr logical_expression(L l, R r) : _l(l), _r(r)
{
}
logical_expression(const logical_expression&) = default;
logical_expression(logical_expression&&) = default;
logical_expression& operator=(const logical_expression&) = default;
logical_expression& operator=(logical_expression&&) = default;
~logical_expression() = default;
template <typename alias_provider>
expression_alias_t<logical_expression, alias_provider> as(const alias_provider& /*unused*/) const
{
return {*this};
}
L _l;
R _r;
};
template <typename Operator, typename R>
struct unary_logical_expression
{
unary_logical_expression() = delete;
constexpr unary_logical_expression(R r) : _r(r)
{
}
unary_logical_expression(const unary_logical_expression&) = default;
unary_logical_expression(unary_logical_expression&&) = default;
unary_logical_expression& operator=(const unary_logical_expression&) = default;
unary_logical_expression& operator=(unary_logical_expression&&) = default;
~unary_logical_expression() = default;
template <typename alias_provider>
expression_alias_t<unary_logical_expression, alias_provider> as(const alias_provider& /*unused*/) const
{
return {*this};
}
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 nodes_of<logical_binary_expression<L, Operator, R>>
{
using type = type_vector<L, R>;
};
template <typename L, typename Operator, typename R>
struct value_type_of_t<logical_binary_expression<L, Operator, R>>
{
using type = bool;
};
template <typename L, typename Operator, typename R>
constexpr auto requires_braces_v<logical_binary_expression<L, Operator, R>> = true;
template <typename Context, typename L, typename Operator, typename R>
[[nodiscard]] auto to_sql_string(Context& context, const logical_binary_expression<L, Operator, R>& t)
{
return to_sql_string(context, embrace(t._l)) + Operator::symbol + to_sql_string(context, embrace(t._r));
}
template <typename Context, typename Operator, typename R>
[[nodiscard]] auto to_sql_string(Context& context, const logical_binary_expression<none_t, Operator, R>& t)
{
return Operator::symbol + to_sql_string(context, embrace(t._r));
}
template <typename Context, typename L1, typename Operator, typename R1, typename R2>
[[nodiscard]] auto to_sql_string(Context& context, const logical_binary_expression<logical_binary_expression<L1, Operator, R1>, Operator, R2>& t)
{
return to_sql_string(context, t._l) + Operator::symbol + to_sql_string(context, embrace(t._r));
}
*/
} // namespace sqlpp

View File

@ -0,0 +1,83 @@
#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.
*/
/* Hint
Most operators are using enable_if instead of wrapped static_assert.
This is because variants with static_assert would enter the overload
set and cause havoc.
*/
// logical
#include <sqlpp11/operator/logical_and.h>
#include <sqlpp11/operator/logical_not.h>
#include <sqlpp11/operator/logical_or.h>
// comparison
#include <sqlpp11/operator/equal_to.h>
#include <sqlpp11/operator/greater.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
#include <sqlpp11/operator/divides.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
#include <sqlpp11/operator/bit_and.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
#include <sqlpp11/operator/assign.h>
// misc
#include <sqlpp11/operator/as.h>
#include <sqlpp11/operator/asc.h>
#include <sqlpp11/operator/desc.h>
#include <sqlpp11/operator/order.h>
#include <sqlpp11/operator/in.h>
#include <sqlpp11/operator/not_in.h>
#include <sqlpp11/operator/exists.h>

View File

@ -0,0 +1,47 @@
#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

View File

@ -0,0 +1,39 @@
#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

View File

@ -0,0 +1,82 @@
#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 <utility>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/default_value.h>
namespace sqlpp
{
template <typename L, typename R>
struct assign_expression
{
L column;
R value;
};
#warning rename is_column, is_default, values_are_comparable -> values_are_compatible
#warning document the change that there is no read-only!
#warning handle default_t, but only if the column does have a default!
template <typename L, typename R>
using check_assign_args = std::enable_if_t<is_column_t<L>::value and values_are_comparable<L, R>::value and
(can_be_null_t<L>::value or not is_optional<R>::value) and
(has_default_t<L>::value or not std::is_same<R, default_value_t>::value)>;
template <typename L, typename R, typename = check_assign_args<L, R>>
constexpr auto assign(L column, R value) -> assign_expression<L, R>
{
return {std::move(column), std::move(value)};
}
/*
template <typename L, typename R>
struct nodes_of<assign_t<L, R>>
{
using type = type_vector<L, R>;
};
template <typename L, typename R>
constexpr auto is_assignment_v<assign_t<L, R>> = true;
template <typename L, typename R>
struct column_of<assign_t<L, R>>
{
using type = L;
};
template <typename L, typename R>
constexpr auto requires_braces_v<assign_t<L, R>> = true;
template <typename Context, typename L, typename R>
[[nodiscard]] auto to_sql_string(Context& context, const assign_t<L, R>& t)
{
return to_sql_string(context, t.column) + " = " + to_sql_string(context, embrace(t.value));
}
*/
} // namespace sqlpp

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,39 @@
#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

View File

@ -0,0 +1,45 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,68 @@
#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/type_traits.h>
namespace sqlpp
{
template <typename SubSelect>
struct exists_t
{
SubSelect sub_select;
};
template <typename SubSelect>
using check_exists_arg = std::enable_if_t<is_statement_t<SubSelect>::value and has_result_row_t<SubSelect>::value>;
#warning: Document that functions dont come with their default alias any more
template <typename SubSelect, typename = check_exists_arg<SubSelect>>
constexpr auto exists(SubSelect sub_select) -> exists_t<SubSelect>
{
return exists_t<SubSelect>{sub_select};
}
/*
template <typename SubSelect>
struct nodes_of<exists_t<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>
[[nodiscard]] auto to_sql_string(Context& context, const exists_t<SubSelect>& t)
{
return " EXISTS(" + to_sql_string(context, t.sub_select) + ") ";
}
*/
} // namespace sqlpp

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,60 @@
#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

View File

@ -0,0 +1,46 @@
#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

View File

@ -0,0 +1,46 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,45 @@
#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

View File

@ -0,0 +1,49 @@
#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

View File

@ -0,0 +1,45 @@
#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

View File

@ -0,0 +1,45 @@
#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

View File

@ -0,0 +1,44 @@
#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

View File

@ -0,0 +1,60 @@
#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

View File

@ -0,0 +1,39 @@
#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

View File

@ -0,0 +1,45 @@
#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

View File

@ -64,7 +64,7 @@ namespace sqlpp
}
template <typename NamedExpr>
auto parameter(const NamedExpr & /*unused*/) -> parameter_t<value_type_of<NamedExpr>, NamedExpr>
auto parameter(const NamedExpr & /*unused*/) -> parameter_t<value_type_of_t<NamedExpr>, NamedExpr>
{
static_assert(is_selectable_t<NamedExpr>::value, "not a named expression");
return {};

View File

@ -60,7 +60,7 @@ namespace sqlpp
template <typename Column>
struct returning_traits<Column>
{
using _traits = make_traits<value_type_of<Column>,
using _traits = make_traits<value_type_of_t<Column>,
tag::is_returning_column_list,
tag::is_return_value,
tag::is_expression,

View File

@ -40,7 +40,7 @@ namespace sqlpp
template <typename Table>
struct schema_qualified_table_t
{
using _traits = make_traits<value_type_of<Table>, tag::is_table>;
using _traits = make_traits<value_type_of_t<Table>, tag::is_table>;
using _nodes = detail::type_vector<>;
using _required_ctes = detail::type_set<>;

View File

@ -55,7 +55,7 @@ namespace sqlpp
template <typename Column>
struct select_traits<Column>
{
using _traits = make_traits<value_type_of<remove_optional_t<Column>>,
using _traits = make_traits<value_type_of_t<remove_optional_t<Column>>,
tag::is_select_column_list,
tag::is_return_value,
tag::is_expression,

View File

@ -44,9 +44,8 @@ namespace sqlpp
detail::make_intersect_set_t<required_tables_of<NamedExpr>, typename Select::_used_outer_tables>::size::value >
0;
using _traits = make_traits<value_type_of<NamedExpr>,
tag::must_not_insert,
tag::must_not_update,
#warning: somehow prevent insert...
using _traits = make_traits<value_type_of_t<NamedExpr>,
tag_if<tag::can_be_null, _can_be_null or _depends_on_outer_table>>;
};
@ -59,7 +58,7 @@ namespace sqlpp
template<typename NamedExpr>
struct select_expression_type<NamedExpr> {
using value_t = value_type_of<NamedExpr>;
using value_t = value_type_of_t<NamedExpr>;
static constexpr bool _is_expression = true;
static constexpr bool _can_be_null = can_be_null_t<NamedExpr>::value;
};

View File

@ -35,7 +35,7 @@ namespace sqlpp
template <typename Select>
struct some_t
{
using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>;
using _traits = make_traits<value_type_of_t<Select>, tag::is_multi_expression>;
using _nodes = detail::type_vector<Select>;
some_t(Select select) : _select(select)

View File

@ -0,0 +1,81 @@
#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 <type_traits>
namespace sqlpp
{
enum class sort_order
{
asc,
desc,
};
template <typename L>
struct sort_order_expression
{
L l;
sort_order order;
};
template <typename L>
using check_sort_order_args = std::enable_if_t<values_are_comparable<L, L>::value>;
/*
template <typename L>
struct nodes_of<sort_order_t<L>>
{
using type = type_vector<L>;
};
template <typename L>
constexpr auto requires_braces_v<sort_order_t<L>> = false;
template <typename L>
constexpr auto is_sort_order_v<sort_order_t<L>> = true;
template <typename Context>
[[nodiscard]] auto to_sql_string(Context& context, const sort_order& t)
{
switch (t)
{
case sort_order::asc:
return std::string(" ASC");
case sort_order::desc:
return std::string(" DESC");
}
}
template <typename Context, typename L>
[[nodiscard]] auto to_sql_string(Context& context, const sort_order_t<L>& t)
{
return to_sql_string(context, embrace(t.l)) + to_sql_string(context, t.order);
}
*/
} // namespace sqlpp

View File

@ -33,6 +33,7 @@
#include <sqlpp11/update.h>
#include <sqlpp11/select.h>
#include <sqlpp11/functions.h>
#include <sqlpp11/operator.h>
#include <sqlpp11/transaction.h>
#include <sqlpp11/without_table_check.h>
#include <sqlpp11/schema_qualified_table.h>

View File

@ -132,7 +132,7 @@ namespace sqlpp
typename std::conditional<is_any_policy_missing<Policies...>(),
no_value_t, // if a required statement part is missing (e.g. columns in a select),
// then the statement cannot be used as a value
value_type_of<_result_type_provider>>::type;
value_type_of_t<_result_type_provider>>::type;
using _traits =
make_traits<_value_type, tag_if<tag::is_expression, not std::is_same<_value_type, no_value_t>::value>>;
@ -151,12 +151,19 @@ namespace sqlpp
using _parameter_check = typename std::
conditional<detail::type_vector_size<_parameters>::value == 0, consistent_t, assert_no_parameters_t>::type;
};
} // namespace detail
template <typename... Policies>
struct value_type_of<detail::statement_policies_t<Policies...>>
{
using type = typename detail::statement_policies_t<Policies...>::_value_type;
};
template <typename... Policies>
struct statement_t : public Policies::template _base_t<detail::statement_policies_t<Policies...>>...,
public expression_operators<statement_t<Policies...>,
value_type_of<detail::statement_policies_t<Policies...>>>,
value_type_of_t<detail::statement_policies_t<Policies...>>>,
public detail::statement_policies_t<Policies...>::_result_methods_t
{
using _policies_t = typename detail::statement_policies_t<Policies...>;
@ -185,7 +192,7 @@ namespace sqlpp
using _result_methods_t = typename _result_type_provider::template _result_methods_t<Composite>;
using _traits =
make_traits<value_type_of<_policies_t>,
make_traits<value_type_of_t<_policies_t>,
tag::is_statement,
tag_if<tag::is_select, logic::any_t<is_select_t<Policies>::value...>::value>,
tag_if<tag::is_expression, is_expression_t<_policies_t>::value>,

View File

@ -48,8 +48,6 @@ namespace sqlpp
using _provided_tables = detail::type_set<Table>;
static_assert(sizeof...(ColumnSpec) > 0, "at least one column required per table");
using _required_insert_columns =
typename detail::make_type_set_if<require_insert_t, column_t<Table, ColumnSpec>...>::type;
using _column_tuple_t = std::tuple<column_t<Table, ColumnSpec>...>;
template <typename AliasProvider, typename T>
using _foreign_table_alias_t = table_alias_t<AliasProvider, T, ColumnSpec...>;

View File

@ -41,7 +41,7 @@ namespace sqlpp
template <typename AliasProvider, typename Table, typename... ColumnSpec>
struct table_alias_t : public ColumnSpec::_alias_t::template _member_t<column_t<AliasProvider, ColumnSpec>>...
{
using _traits = make_traits<value_type_of<Table>,
using _traits = make_traits<value_type_of_t<Table>,
tag::is_table,
tag::is_alias,
tag_if<tag::can_be_null, can_be_null_t<Table>::value>,

View File

@ -26,10 +26,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <type_traits>
#include <cstdint>
#include <tuple>
#include <type_traits>
#include <vector>
#include <sqlpp11/chrono.h>
#include <sqlpp11/compat/optional.h>
#include <sqlpp11/compat/string_view.h>
#include <sqlpp11/compat/span.h>
#include <sqlpp11/consistent.h>
#include <sqlpp11/portable_static_assert.h>
#include <sqlpp11/detail/type_vector.h>
@ -49,6 +54,11 @@ namespace sqlpp
{
};
template <>
struct is_optional<sqlpp::compat::nullopt_t> : public std::true_type
{
};
template <typename T>
struct remove_optional
{
@ -61,6 +71,9 @@ namespace sqlpp
using type = T;
};
template <typename T>
using remove_optional_t = typename remove_optional<T>::type;
template <typename T>
const T& get_value(const T& t)
{
@ -85,26 +98,26 @@ namespace sqlpp
return t.has_value();
}
template <typename T>
using remove_optional_t = typename remove_optional<T>::type;
struct no_value_t;
namespace detail
{
template <typename T, typename Enable = void>
struct value_type_of_impl
{
using type = no_value_t;
};
template <typename T>
struct value_type_of_impl<T, detail::void_t<typename T::_traits::_value_type>>
{
using type = typename T::_traits::_value_type;
};
} // namespace detail
// This requires specializations for anything that has a value, like a column or a boolean expression
template <typename T>
using value_type_of = typename detail::value_type_of_impl<T>::type;
struct value_type_of
{
using type = no_value_t;
};
template <typename T>
using value_type_of_t = typename value_type_of<T>::type;
template<typename T>
struct value_type_of<sqlpp::compat::optional<T>>
{
using type = sqlpp::compat::optional<value_type_of_t<remove_optional_t<T>>>;
};
template <typename T>
struct has_value_type : public std::integral_constant<bool, not std::is_same<value_type_of_t<T>, no_value_t>::value> {};
template <typename T>
struct is_not_cpp_bool_t
@ -112,42 +125,280 @@ namespace sqlpp
static constexpr bool value = not std::is_same<T, bool>::value;
};
// data types
struct blob;
template <typename T>
using is_blob_t = std::is_same<value_type_of<T>, blob>;
//
struct boolean;
template <typename T>
using is_boolean_t = std::is_same<value_type_of<T>, boolean>;
template<>
struct value_type_of<bool> { using type = boolean; };
struct day_point;
template <typename T>
using is_day_point_t = std::is_same<value_type_of<T>, day_point>;
struct integral;
template<>
struct value_type_of<int8_t> { using type = integral; };
template<>
struct value_type_of<int16_t> { using type = integral; };
template<>
struct value_type_of<int32_t> { using type = integral; };
template<>
struct value_type_of<int64_t> { using type = integral; };
struct unsigned_integral;
template<>
struct value_type_of<uint8_t> { using type = unsigned_integral; };
template<>
struct value_type_of<uint16_t> { using type = unsigned_integral; };
template<>
struct value_type_of<uint32_t> { using type = unsigned_integral; };
template<>
struct value_type_of<uint64_t> { using type = unsigned_integral; };
struct floating_point;
template<>
struct value_type_of<float> { using type = floating_point; };
template<>
struct value_type_of<double> { using type = floating_point; };
struct text;
template <>
struct value_type_of<char> { using type = text; };
template <>
struct value_type_of<const char*> { using type = text; };
template <>
struct value_type_of<std::string> { using type = text; };
template <>
struct value_type_of<sqlpp::compat::string_view> { using type = text; };
/////////////////
struct blob;
template <>
struct value_type_of<std::vector<std::uint8_t>> { using type = blob; };
template <>
struct value_type_of<sqlpp::compat::span<std::uint8_t>> { using type = blob; };
struct day_point;
template <>
struct value_type_of<std::chrono::time_point<std::chrono::system_clock, sqlpp::chrono::days>> { using type = day_point; };
struct time_of_day;
template <typename Rep, typename Period>
struct value_type_of<std::chrono::duration<Rep, Period>> { using type = time_of_day; };
struct time_point;
template <typename Period>
struct value_type_of<std::chrono::time_point<std::chrono::system_clock, Period>> { using type = time_point; };
/////////////////
template <typename T>
using is_floating_point_t = std::is_same<value_type_of<T>, floating_point>;
struct is_boolean : public std::is_same<T, bool>
{
};
template <>
struct is_boolean<boolean> : public std::true_type {
};
template <>
struct is_boolean<sqlpp::compat::nullopt_t> : public std::true_type {
};
template <typename T>
struct has_boolean_value : public std::integral_constant<bool,
is_boolean<remove_optional_t<T>>::value or
is_boolean<remove_optional_t<value_type_of_t<T>>>::value>
{
};
struct integral;
template <typename T>
using is_integral_t = std::is_same<value_type_of<T>, integral>;
struct is_integral : public std::is_integral<T>{};
template <>
struct is_integral<char> : public std::false_type // char is text
{
};
template <>
struct is_integral<bool> : public std::false_type // bool is boolean
{
};
template <>
struct is_integral<sqlpp::compat::nullopt_t> : public std::true_type{};
template <>
struct is_integral<integral> : public std::true_type{};
struct unsigned_integral;
template <typename T>
using is_unsigned_integral_t = std::is_same<value_type_of<T>, unsigned_integral>;
struct has_integral_value
: public std::integral_constant<bool,
is_integral<remove_optional_t<T>>::value or
is_integral<remove_optional_t<value_type_of_t<T>>>::value>
{
};
template <typename T>
struct is_numeric : public std::integral_constant<bool, is_integral<T>::value or std::is_floating_point<T>::value>{};
template <>
struct is_numeric<sqlpp::compat::nullopt_t> : public std::true_type{};
template <typename T>
struct has_numeric_value : public std::integral_constant<bool,
is_numeric<remove_optional_t<T>>::value or is_numeric<remove_optional_t<value_type_of_t<T>>>::value>{};
struct text;
template <typename T>
using is_text_t = std::is_same<value_type_of<T>, text>;
struct is_text : public std::false_type {};
template <>
struct is_text<text> : public std::true_type {};
template <>
struct is_text<char> : public std::true_type {};
template <>
struct is_text<const char*> : public std::true_type {};
template <>
struct is_text<std::string> : public std::true_type {};
template <>
struct is_text<sqlpp::compat::string_view> : public std::true_type {};
template <>
struct is_text<sqlpp::compat::nullopt_t> : public std::true_type {};
template <typename T>
struct has_text_value : public std::integral_constant<bool,
is_text<remove_optional_t<T>>::value or
is_text<remove_optional_t<value_type_of_t<T>>>::value>{};
struct blob;
template <typename T>
struct is_blob : public std::false_type {};
template <>
struct is_blob<blob> : public std::true_type {};
template <>
struct is_blob<std::vector<std::uint8_t>> : public std::true_type {};
template <>
struct is_blob<sqlpp::compat::span<std::uint8_t>> : public std::true_type {};
template <>
struct is_blob<sqlpp::compat::nullopt_t> : public std::true_type {};
template <typename T>
struct has_blob_value : public std::integral_constant<bool,
is_blob<remove_optional_t<T>>::value or
is_blob<remove_optional_t<value_type_of_t<T>>>::value>{};
struct day_point;
template <typename T>
struct is_day_point : public std::false_type {};
template <>
struct is_day_point<day_point> : public std::true_type {};
template <>
struct is_day_point<std::chrono::time_point<std::chrono::system_clock, sqlpp::chrono::days>> : public std::true_type {};
template <>
struct is_day_point<sqlpp::compat::nullopt_t> : public std::true_type {};
template <typename T>
struct has_day_point_value : public std::integral_constant<bool,
is_day_point<remove_optional_t<T>>::value or
is_day_point<remove_optional_t<value_type_of_t<T>>>::value>{};
struct time_of_day;
template <typename T>
using is_time_of_day_t = std::is_same<value_type_of<T>, time_of_day>;
struct is_time_of_day : public std::false_type {};
template <>
struct is_time_of_day<time_of_day> : public std::true_type {};
template <typename Rep, typename Period>
struct is_time_of_day<std::chrono::duration<Rep, Period>> : public std::true_type {};
template <>
struct is_time_of_day<sqlpp::compat::nullopt_t> : public std::true_type {};
template <typename T>
struct has_time_of_day_value : public std::integral_constant<bool,
is_time_of_day<remove_optional_t<T>>::value or
is_time_of_day<remove_optional_t<value_type_of_t<T>>>::value>{};
struct time_point;
template <typename T>
using is_time_point_t = std::is_same<value_type_of<T>, time_point>;
struct is_time_point : public std::false_type {};
template <>
struct is_time_point<time_point> : public std::true_type {};
template <typename Period>
struct is_time_point<std::chrono::time_point<std::chrono::system_clock, Period>> : public std::true_type {};
template <>
struct is_time_point<sqlpp::compat::nullopt_t> : public std::true_type {};
template <typename T>
struct has_time_point_value : public std::integral_constant<bool,
is_time_point<remove_optional_t<T>>::value or
is_time_point<remove_optional_t<value_type_of_t<T>>>::value>{};
#warning: Need to add float and unsigned traits?
template <typename L, typename R>
struct values_are_comparable
: public std::integral_constant<bool,
(has_blob_value<L>::value and has_blob_value<R>::value) or
(has_boolean_value<L>::value and has_boolean_value<R>::value) or
(has_day_point_value<L>::value and has_day_point_value<R>::value) or
(has_numeric_value<L>::value and has_numeric_value<R>::value) or
(has_text_value<L>::value and has_text_value<R>::value) or
(has_time_of_day_value<L>::value and has_time_of_day_value<R>::value) or
(has_time_point_value<L>::value and has_time_point_value<R>::value)>
{
};
// data types
struct blob;
template <typename T>
using is_blob_t = std::is_same<value_type_of_t<T>, blob>;
template <typename T>
using is_boolean_t = std::is_same<value_type_of_t<T>, boolean>;
struct day_point;
template <typename T>
using is_day_point_t = std::is_same<value_type_of_t<T>, day_point>;
struct floating_point;
template <typename T>
using is_floating_point_t = std::is_same<value_type_of_t<T>, floating_point>;
struct integral;
template <typename T>
using is_integral_t = std::is_same<value_type_of_t<T>, integral>;
struct unsigned_integral;
template <typename T>
using is_unsigned_integral_t = std::is_same<value_type_of_t<T>, unsigned_integral>;
struct text;
template <typename T>
using is_text_t = std::is_same<value_type_of_t<T>, text>;
struct time_of_day;
template <typename T>
using is_time_of_day_t = std::is_same<value_type_of_t<T>, time_of_day>;
struct time_point;
template <typename T>
using is_time_point_t = std::is_same<value_type_of_t<T>, time_point>;
// joined data type
template <typename T>
@ -220,9 +471,8 @@ namespace sqlpp
SQLPP_VALUE_TRAIT_GENERATOR(is_union_flag)
SQLPP_VALUE_TRAIT_GENERATOR(is_result_field)
SQLPP_VALUE_TRAIT_GENERATOR(must_not_insert)
SQLPP_VALUE_TRAIT_GENERATOR(must_not_update)
SQLPP_VALUE_TRAIT_GENERATOR(require_insert)
#warning Document loss of must_not_insert/update and require_insert (and new has_default)
SQLPP_VALUE_TRAIT_GENERATOR(has_default)
SQLPP_VALUE_TRAIT_GENERATOR(is_statement)
SQLPP_VALUE_TRAIT_GENERATOR(is_prepared_statement)
@ -277,7 +527,7 @@ namespace sqlpp
typename std::conditional<std::is_same<Database, void>::value, std::false_type, std::true_type>::type;
template <typename T>
using cpp_value_type_of = typename value_type_of<T>::_cpp_value_type;
using cpp_value_type_of_t = typename value_type_of_t<T>::_cpp_value_type;
namespace detail
{
@ -468,6 +718,12 @@ namespace sqlpp
template <typename T>
using name_of = typename T::_alias_t::_name_t;
template<typename T, typename = void>
struct has_name : public std::false_type {};
template<typename T>
struct has_name<T, typename T::_alias_t> : public std::true_type {};
template <typename ValueType, typename... Tags>
struct make_traits
{

View File

@ -89,23 +89,12 @@ namespace sqlpp
"set() contains assignments for columns from more than one table");
SQLPP_PORTABLE_STATIC_ASSERT(assert_update_set_count_args_t, "at least one assignment expression required in set()");
namespace detail
{
template <typename Assignment>
struct lhs_must_not_update
{
static constexpr auto value = detail::must_not_update_impl<typename lhs<Assignment>::type>::type::value;
};
} // namespace detail
template <typename... Assignments>
using check_update_set_t = static_combined_check_t<
static_check_t<logic::all_t<detail::is_assignment_impl<Assignments>::type::value...>::value,
assert_update_set_assignments_t>,
static_check_t<not detail::has_duplicates<typename lhs<Assignments>::type...>::value,
assert_update_set_no_duplicates_t>,
static_check_t<logic::none_t<detail::lhs_must_not_update<Assignments>::value...>::value,
assert_update_set_allowed_t>,
static_check_t<sizeof...(Assignments) == 0 or detail::make_joined_set_t<required_tables_of<
typename lhs<Assignments>::type>...>::size::value == 1,
assert_update_set_single_table_t>>;

View File

@ -33,16 +33,28 @@
namespace sqlpp
{
template <typename T>
struct value_t : public wrap_operand_t<T>, public expression_operators<value_t<T>, value_type_of<wrap_operand_t<T>>>
struct value_t
{
using _base_t = wrap_operand_t<T>;
using _base_t::_base_t;
template <typename alias_provider>
expression_alias_t<value_t, alias_provider> as(const alias_provider& /*unused*/) const
{
return {*this};
}
T _value;
};
template<typename T>
struct value_type_of<value_t<T>>
{
using type = value_type_of_t<T>;
};
template <typename T>
using check_value_arg = std::enable_if_t<not std::is_same<value_type_of_t<T>, no_value_t>::value and values_are_comparable<T, T>::value>;
template <typename T, typename = check_value_arg<T>>
auto value(T t) -> value_t<T>
{
static_assert(is_wrapped_value_t<wrap_operand_t<T>>::value,
"value() is to be called with non-sql-type like int, or string");
return {t};
return {std::move(t)};
}
} // namespace sqlpp

View File

@ -68,7 +68,7 @@ namespace sqlpp
}
template <typename T>
auto value_or_null(T t) -> value_or_null_t<value_type_of<wrap_operand_t<T>>>
auto value_or_null(T t) -> value_or_null_t<value_type_of_t<wrap_operand_t<T>>>
{
static_assert(is_wrapped_value_t<wrap_operand_t<T>>::value,
"value_or_null() is to be called with non-sql-type like int, or string or null");

View File

@ -32,5 +32,5 @@
namespace sqlpp
{
template <typename T>
using value_type_t = value_type_of<wrap_operand_t<T>>;
using value_type_t = value_type_of_t<wrap_operand_t<T>>;
} // namespace sqlpp

View File

@ -703,8 +703,8 @@ def createHeader():
)
print("You can disable this warning using -no-timestamp-warning")
noTimestampWarning = True
traitslist = ["sqlpp::" + columnType]
columnCanBeNull = not column.notNull
traitslist = ["::sqlpp::" + columnType]
columnCanBeNull = not column.notNull and not column.isPrimaryKey
print(" struct " + columnClass, file=header)
print(" {", file=header)
print(" struct _alias_t", file=header)
@ -716,7 +716,7 @@ def createHeader():
file=header,
)
print(
" using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;",
" using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;",
file=header,
)
print(" template<typename T>", file=header)
@ -735,21 +735,17 @@ def createHeader():
)
print(" };", file=header)
print(" };", file=header)
requireInsert = True
hasAutoValue = column.hasAutoValue or (autoId and sqlColumnName == "id")
if hasAutoValue:
traitslist.append("sqlpp::tag::must_not_insert")
traitslist.append("sqlpp::tag::must_not_update")
requireInsert = False
if not column.notNull and not column.isPrimaryKey:
traitslist.append("sqlpp::tag::can_be_null")
requireInsert = False
if column.hasDefaultValue:
requireInsert = False
if requireInsert:
traitslist.append("sqlpp::tag::require_insert")
if columnCanBeNull:
traitslist.append("::sqlpp::tag::can_be_null")
if column.hasDefaultValue or hasAutoValue or columnCanBeNull:
traitslist.append("::sqlpp::tag::has_default")
if columnCanBeNull:
print(" using value_type = ::sqlpp::compat::optional<::sqlpp::" + columnType + ">;", file=header)
else:
print(" using value_type = ::sqlpp::" + columnType + ";", file=header)
print(
" using _traits = sqlpp::make_traits<"
" using _traits = ::sqlpp::make_traits<"
+ ", ".join(traitslist)
+ ">;",
file=header,
@ -761,7 +757,7 @@ def createHeader():
print(
" struct "
+ tableClass
+ ": sqlpp::table_t<"
+ ": ::sqlpp::table_t<"
+ tableTemplateParameters
+ ">",
file=header,
@ -774,7 +770,7 @@ def createHeader():
file=header,
)
print(
" using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;",
" using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;",
file=header,
)
print(" template<typename T>", file=header)

View File

@ -99,20 +99,44 @@ int main()
}
// Select value and optional value.
sqlpp::value(7);
/*
for (const auto& row : db(select(sqlpp::value(7).as(sqlpp::alias::a),
sqlpp::value(sqlpp::compat::optional<int>(7)).as(sqlpp::alias::b))))
*/
{
/*
static_assert(is_same_type<decltype(row.a), int64_t>(), "");
static_assert(is_same_type<decltype(row.a), sqlpp::compat::optional<int64_t>>(), "");
static_assert(is_same_type<decltype(row.textN), sqlpp::compat::optional<sqlpp::compat::string_view>>(), "");
static_assert(is_same_type<decltype(row.b), sqlpp::compat::optional<sqlpp::compat::string_view>>(), "");
*/
static_assert(is_same_type<decltype(row.b), sqlpp::compat::optional<int64_t>>(), "");
}
static_assert(sqlpp::has_boolean_value<bool>::value, "");
static_assert(sqlpp::has_boolean_value<decltype(bar.boolNn)>::value, "");
static_assert(sqlpp::has_text_value<decltype(bar.textN)>::value, "");
static_assert(sqlpp::has_text_value<std::string>::value, "");
static_assert(sqlpp::has_numeric_value<int>::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
(bar.textN == "hansi").berti;
(-bar.intN).berti;
(bar.intN + 7).berti;
(bar.intN << 7).berti;
assign(bar.intN, sqlpp::compat::nullopt).berti;
#warning: This is not the real thing yet
bar.intN.as(bar.textN).berti;
in(bar.intN, 7, 8, 9).berti;
in(bar.intN, std::vector<int>{7, 8, 9}).berti;
max(bar.intN);
sqlpp::max(7);
#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.
#if 0

View File

@ -1,6 +1,6 @@
#pragma once
// generated by ./scripts/ddl2cpp -with-table-creation-helper tests/core/usage/sample.sql tests/core/usage/Sample test
// generated by ./scripts/ddl2cpp -auto-id tests/core/usage/sample.sql tests/core/usage/Sample test
#include <sqlpp11/table.h>
#include <sqlpp11/data_types.h>
@ -8,21 +8,6 @@
namespace test
{
template<typename Db>
void createTabFoo(Db& db)
{
db.execute(R"+++(DROP TABLE IF EXISTS tab_foo)+++");
db.execute(R"+++(CREATE TABLE tab_foo
(
id bigint AUTO_INCREMENT PRIMARY KEY,
text_nn_d varchar(255) NOT NULL DEFAULT "",
int_n bigint,
double_n double,
u_int_n bigint UNSIGNED,
blob_n BLOB
))+++");
}
namespace TabFoo_
{
struct Id
@ -30,7 +15,7 @@ namespace test
struct _alias_t
{
static constexpr const char _literal[] = "id";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -39,14 +24,15 @@ namespace test
const T& operator()() const { return id; }
};
};
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>;
using value_type = ::sqlpp::integer;
using _traits = ::sqlpp::make_traits<::sqlpp::integer, ::sqlpp::tag::has_default>;
};
struct TextNnD
{
struct _alias_t
{
static constexpr const char _literal[] = "text_nn_d";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -55,14 +41,15 @@ namespace test
const T& operator()() const { return textNnD; }
};
};
using _traits = sqlpp::make_traits<sqlpp::text>;
using value_type = ::sqlpp::text;
using _traits = ::sqlpp::make_traits<::sqlpp::text, ::sqlpp::tag::has_default>;
};
struct IntN
{
struct _alias_t
{
static constexpr const char _literal[] = "int_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -71,14 +58,15 @@ namespace test
const T& operator()() const { return intN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::can_be_null>;
using value_type = ::sqlpp::compat::optional<::sqlpp::integer>;
using _traits = ::sqlpp::make_traits<::sqlpp::integer, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
};
struct DoubleN
{
struct _alias_t
{
static constexpr const char _literal[] = "double_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -87,14 +75,15 @@ namespace test
const T& operator()() const { return doubleN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::floating_point, sqlpp::tag::can_be_null>;
using value_type = ::sqlpp::compat::optional<::sqlpp::floating_point>;
using _traits = ::sqlpp::make_traits<::sqlpp::floating_point, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
};
struct UIntN
{
struct _alias_t
{
static constexpr const char _literal[] = "u_int_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -103,14 +92,15 @@ namespace test
const T& operator()() const { return uIntN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::integer_unsigned, sqlpp::tag::can_be_null>;
using value_type = ::sqlpp::compat::optional<::sqlpp::integer_unsigned>;
using _traits = ::sqlpp::make_traits<::sqlpp::integer_unsigned, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
};
struct BlobN
{
struct _alias_t
{
static constexpr const char _literal[] = "blob_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -119,11 +109,12 @@ namespace test
const T& operator()() const { return blobN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::blob, sqlpp::tag::can_be_null>;
using value_type = ::sqlpp::compat::optional<::sqlpp::blob>;
using _traits = ::sqlpp::make_traits<::sqlpp::blob, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
};
} // namespace TabFoo_
struct TabFoo: sqlpp::table_t<TabFoo,
struct TabFoo: ::sqlpp::table_t<TabFoo,
TabFoo_::Id,
TabFoo_::TextNnD,
TabFoo_::IntN,
@ -134,7 +125,7 @@ namespace test
struct _alias_t
{
static constexpr const char _literal[] = "tab_foo";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -144,19 +135,6 @@ namespace test
};
};
};
template<typename Db>
void createTabBar(Db& db)
{
db.execute(R"+++(DROP TABLE IF EXISTS tab_bar)+++");
db.execute(R"+++(CREATE TABLE tab_bar
(
id bigint AUTO_INCREMENT PRIMARY KEY,
text_n varchar(255) NULL DEFAULT "",
bool_nn bool NOT NULL,
int_n int
))+++");
}
namespace TabBar_
{
struct Id
@ -164,7 +142,7 @@ namespace test
struct _alias_t
{
static constexpr const char _literal[] = "id";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -173,14 +151,15 @@ namespace test
const T& operator()() const { return id; }
};
};
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>;
using value_type = ::sqlpp::integer;
using _traits = ::sqlpp::make_traits<::sqlpp::integer, ::sqlpp::tag::has_default>;
};
struct TextN
{
struct _alias_t
{
static constexpr const char _literal[] = "text_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -189,14 +168,15 @@ namespace test
const T& operator()() const { return textN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::text, sqlpp::tag::can_be_null>;
using value_type = ::sqlpp::compat::optional<::sqlpp::text>;
using _traits = ::sqlpp::make_traits<::sqlpp::text, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
};
struct BoolNn
{
struct _alias_t
{
static constexpr const char _literal[] = "bool_nn";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -205,14 +185,15 @@ namespace test
const T& operator()() const { return boolNn; }
};
};
using _traits = sqlpp::make_traits<sqlpp::boolean, sqlpp::tag::require_insert>;
using value_type = ::sqlpp::boolean;
using _traits = ::sqlpp::make_traits<::sqlpp::boolean>;
};
struct IntN
{
struct _alias_t
{
static constexpr const char _literal[] = "int_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -221,11 +202,12 @@ namespace test
const T& operator()() const { return intN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::can_be_null>;
using value_type = ::sqlpp::compat::optional<::sqlpp::integer>;
using _traits = ::sqlpp::make_traits<::sqlpp::integer, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
};
} // namespace TabBar_
struct TabBar: sqlpp::table_t<TabBar,
struct TabBar: ::sqlpp::table_t<TabBar,
TabBar_::Id,
TabBar_::TextN,
TabBar_::BoolNn,
@ -234,7 +216,7 @@ namespace test
struct _alias_t
{
static constexpr const char _literal[] = "tab_bar";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -244,19 +226,6 @@ namespace test
};
};
};
template<typename Db>
void createTabDateTime(Db& db)
{
db.execute(R"+++(DROP TABLE IF EXISTS tab_date_time)+++");
db.execute(R"+++(CREATE TABLE tab_date_time
(
id bigint AUTO_INCREMENT PRIMARY KEY,
day_point_n date,
time_point_n datetime,
time_of_day_n time
))+++");
}
namespace TabDateTime_
{
struct Id
@ -264,7 +233,7 @@ namespace test
struct _alias_t
{
static constexpr const char _literal[] = "id";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -273,14 +242,15 @@ namespace test
const T& operator()() const { return id; }
};
};
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>;
using value_type = ::sqlpp::integer;
using _traits = ::sqlpp::make_traits<::sqlpp::integer, ::sqlpp::tag::has_default>;
};
struct DayPointN
{
struct _alias_t
{
static constexpr const char _literal[] = "day_point_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -289,14 +259,15 @@ namespace test
const T& operator()() const { return dayPointN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::day_point, sqlpp::tag::can_be_null>;
using value_type = ::sqlpp::compat::optional<::sqlpp::day_point>;
using _traits = ::sqlpp::make_traits<::sqlpp::day_point, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
};
struct TimePointN
{
struct _alias_t
{
static constexpr const char _literal[] = "time_point_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -305,14 +276,15 @@ namespace test
const T& operator()() const { return timePointN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::time_point, sqlpp::tag::can_be_null>;
using value_type = ::sqlpp::compat::optional<::sqlpp::time_point>;
using _traits = ::sqlpp::make_traits<::sqlpp::time_point, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
};
struct TimeOfDayN
{
struct _alias_t
{
static constexpr const char _literal[] = "time_of_day_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
@ -321,11 +293,12 @@ namespace test
const T& operator()() const { return timeOfDayN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::time_of_day, sqlpp::tag::can_be_null>;
using value_type = ::sqlpp::compat::optional<::sqlpp::time_of_day>;
using _traits = ::sqlpp::make_traits<::sqlpp::time_of_day, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
};
} // namespace TabDateTime_
struct TabDateTime: sqlpp::table_t<TabDateTime,
struct TabDateTime: ::sqlpp::table_t<TabDateTime,
TabDateTime_::Id,
TabDateTime_::DayPointN,
TabDateTime_::TimePointN,
@ -334,7 +307,7 @@ namespace test
struct _alias_t
{
static constexpr const char _literal[] = "tab_date_time";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
using _name_t = ::sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{