diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index f2801f98..7abda19f 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -40,7 +40,7 @@ namespace sqlpp { using _traits = make_traits; - using _nodes = detail::type_vector; + using _nodes = detail::type_vector; using _can_be_null = std::false_type; static_assert(is_noop::value or std::is_same::value, "count() used with flag other than 'distinct'"); @@ -98,6 +98,7 @@ namespace sqlpp template auto count(T t) -> count_t> { + static_assert(not contains_aggregate_function_t>::value, "count() cannot be used on an aggregate function"); static_assert(is_expression_t>::value, "count() requires an expression as argument"); return { t }; } @@ -105,6 +106,7 @@ namespace sqlpp template auto count(const distinct_t&, T t) -> count_t> { + static_assert(not contains_aggregate_function_t>::value, "count() cannot be used on an aggregate function"); static_assert(is_expression_t>::value, "count() requires an expression as argument"); return { t }; } diff --git a/include/sqlpp11/max.h b/include/sqlpp11/max.h index c497a56d..f2011988 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/max.h @@ -84,6 +84,7 @@ namespace sqlpp template auto max(T t) -> max_t> { + static_assert(not contains_aggregate_function_t>::value, "max() cannot be used on an aggregate function"); static_assert(is_expression_t>::value, "max() requires an expression as argument"); return { t }; } diff --git a/include/sqlpp11/min.h b/include/sqlpp11/min.h index 95649823..7f885c07 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/min.h @@ -84,6 +84,7 @@ namespace sqlpp template auto min(T t) -> min_t> { + static_assert(not contains_aggregate_function_t>::value, "min() cannot be used on an aggregate function"); static_assert(is_expression_t>::value, "min() requires an expression as argument"); return { t }; } diff --git a/test_constraints/CMakeLists.txt b/test_constraints/CMakeLists.txt index 2281b371..d36c597f 100644 --- a/test_constraints/CMakeLists.txt +++ b/test_constraints/CMakeLists.txt @@ -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")