mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
More tests
This commit is contained in:
parent
a2f91c4a7c
commit
dc38a81a8c
@ -215,6 +215,7 @@ namespace sqlpp
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <typename Column>
|
||||
struct value_type_of<select_column_list_t<Column>> : public select_column_value_type_of<Column>
|
||||
{
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sqlpp11/core/wrong.h>
|
||||
#include <sqlpp11/core/logic.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
@ -35,6 +36,8 @@ namespace sqlpp
|
||||
template <typename... T>
|
||||
struct type_vector
|
||||
{
|
||||
template<typename X>
|
||||
using contains = std::integral_constant<bool, ::sqlpp::logic::any_t<std::is_same<T, X>::value...>::value>;
|
||||
};
|
||||
|
||||
template <typename... T>
|
||||
|
@ -51,6 +51,15 @@ namespace sqlpp
|
||||
Expr _expr;
|
||||
};
|
||||
|
||||
template <typename Expr>
|
||||
struct value_type_of<lower_t<Expr>> : public value_type_of<Expr> {};
|
||||
|
||||
template <typename Expr>
|
||||
struct nodes_of<lower_t<Expr>>
|
||||
{
|
||||
using type = detail::type_vector<Expr>;
|
||||
};
|
||||
|
||||
template <typename Context, typename Expr>
|
||||
auto to_sql_string(Context& context, const lower_t<Expr>& t) -> std::string
|
||||
{
|
||||
|
@ -51,6 +51,15 @@ namespace sqlpp
|
||||
Expr _expr;
|
||||
};
|
||||
|
||||
template <typename Expr>
|
||||
struct value_type_of<upper_t<Expr>> : public value_type_of<Expr> {};
|
||||
|
||||
template <typename Expr>
|
||||
struct nodes_of<upper_t<Expr>>
|
||||
{
|
||||
using type = detail::type_vector<Expr>;
|
||||
};
|
||||
|
||||
template <typename Context, typename Expr>
|
||||
auto to_sql_string(Context& context, const upper_t<Expr>& t) -> std::string
|
||||
{
|
||||
|
@ -44,20 +44,22 @@ namespace sqlpp
|
||||
{
|
||||
};
|
||||
|
||||
// Finds group_by expressions.
|
||||
// Finds group_by expression.
|
||||
// @GroupByExpressions: type_vector
|
||||
template <typename T, typename GroupByExpressions>
|
||||
struct contains_aggregate_expressions
|
||||
: public std::integral_constant<bool, contains_aggregate_expressions<nodes_of_t<T>, GroupByExpressions>::value>
|
||||
template <typename GroupByExpressions, typename T>
|
||||
struct contains_aggregate_expression
|
||||
: public std::integral_constant<bool,
|
||||
GroupByExpressions::template contains<T>::value or
|
||||
contains_aggregate_expression<GroupByExpressions, nodes_of_t<T>>::value>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename... T, typename GroupByExpressions>
|
||||
struct contains_aggregate_expressions<detail::type_vector<T...>, GroupByExpressions>
|
||||
template <typename GroupByExpressions, typename... T>
|
||||
struct contains_aggregate_expression<GroupByExpressions, detail::type_vector<T...>>
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
logic::any_t<(GroupByExpressions::template contains<T>::value or
|
||||
contains_aggregate_expressions<T, GroupByExpressions>::value)...>::value>
|
||||
contains_aggregate_expression<GroupByExpressions, T>::value)...>::value>
|
||||
{
|
||||
};
|
||||
|
||||
|
@ -26,37 +26,187 @@
|
||||
#include "Sample.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
SQLPP_ALIAS_PROVIDER(cheese);
|
||||
|
||||
void test_contains_aggregate_function()
|
||||
{
|
||||
auto v_not_null = sqlpp::value(17);
|
||||
auto v = sqlpp::value(17);
|
||||
auto t = sqlpp::value("");
|
||||
auto col_int = test::TabFoo{}.id;
|
||||
auto col_txt = test::TabFoo{}.textNnD;
|
||||
|
||||
#warning: Need to test contains_aggregate_function
|
||||
// Values are aggregate neutral and therefore considered neither aggregate and non-aggregate context.
|
||||
static_assert(not sqlpp::contains_aggregate_function<decltype(v)>::value, "");
|
||||
static_assert(not sqlpp::contains_aggregate_function<decltype(v + v)>::value, "");
|
||||
|
||||
// Columns are non-aggregates.
|
||||
static_assert(not sqlpp::contains_aggregate_function<decltype(col_int)>::value, "");
|
||||
static_assert(not sqlpp::contains_aggregate_function<decltype(col_int + v)>::value, "");
|
||||
|
||||
// Normal functions of values or non-aggregates do not contain aggregate functions.
|
||||
static_assert(not sqlpp::contains_aggregate_function<decltype(trim(t))>::value, "");
|
||||
static_assert(not sqlpp::contains_aggregate_function<decltype(trim(col_txt))>::value, "");
|
||||
|
||||
// Aggregate functions of non-aggregates and values contain aggregate functions.
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(avg(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(count(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(min(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(max(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(sum(v))>::value, "");
|
||||
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(avg(col_int))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(count(col_int))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(min(col_int))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(max(col_int))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(sum(col_int))>::value, "");
|
||||
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(avg(col_int) + v)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(count(col_int) + v)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(min(col_int) + v)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(max(col_int) + v)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(sum(col_int) + v)>::value, "");
|
||||
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(trim(max(col_txt)))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(max(trim(col_txt)))>::value, "");
|
||||
|
||||
// Expressions of aggregate functions and non-aggregates contain aggregate functions.
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(avg(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(count(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(min(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(max(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(sum(col_int) + col_int)>::value, "");
|
||||
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(trim(upper(lower(max(col_txt)))) + trim(col_txt))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(max(trim(col_txt)) + trim(col_txt))>::value, "");
|
||||
|
||||
// Clauses expose non-aggregates (probably irrelevant)
|
||||
static_assert(not sqlpp::contains_aggregate_function<decltype(where(col_int > v))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_function<decltype(select_columns(max(col_int), v.as(cheese), col_int))>::value, "");
|
||||
}
|
||||
|
||||
void test_contains_aggregate_expression()
|
||||
{
|
||||
auto v_not_null = sqlpp::value(17);
|
||||
|
||||
#warning: Need to test contains_aggregate_expression
|
||||
auto v = sqlpp::value(17);
|
||||
auto t = sqlpp::value("");
|
||||
auto col_int = test::TabFoo{}.id;
|
||||
auto col_txt = test::TabFoo{}.textNnD;
|
||||
|
||||
using known_aggregates = sqlpp::detail::type_vector<decltype(v), decltype(col_txt), decltype(col_int + v)>;
|
||||
using unknown = sqlpp::detail::type_vector<>;
|
||||
|
||||
// ...
|
||||
static_assert(sqlpp::contains_aggregate_expression<known_aggregates, decltype(v)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<known_aggregates, decltype(v + v)>::value, "");
|
||||
|
||||
// ...
|
||||
static_assert(not sqlpp::contains_aggregate_expression<unknown, decltype(v)>::value, "");
|
||||
static_assert(not sqlpp::contains_aggregate_expression<unknown, decltype(v + v)>::value, "");
|
||||
|
||||
#warning: activate
|
||||
#if 0
|
||||
// Columns are non-aggregates.
|
||||
static_assert(not sqlpp::contains_aggregate_expression<decltype(col_int)>::value, "");
|
||||
static_assert(not sqlpp::contains_aggregate_expression<decltype(col_int + v)>::value, "");
|
||||
|
||||
// Normal expressions of values or non-aggregates do not contain aggregate functions.
|
||||
static_assert(not sqlpp::contains_aggregate_expression<decltype(trim(t))>::value, "");
|
||||
static_assert(not sqlpp::contains_aggregate_expression<decltype(trim(col_txt))>::value, "");
|
||||
|
||||
// Aggregate expressions of non-aggregates contain aggregate functions.
|
||||
static_assert(not sqlpp::contains_aggregate_expressions<decltype(avg(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_aggregate_expressions<decltype(count(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_aggregate_expressions<decltype(min(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_aggregate_expressions<decltype(max(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_aggregate_expressions<decltype(sum(v))>::value, "");
|
||||
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(avg(col_int))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(count(col_int))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(min(col_int))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(max(col_int))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(sum(col_int))>::value, "");
|
||||
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(avg(col_int) + v)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(count(col_int) + v)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(min(col_int) + v)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(max(col_int) + v)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(sum(col_int) + v)>::value, "");
|
||||
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(trim(max(col_txt)))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(max(trim(col_txt)))>::value, "");
|
||||
|
||||
// Expressions of aggregate expressions and non-aggregates contain aggregate functions.
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(avg(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(count(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(min(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(max(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(sum(col_int) + col_int)>::value, "");
|
||||
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(trim(upper(lower(max(col_txt)))) + trim(col_txt))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(max(trim(col_txt)) + trim(col_txt))>::value, "");
|
||||
|
||||
// Clauses expose non-aggregates (probably irrelevant)
|
||||
static_assert(not sqlpp::contains_aggregate_expression<decltype(where(col_int > v))>::value, "");
|
||||
static_assert(sqlpp::contains_aggregate_expression<decltype(select_columns(max(col_int), v.as(cheese), col_int))>::value, "");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void test_contains_non_aggregate()
|
||||
{
|
||||
auto v = sqlpp::value(17);
|
||||
auto col = test::TabFoo{}.id;
|
||||
auto t = sqlpp::value("");
|
||||
auto col_int = test::TabFoo{}.id;
|
||||
auto col_txt = test::TabFoo{}.textNnD;
|
||||
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(col)>::value, "");
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(col + v)>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(avg(col) + v)>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(count(col) + v)>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(min(col) + v)>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(max(col) + v)>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(sum(col) + v)>::value, "");
|
||||
#warning: lets test some functions, too
|
||||
#warning: lets test some clauses, too
|
||||
// Values are aggregate neutral and therefore considered neither aggregate and non-aggregate context.
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(v)>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(v + v)>::value, "");
|
||||
|
||||
// Columns are non-aggregates.
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(col_int + v)>::value, "");
|
||||
|
||||
// Functions can contain non-aggregates.
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(trim(t))>::value, "");
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(trim(col_txt))>::value, "");
|
||||
|
||||
// Aggregate functions of non-aggregates and values are aggregate functions.
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(avg(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(count(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(min(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(max(v))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(sum(v))>::value, "");
|
||||
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(avg(col_int))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(count(col_int))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(min(col_int))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(max(col_int))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(sum(col_int))>::value, "");
|
||||
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(avg(col_int) + v)>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(count(col_int) + v)>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(min(col_int) + v)>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(max(col_int) + v)>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(sum(col_int) + v)>::value, "");
|
||||
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(trim(max(col_txt)))>::value, "");
|
||||
static_assert(not sqlpp::contains_non_aggregate<decltype(max(trim(col_txt)))>::value, "");
|
||||
|
||||
// Expressions of aggregate functions and non-aggregates contain non-aggregates.
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(avg(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(count(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(min(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(max(col_int) + col_int)>::value, "");
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(sum(col_int) + col_int)>::value, "");
|
||||
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(trim(max(col_txt)) + trim(col_txt))>::value, "");
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(max(trim(col_txt)) + trim(col_txt))>::value, "");
|
||||
|
||||
// Clauses expose non-aggregates (probably irrelevant)
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(where(col_int > v))>::value, "");
|
||||
static_assert(sqlpp::contains_non_aggregate<decltype(select_columns(max(col_int), v.as(cheese), col_int))>::value, "");
|
||||
}
|
||||
|
||||
int main()
|
||||
|
Loading…
Reference in New Issue
Block a user