0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Added missing checks for aggregate functions

This commit is contained in:
rbock 2015-02-24 08:02:14 +01:00
parent c9401d4b00
commit 57ceefbd0c
4 changed files with 7 additions and 3 deletions

View File

@ -40,7 +40,7 @@ namespace sqlpp
{
using _traits = make_traits<integral, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
using _can_be_null = std::false_type;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "count() used with flag other than 'distinct'");
@ -98,6 +98,7 @@ 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 };
}
@ -105,6 +106,7 @@ 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 };
}

View File

@ -84,6 +84,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 an expression as argument");
return { t };
}

View File

@ -84,6 +84,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 an expression as argument");
return { t };
}

View File

@ -24,8 +24,8 @@ function(test_constraint name pattern)
endfunction(test_constraint)
test_constraint(count_of_count "requires an expression as argument")
test_constraint(max_of_max "requires an expression as argument")
test_constraint(count_of_count "count() cannot be used on an aggregate function")
test_constraint(max_of_max "max() cannot be used on an aggregate function")
test_constraint(no_conversion_operator_if_null_not_trivial "int i = row.alpha")
test_constraint(require_insert "required column is missing")
test_constraint(must_not_insert "one assignment is prohibited")