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

First with-query compiles

This commit is contained in:
rbock 2015-01-29 19:17:24 +01:00
parent da9ca73788
commit 2adf529445
4 changed files with 40 additions and 10 deletions

View File

@ -71,6 +71,19 @@ namespace sqlpp
template<typename AliasProvider, typename Statement, typename... ColumnSpecs>
struct cte_t: public member_t<ColumnSpecs, column_t<AliasProvider, ColumnSpecs>>... // FIXME
{
using _traits = make_traits<no_value_t, tag::is_cte, tag::is_table>;
struct _recursive_traits
{
using _required_ctes = required_ctes_of<Statement>;
using _provided_ctes = detail::make_type_set_t<AliasProvider>;
using _required_tables = required_tables_of<Statement>;
using _provided_tables = detail::type_set<AliasProvider>;
using _provided_outer_tables = detail::type_set<>;
using _extra_tables = detail::type_set<>;
using _parameters = parameters_of<Statement>;
using _tags = detail::type_set<>;
};
using _alias_t = typename AliasProvider::_alias_t;
cte_t(Statement statement): _statement(statement){}

View File

@ -126,6 +126,8 @@ namespace sqlpp
SQLPP_VALUE_TRAIT_GENERATOR(trivial_value_is_null);
SQLPP_VALUE_TRAIT_GENERATOR(null_is_trivial_value);
SQLPP_VALUE_TRAIT_GENERATOR(is_with);
SQLPP_VALUE_TRAIT_GENERATOR(is_cte);
SQLPP_VALUE_TRAIT_GENERATOR(is_statement);
SQLPP_VALUE_TRAIT_GENERATOR(is_prepared_statement);
SQLPP_VALUE_TRAIT_GENERATOR(is_noop);

View File

@ -56,13 +56,12 @@ namespace sqlpp
~with_data_t() = default;
std::tuple<Expressions...> _expressions;
interpretable_list_t<Database> _dynamic_expressions;
};
template<typename Database, typename... Expressions>
struct with_t
{
using _traits = make_traits<no_value_t, tag::is_where>;
using _traits = make_traits<no_value_t, tag::is_with>;
using _recursive_traits = make_recursive_traits<Expressions...>;
using _is_dynamic = is_database<Database>;
@ -84,14 +83,14 @@ namespace sqlpp
{
using _data_t = with_data_t<Database, Expressions...>;
_impl_t<Policies> where;
_impl_t<Policies>& operator()() { return where; }
const _impl_t<Policies>& operator()() const { return where; }
_impl_t<Policies> with;
_impl_t<Policies>& operator()() { return with; }
const _impl_t<Policies>& operator()() const { return with; }
template<typename T>
static auto _get_member(T t) -> decltype(t.where)
static auto _get_member(T t) -> decltype(t.with)
{
return t.where;
return t.with;
}
#warning: Need real checks here
@ -102,7 +101,7 @@ namespace sqlpp
struct no_with_t
{
using _traits = make_traits<no_value_t, tag::is_where>;
using _traits = make_traits<no_value_t, tag::is_with>;
using _recursive_traits = make_recursive_traits<>;
// Data
@ -143,13 +142,28 @@ namespace sqlpp
template<typename Statement>
auto operator()(Statement statement)
-> new_statement_t<true, Statement, no_with_t, with_t<Expressions...>>
-> new_statement_t<true, typename Statement::_policies_t, no_with_t, with_t<Database, Expressions...>>
{
// FIXME need checks here, e.g. if there is recursion
return { statement, _data };
}
};
// Interpreters
template<typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, with_data_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = with_data_t<Database, Expressions...>;
static Context& _(const T& t, Context& context)
{
context << " WITH ";
interpret_tuple(t._expressions, ',', context);
return context;
}
};
template<typename... Expressions>
auto with(Expressions... cte)
-> blank_with_t<void, Expressions...>

View File

@ -37,7 +37,8 @@ int main()
const auto t = test::TabBar{};
auto x = cte(sqlpp::x).as(select(all_of(t)).from(t));
// to be done
db(with(x)(select(x.alpha).from(x).where(true)));
return 0;
}