mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-01-09 14:42:17 -06:00
Ensure that expression do not contain aggregate functions
This commit is contained in:
@@ -51,7 +51,6 @@ namespace sqlpp
|
||||
|
||||
|
||||
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "count() used with flag other than 'distinct'");
|
||||
static_assert(is_expression_t<Expr>::value, "count() requires a sql expression as argument");
|
||||
|
||||
struct _name_t
|
||||
{
|
||||
@@ -100,7 +99,6 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
auto count(T t) -> count_t<noop, wrap_operand_t<T>>
|
||||
{
|
||||
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "count() cannot be used on an aggregate function");
|
||||
static_assert(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
|
||||
return { t };
|
||||
}
|
||||
@@ -108,7 +106,6 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
auto count(const distinct_t&, T t) -> count_t<distinct_t, wrap_operand_t<T>>
|
||||
{
|
||||
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "count() cannot be used on an aggregate function");
|
||||
static_assert(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
|
||||
return { t };
|
||||
}
|
||||
|
||||
@@ -39,8 +39,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_named_expression>;
|
||||
using _recursive_traits = make_recursive_traits<Expr, aggregate_function>;
|
||||
|
||||
static_assert(is_expression_t<Expr>::value, "max() requires a value expression as argument");
|
||||
|
||||
struct _name_t
|
||||
{
|
||||
static constexpr const char* _get_name() { return "MAX"; }
|
||||
@@ -83,8 +81,7 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
auto max(T t) -> max_t<wrap_operand_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 a value expression as argument");
|
||||
static_assert(is_expression_t<wrap_operand_t<T>>::value, "max() requires an expression as argument");
|
||||
return { t };
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_named_expression>;
|
||||
using _recursive_traits = make_recursive_traits<Expr, aggregate_function>;
|
||||
|
||||
static_assert(is_expression_t<Expr>::value, "min() requires a value expression as argument");
|
||||
|
||||
struct _name_t
|
||||
{
|
||||
static constexpr const char* _get_name() { return "MIN"; }
|
||||
@@ -83,8 +81,7 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
auto min(T t) -> min_t<wrap_operand_t<T>>
|
||||
{
|
||||
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "min() cannot be used on an aggregate function");
|
||||
static_assert(is_expression_t<wrap_operand_t<T>>::value, "min() requires a value expression as argument");
|
||||
static_assert(is_expression_t<wrap_operand_t<T>>::value, "min() requires an expression as argument");
|
||||
return { t };
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,23 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using column_spec_can_be_null_t = typename detail::column_spec_can_be_null_impl<T>::type;
|
||||
|
||||
namespace tag
|
||||
{
|
||||
struct is_expression{};
|
||||
};
|
||||
namespace detail
|
||||
{
|
||||
template<typename T, typename Enable = void>
|
||||
struct is_expression_impl { using type = std::false_type; };
|
||||
template<typename T>
|
||||
struct is_expression_impl<T, typename std::enable_if<
|
||||
detail::is_element_of<tag::is_expression, typename T::_traits::_tags>::value
|
||||
and not detail::is_element_of<tag::contains_aggregate_function, typename T::_recursive_traits::_tags>::value
|
||||
>::type> { using type = std::true_type; };
|
||||
}
|
||||
template<typename T>
|
||||
using is_expression_t = typename detail::is_expression_impl<T>::type;
|
||||
|
||||
#define SQLPP_VALUE_TRAIT_GENERATOR(name) \
|
||||
namespace tag\
|
||||
{\
|
||||
@@ -94,7 +111,6 @@ namespace sqlpp
|
||||
detail::is_element_of<tag::is_floating_point, typename T::_traits::_tags>::value>;
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(is_text);
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(is_wrapped_value);
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(is_expression);
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(is_named_expression);
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(is_multi_expression);
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(is_alias);
|
||||
|
||||
Reference in New Issue
Block a user