Moved from-methods to from-classes

This commit is contained in:
rbock
2014-04-09 07:25:24 +02:00
parent 5e0c1cff48
commit 18d244dd9f
3 changed files with 36 additions and 29 deletions

View File

@@ -131,6 +131,7 @@ namespace sqlpp
>
struct select_t: public detail::select_helper_t<ColumnList, From>::_value_type::template expression_operators<select_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
FlagList::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
From::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
Where::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
GroupBy::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
Having::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
@@ -206,21 +207,6 @@ namespace sqlpp
return { *this, vendor::select_column_list_t<_database_t, Args...>{args...} };
}
template<typename... Args>
auto from(Args... args)
-> _policies_update_t<vendor::no_from_t, vendor::from_t<void, Args...>>
{
return { *this, vendor::from_t<void, Args...>{args...} };
}
template<typename... Args>
auto dynamic_from(Args... args)
-> _policies_update_t<vendor::no_from_t, vendor::from_t<_database_t, Args...>>
{
static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement");
return { *this, vendor::from_t<_database_t, Args...>{args...} };
}
// value adding methods
template<typename... Args>
void add_column(Args... args)
@@ -230,14 +216,6 @@ namespace sqlpp
return _column_list.add_column(*this, args...);
}
template<typename... Args>
void add_from(Args... args)
{
static_assert(is_from_t<From>::value, "cannot call add_from() before dynamic_from()");
static_assert(is_dynamic_t<From>::value, "cannot call add_using() before dynamic_from()");
return _from.add_from(*this, args...);
}
// PseudoTable
template<typename AliasProvider>
struct _pseudo_table_t

View File

@@ -64,13 +64,17 @@ namespace sqlpp
from_t& operator=(from_t&&) = default;
~from_t() = default;
template<typename Select, typename Table>
void add_from(const Select&, Table table)
template<typename Policies>
struct _methods_t
{
static_assert(_is_dynamic::value, "add_from can only be called for dynamic_from");
static_assert(is_table_t<Table>::value, "from arguments require to be tables or joins");
_dynamic_tables.emplace_back(table);
}
template<typename Table>
void add_from(Table table)
{
static_assert(is_table_t<Table>::value, "invalid expression argument in add_from()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated
return static_cast<typename Policies::_select_t*>(this)->_from._dynamic_tables.emplace_back(table);
}
};
std::tuple<Tables...> _tables;
vendor::interpretable_list_t<Database> _dynamic_tables;
@@ -79,6 +83,30 @@ namespace sqlpp
struct no_from_t
{
using _is_noop = std::true_type;
using _table_set = ::sqlpp::detail::type_set<>;
template<typename Policies>
struct _methods_t
{
using _database_t = typename Policies::_database_t;
template<typename T>
using _new_select_t = typename Policies::template _policies_update_t<no_from_t, T>;
template<typename... Args>
auto from(Args... args)
-> _new_select_t<from_t<void, Args...>>
{
return { *static_cast<typename Policies::_select_t*>(this), from_t<void, Args...>{args...} };
}
template<typename... Args>
auto dynamic_from(Args... args)
-> _new_select_t<from_t<_database_t, Args...>>
{
static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement");
return { *static_cast<typename Policies::_select_t*>(this), vendor::from_t<_database_t, Args...>{args...} };
}
};
};
// Interpreters

View File

@@ -70,6 +70,7 @@ namespace sqlpp
template<typename Expression>
void add_where(Expression expression)
{
static_assert(_is_dynamic::value, "add_where can only be called for dynamic_where");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in add_where()");
#warning: Need to dispatch to actual add method to prevent error messages from being generated
return static_cast<typename Policies::_select_t*>(this)->_where._dynamic_expressions.emplace_back(expression);