From 40d03f5312a72d48d7ace4454a5adbf193828dc8 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sat, 17 Aug 2024 08:48:33 +0200 Subject: [PATCH] More tests and fixed names for aggregates --- include/sqlpp11/core/aggregate_function/avg.h | 4 +- .../sqlpp11/core/aggregate_function/count.h | 4 +- include/sqlpp11/core/aggregate_function/max.h | 4 +- include/sqlpp11/core/aggregate_function/min.h | 4 +- include/sqlpp11/core/aggregate_function/sum.h | 4 +- .../sqlpp11/core/clause/select_column_list.h | 2 +- tests/core/types/clause/select_columns.cpp | 45 ++++++++++++++++--- tests/core/types/result_row.cpp | 2 +- 8 files changed, 51 insertions(+), 18 deletions(-) diff --git a/include/sqlpp11/core/aggregate_function/avg.h b/include/sqlpp11/core/aggregate_function/avg.h index 4a993724..4d860a88 100644 --- a/include/sqlpp11/core/aggregate_function/avg.h +++ b/include/sqlpp11/core/aggregate_function/avg.h @@ -37,7 +37,7 @@ namespace sqlpp { namespace alias { - SQLPP_ALIAS_PROVIDER(avg); + SQLPP_ALIAS_PROVIDER(_avg); } template @@ -68,7 +68,7 @@ namespace sqlpp }; template - struct name_tag_of>: public name_tag_of + struct name_tag_of>: public name_tag_of { }; diff --git a/include/sqlpp11/core/aggregate_function/count.h b/include/sqlpp11/core/aggregate_function/count.h index 7577fc5b..df79eac5 100644 --- a/include/sqlpp11/core/aggregate_function/count.h +++ b/include/sqlpp11/core/aggregate_function/count.h @@ -37,7 +37,7 @@ namespace sqlpp { namespace alias { - SQLPP_ALIAS_PROVIDER(count); + SQLPP_ALIAS_PROVIDER(_count); } template @@ -68,7 +68,7 @@ namespace sqlpp }; template - struct name_tag_of>: public name_tag_of + struct name_tag_of>: public name_tag_of { }; diff --git a/include/sqlpp11/core/aggregate_function/max.h b/include/sqlpp11/core/aggregate_function/max.h index d4f53286..5c4e6756 100644 --- a/include/sqlpp11/core/aggregate_function/max.h +++ b/include/sqlpp11/core/aggregate_function/max.h @@ -37,7 +37,7 @@ namespace sqlpp { namespace alias { - SQLPP_ALIAS_PROVIDER(max); + SQLPP_ALIAS_PROVIDER(_max); } template @@ -67,7 +67,7 @@ namespace sqlpp }; template - struct name_tag_of>: public name_tag_of + struct name_tag_of>: public name_tag_of { }; diff --git a/include/sqlpp11/core/aggregate_function/min.h b/include/sqlpp11/core/aggregate_function/min.h index eb06ca56..2c3e3596 100644 --- a/include/sqlpp11/core/aggregate_function/min.h +++ b/include/sqlpp11/core/aggregate_function/min.h @@ -37,7 +37,7 @@ namespace sqlpp { namespace alias { - SQLPP_ALIAS_PROVIDER(min); + SQLPP_ALIAS_PROVIDER(_min); } template @@ -67,7 +67,7 @@ namespace sqlpp }; template - struct name_tag_of>: public name_tag_of + struct name_tag_of>: public name_tag_of { }; diff --git a/include/sqlpp11/core/aggregate_function/sum.h b/include/sqlpp11/core/aggregate_function/sum.h index 45c1daf7..38020268 100644 --- a/include/sqlpp11/core/aggregate_function/sum.h +++ b/include/sqlpp11/core/aggregate_function/sum.h @@ -37,7 +37,7 @@ namespace sqlpp { namespace alias { - SQLPP_ALIAS_PROVIDER(sum); + SQLPP_ALIAS_PROVIDER(_sum); } template @@ -67,7 +67,7 @@ namespace sqlpp }; template - struct name_tag_of>: public name_tag_of + struct name_tag_of>: public name_tag_of { }; diff --git a/include/sqlpp11/core/clause/select_column_list.h b/include/sqlpp11/core/clause/select_column_list.h index 6f10a0ad..ee7372db 100644 --- a/include/sqlpp11/core/clause/select_column_list.h +++ b/include/sqlpp11/core/clause/select_column_list.h @@ -223,7 +223,7 @@ namespace sqlpp }; template - struct name_tag_of> : public name_tag_of + struct name_tag_of> : public select_column_name_tag_of { }; diff --git a/tests/core/types/clause/select_columns.cpp b/tests/core/types/clause/select_columns.cpp index d7b744ab..16b55cd0 100644 --- a/tests/core/types/clause/select_columns.cpp +++ b/tests/core/types/clause/select_columns.cpp @@ -29,18 +29,51 @@ namespace { SQLPP_ALIAS_PROVIDER(cheese); + + template + struct clause_of; + + template + struct clause_of> + { + using type = T; + }; + template + using clause_of_t = typename clause_of::type; } void test_select_columns() { - auto v = sqlpp::value(17); + auto v = sqlpp::value("text"); auto col_int = test::TabFoo{}.id; - auto col_txt = test::TabFoo{}.textNnD; - select_columns(col_int); - select_columns(dynamic(true, col_int)); - select_columns(as(declare_group_by_column(v), cheese)); - select_columns(dynamic(true, declare_group_by_column(v)).as(cheese)); + // Single column + { + using T = clause_of_t; + static_assert(std::is_same, test::TabFoo_::Id::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::integral>::value, ""); + } + + // Single dynamic column + { + using T = clause_of_t; + static_assert(std::is_same, test::TabFoo_::Id::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::optional>::value, ""); + } + + // Single declared group by column + { + using T = clause_of_t; + static_assert(std::is_same, cheese_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::text>::value, ""); + } + + // Single dynamic declared group by column + { + using T = clause_of_t; + static_assert(std::is_same, cheese_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::optional>::value, ""); + } #warning: add actual tests here diff --git a/tests/core/types/result_row.cpp b/tests/core/types/result_row.cpp index 41cc8d6b..c49fcac8 100644 --- a/tests/core/types/result_row.cpp +++ b/tests/core/types/result_row.cpp @@ -56,7 +56,7 @@ void test_result_row(Value v) auto v_not_null = sqlpp::value(v).as(r_not_null); const auto v_maybe_null = sqlpp::value(::sqlpp::make_optional(v)).as(r_maybe_null); - // Optional selectable values. + // Dynamically selectable values. const auto v_opt_not_null = dynamic(true, sqlpp::value(v)).as(r_opt_not_null); const auto v_opt_maybe_null = dynamic(true, sqlpp::value(::sqlpp::make_optional(v))).as(r_opt_maybe_null);