0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Started to move statement-specific methods into the result provider classes

First method is: select_t::as()
This commit is contained in:
rbock 2014-05-27 11:20:03 +02:00
parent 45ff16600f
commit a5457e93f7
4 changed files with 40 additions and 17 deletions

View File

@ -95,6 +95,10 @@ namespace sqlpp
using _result_type_provider = detail::get_last_if<is_return_value_t, vendor::no_select_column_list_t, Policies...>; using _result_type_provider = detail::get_last_if<is_return_value_t, vendor::no_select_column_list_t, Policies...>;
struct _result_methods_t: public _result_type_provider::template _result_methods_t<select_policies_t>
{};
// A select can be used as a pseudo table if // A select can be used as a pseudo table if
// - at least one column is selected // - at least one column is selected
// - the select is complete (leaks no tables) // - the select is complete (leaks no tables)
@ -135,6 +139,7 @@ namespace sqlpp
struct select_t: struct select_t:
public Policies..., public Policies...,
public detail::select_policies_t<Db, Policies...>::_value_type::template expression_operators<select_t<Db, Policies...>>, public detail::select_policies_t<Db, Policies...>::_value_type::template expression_operators<select_t<Db, Policies...>>,
public detail::select_policies_t<Db, Policies...>::_result_methods_t,
public detail::select_policies_t<Db, Policies...>::_methods_t public detail::select_policies_t<Db, Policies...>::_methods_t
{ {
using _policies_t = typename detail::select_policies_t<Db, Policies...>; using _policies_t = typename detail::select_policies_t<Db, Policies...>;
@ -174,21 +179,6 @@ namespace sqlpp
~select_t() = default; ~select_t() = default;
// PseudoTable // PseudoTable
template<typename AliasProvider>
struct _pseudo_table_t
{
using table = typename _result_type_provider::template _pseudo_table_t<select_t>;
using alias = typename table::template _alias_t<AliasProvider>;
};
template<typename AliasProvider>
typename _pseudo_table_t<AliasProvider>::alias as(const AliasProvider& aliasProvider) const
{
static_assert(_policies_t::_can_be_used_as_table::value, "select cannot be used as table, incomplete from()");
return typename _pseudo_table_t<AliasProvider>::table(
*this).as(aliasProvider);
}
const _dynamic_names_t& get_dynamic_names() const const _dynamic_names_t& get_dynamic_names() const
{ {
return static_cast<const _result_type_provider&>(*this)._dynamic_columns._dynamic_expression_names; return static_cast<const _result_type_provider&>(*this)._dynamic_columns._dynamic_expression_names;

View File

@ -222,6 +222,32 @@ namespace sqlpp
void _add_column_impl(NamedExpression namedExpression, const std::false_type&); void _add_column_impl(NamedExpression namedExpression, const std::false_type&);
}; };
template<typename Policies>
struct _result_methods_t
{
using _statement_t = typename Policies::_statement_t;
template<typename AliasProvider>
struct _deferred_table_t
{
using table = _pseudo_table_t<_statement_t>;
using alias = typename _pseudo_table_t<_statement_t>::template _alias_t<AliasProvider>;
};
template<typename AliasProvider>
using _table_t = typename _deferred_table_t<AliasProvider>::table;
template<typename AliasProvider>
using _alias_t = typename _deferred_table_t<AliasProvider>::alias;
template<typename AliasProvider>
_alias_t<AliasProvider> as(const AliasProvider& aliasProvider) const
{
static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables");
return _table_t<AliasProvider>(static_cast<const _statement_t&>(*this)).as(aliasProvider);
}
};
const select_column_list_t& _column_list() const { return *this; } const select_column_list_t& _column_list() const { return *this; }
std::tuple<Columns...> _columns; std::tuple<Columns...> _columns;
@ -277,6 +303,10 @@ namespace sqlpp
return { *static_cast<typename Policies::_statement_t*>(this), ::sqlpp::detail::make_select_column_list_t<_database_t, Args...>{std::tuple_cat(::sqlpp::detail::as_tuple<Args>::_(args)...)} }; return { *static_cast<typename Policies::_statement_t*>(this), ::sqlpp::detail::make_select_column_list_t<_database_t, Args...>{std::tuple_cat(::sqlpp::detail::as_tuple<Args>::_(args)...)} };
} }
}; };
template<typename Policies>
struct _result_methods_t
{};
}; };
// Interpreters // Interpreters

View File

@ -10,8 +10,8 @@ endmacro ()
#build_and_run(InsertTest) #build_and_run(InsertTest)
#build_and_run(RemoveTest) #build_and_run(RemoveTest)
#build_and_run(UpdateTest) #build_and_run(UpdateTest)
#build_and_run(SelectTest) build_and_run(SelectTest)
build_and_run(SelectTypeTest) #build_and_run(SelectTypeTest)
#build_and_run(FunctionTest) #build_and_run(FunctionTest)
#build_and_run(PreparedTest) #build_and_run(PreparedTest)

View File

@ -83,5 +83,8 @@ int main()
int64_t a = row.alpha; int64_t a = row.alpha;
} }
auto X = select(all_of(t)).from(t).as(t.alpha);
return 0; return 0;
} }