0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Added more tests and fixed dynamic free clauses

This commit is contained in:
rbock 2016-04-16 09:51:13 +02:00
parent be7403c1e7
commit 914ecae7c2
3 changed files with 14 additions and 3 deletions

View File

@ -314,9 +314,9 @@ namespace sqlpp
template <typename Database, typename T> template <typename Database, typename T>
auto dynamic_having(const Database&, T&& t) auto dynamic_having(const Database&, T&& t)
-> decltype(statement_t<void, no_having_t>().dynamic_having(std::forward<T>(t))) -> decltype(statement_t<Database, no_having_t>().dynamic_having(std::forward<T>(t)))
{ {
return statement_t<void, no_having_t>().dynamic_having(std::forward<T>(t)); return statement_t<Database, no_having_t>().dynamic_having(std::forward<T>(t));
} }
} }

View File

@ -449,7 +449,7 @@ namespace sqlpp
template <typename Database, typename... T> template <typename Database, typename... T>
auto dynamic_select_columns(const Database&, T&&... t) auto dynamic_select_columns(const Database&, T&&... t)
-> decltype(statement_t<void, no_select_column_list_t>().dynamic_columns(std::forward<T>(t)...)) -> decltype(statement_t<Database, no_select_column_list_t>().dynamic_columns(std::forward<T>(t)...))
{ {
return statement_t<Database, no_select_column_list_t>().dynamic_columns(std::forward<T>(t)...); return statement_t<Database, no_select_column_list_t>().dynamic_columns(std::forward<T>(t)...);
} }

View File

@ -33,6 +33,7 @@ int CustomQuery(int, char* [])
{ {
const auto foo = test::TabFoo{}; const auto foo = test::TabFoo{};
const auto bar = test::TabBar{}; const auto bar = test::TabBar{};
auto db = MockDb{};
// Unconditionally // Unconditionally
compare(__LINE__, custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega), from(foo), compare(__LINE__, custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega), from(foo),
@ -48,5 +49,15 @@ int CustomQuery(int, char* [])
"(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega ASC " "(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega ASC "
"LIMIT 10 OFFSET 100"); "LIMIT 10 OFFSET 100");
// A full select statement made individual clauses
compare(
__LINE__,
custom_query(sqlpp::select(), dynamic_select_flags(db, sqlpp::distinct), dynamic_select_columns(db, foo.omega),
dynamic_from(db, foo.join(bar).on(foo.omega == bar.alpha)), dynamic_where(db, bar.alpha > 17),
dynamic_group_by(db, foo.omega), dynamic_having(db, avg(bar.alpha) > 19),
dynamic_order_by(db, foo.omega.asc()), sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)),
"SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE "
"(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega ASC ");
return 0; return 0;
} }