mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Added policies into members
What a fight...
This commit is contained in:
parent
408e96af4a
commit
98bb9a7db7
@ -42,7 +42,7 @@ namespace sqlpp
|
||||
template<typename Target, typename Statement, typename Term>
|
||||
typename Target::_data_t pick_arg_impl(Statement statement, Term term, const std::false_type&)
|
||||
{
|
||||
return static_cast<typename Target::template _member_t<Target>>(statement)()._data;
|
||||
return Target::_get_member(statement)._data;
|
||||
};
|
||||
|
||||
// Returns a statement's term either by picking the term from the statement or using the new term
|
||||
|
@ -143,7 +143,7 @@ namespace sqlpp
|
||||
typename... Policies
|
||||
>
|
||||
struct select_t:
|
||||
public Policies::template _member_t<Policies>...,
|
||||
public Policies::template _member_t<detail::select_policies_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
|
||||
@ -165,7 +165,11 @@ namespace sqlpp
|
||||
|
||||
template<typename Statement, typename Term>
|
||||
select_t(Statement statement, Term term):
|
||||
Policies::template _member_t<Policies>{{detail::pick_arg<Policies>(statement, term)}}...
|
||||
Policies::template _member_t<_policies_t>{
|
||||
typename Policies::template _impl_t<_policies_t>{
|
||||
detail::pick_arg<typename Policies::template _member_t<_policies_t>>(statement, term)
|
||||
}}...
|
||||
//Policies::template _member_t<_policies_t>{{detail::pick_arg<typename Policies::template _member_t<_policies_t>>(statement, term)}}...
|
||||
{}
|
||||
|
||||
select_t(const select_t& r) = default;
|
||||
@ -196,10 +200,10 @@ namespace sqlpp
|
||||
|
||||
template<typename Database>
|
||||
using blank_select_t = select_t<Database,
|
||||
//vendor::no_select_flag_list_t,
|
||||
vendor::no_select_flag_list_t,
|
||||
vendor::no_select_column_list_t,
|
||||
vendor::no_from_t/*,
|
||||
vendor::no_extra_tables_t*/,
|
||||
vendor::no_from_t,
|
||||
//vendor::no_extra_tables_t,
|
||||
vendor::no_where_t/*,
|
||||
vendor::no_group_by_t,
|
||||
vendor::no_having_t,
|
||||
|
69
include/sqlpp11/vendor/extra_tables.h
vendored
69
include/sqlpp11/vendor/extra_tables.h
vendored
@ -35,6 +35,20 @@ namespace sqlpp
|
||||
{
|
||||
namespace vendor
|
||||
{
|
||||
template<typename... Tables>
|
||||
struct extra_tables_data_t
|
||||
{
|
||||
extra_tables_data_t()
|
||||
{}
|
||||
|
||||
extra_tables_data_t(const extra_tables_data_t&) = default;
|
||||
extra_tables_data_t(extra_tables_data_t&&) = default;
|
||||
extra_tables_data_t& operator=(const extra_tables_data_t&) = default;
|
||||
extra_tables_data_t& operator=(extra_tables_data_t&&) = default;
|
||||
~extra_tables_data_t() = default;
|
||||
|
||||
};
|
||||
|
||||
// EXTRA_TABLES
|
||||
template<typename... Tables>
|
||||
struct extra_tables_t
|
||||
@ -56,26 +70,59 @@ namespace sqlpp
|
||||
static_assert(not ::sqlpp::detail::has_duplicates<Tables...>::value, "at least one duplicate argument detected in extra_tables()");
|
||||
static_assert(::sqlpp::detail::all_t<is_table_t<Tables>::value...>::value, "at least one argument is not a table or join in extra_tables()");
|
||||
|
||||
extra_tables_t()
|
||||
{}
|
||||
// Data
|
||||
using _data_t = extra_tables_data_t<Tables...>;
|
||||
|
||||
extra_tables_t(const extra_tables_t&) = default;
|
||||
extra_tables_t(extra_tables_t&&) = default;
|
||||
extra_tables_t& operator=(const extra_tables_t&) = default;
|
||||
extra_tables_t& operator=(extra_tables_t&&) = default;
|
||||
~extra_tables_t() = default;
|
||||
// Member implementation with data and methods
|
||||
template <typename Policies>
|
||||
struct _impl_t
|
||||
{
|
||||
_data_t _data;
|
||||
};
|
||||
|
||||
// Member template for adding the named member to a statement
|
||||
template<typename Policies>
|
||||
struct _member_t
|
||||
{
|
||||
_impl_t<Policies> extra_tables;
|
||||
_impl_t<Policies>& operator()() { return extra_tables; }
|
||||
const _impl_t<Policies>& operator()() const { return extra_tables; }
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
// NO EXTRA TABLES YET
|
||||
struct no_extra_tables_t
|
||||
{
|
||||
using _traits = make_traits<no_value_t, ::sqlpp::tag::noop>;
|
||||
using _recursive_traits = make_recursive_traits<>;
|
||||
|
||||
// Data
|
||||
struct _data_t
|
||||
{
|
||||
};
|
||||
|
||||
// Member implementation with data and methods
|
||||
template<typename Policies>
|
||||
struct _impl_t
|
||||
{
|
||||
_data_t _data;
|
||||
};
|
||||
|
||||
// Member template for adding the named member to a statement
|
||||
template<typename Policies>
|
||||
struct _member_t
|
||||
{
|
||||
_impl_t<Policies> no_extra_tables_t;
|
||||
_impl_t<Policies>& operator()() { return no_extra_tables_t; }
|
||||
const _impl_t<Policies>& operator()() const { return no_extra_tables_t; }
|
||||
};
|
||||
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
@ -86,14 +133,14 @@ namespace sqlpp
|
||||
auto extra_tables(Args...)
|
||||
-> _new_statement_t<extra_tables_t<Args...>>
|
||||
{
|
||||
return { *static_cast<typename Policies::_statement_t*>(this), extra_tables_t<Args...>{} };
|
||||
return { *static_cast<typename Policies::_statement_t*>(this), extra_tables_data_t<Args...>{} };
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
template<typename Context, typename Database, typename... Tables>
|
||||
struct serializer_t<Context, extra_tables_t<Database, Tables...>>
|
||||
struct serializer_t<Context, extra_tables_data_t<Database, Tables...>>
|
||||
{
|
||||
using T = extra_tables_t<Database, Tables...>;
|
||||
|
||||
@ -104,9 +151,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template<typename Context>
|
||||
struct serializer_t<Context, no_extra_tables_t>
|
||||
struct serializer_t<Context, typename no_extra_tables_t::_data_t>
|
||||
{
|
||||
using T = no_extra_tables_t;
|
||||
using T = typename no_extra_tables_t::_data_t;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
|
40
include/sqlpp11/vendor/from.h
vendored
40
include/sqlpp11/vendor/from.h
vendored
@ -81,10 +81,11 @@ namespace sqlpp
|
||||
struct _impl_t
|
||||
{
|
||||
template<typename Table>
|
||||
void _add_t(Table table)
|
||||
void add(Table table)
|
||||
{
|
||||
static_assert(_is_dynamic::value, "from::add() must not be called for static from()");
|
||||
static_assert(is_table_t<Table>::value, "invalid table argument in from::add()");
|
||||
#warning need to check if table is already known
|
||||
|
||||
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t<Table>::value>;
|
||||
|
||||
@ -109,9 +110,17 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _member_t
|
||||
{
|
||||
_impl_t<Policies> no_from;
|
||||
_impl_t<Policies>& operator()() { return no_from; }
|
||||
const _impl_t<Policies>& operator()() const { return no_from; }
|
||||
using _data_t = from_data_t<Database, Tables...>;
|
||||
|
||||
_impl_t<Policies> from;
|
||||
_impl_t<Policies>& operator()() { return from; }
|
||||
const _impl_t<Policies>& operator()() const { return from; }
|
||||
|
||||
template<typename T>
|
||||
static auto _get_member(T t) -> decltype(t.from)
|
||||
{
|
||||
return t.from;
|
||||
}
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
@ -127,9 +136,7 @@ namespace sqlpp
|
||||
using _recursive_traits = make_recursive_traits<>;
|
||||
|
||||
// Data
|
||||
struct _data_t
|
||||
{
|
||||
};
|
||||
using _data_t = no_data_t;
|
||||
|
||||
// Member implementation with data and methods
|
||||
template<typename Policies>
|
||||
@ -142,9 +149,17 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _member_t
|
||||
{
|
||||
using _data_t = no_data_t;
|
||||
|
||||
_impl_t<Policies> no_from;
|
||||
_impl_t<Policies>& operator()() { return no_from; }
|
||||
const _impl_t<Policies>& operator()() const { return no_from; }
|
||||
|
||||
template<typename T>
|
||||
static auto _get_member(T t) -> decltype(t.no_from)
|
||||
{
|
||||
return t.no_from;
|
||||
}
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
@ -191,17 +206,6 @@ namespace sqlpp
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Context>
|
||||
struct serializer_t<Context, no_from_t::_data_t>
|
||||
{
|
||||
using T = no_from_t::_data_t;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
14
include/sqlpp11/vendor/noop.h
vendored
14
include/sqlpp11/vendor/noop.h
vendored
@ -35,6 +35,20 @@ namespace sqlpp
|
||||
{
|
||||
namespace vendor
|
||||
{
|
||||
#warning: Need extra include file for no_data
|
||||
struct no_data_t {};
|
||||
|
||||
template<typename Context>
|
||||
struct serializer_t<Context, no_data_t>
|
||||
{
|
||||
using T = no_data_t;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
struct noop
|
||||
{
|
||||
using _traits = make_traits<no_value_t, ::sqlpp::tag::noop>;
|
||||
|
46
include/sqlpp11/vendor/select_column_list.h
vendored
46
include/sqlpp11/vendor/select_column_list.h
vendored
@ -177,17 +177,17 @@ namespace sqlpp
|
||||
struct _impl_t
|
||||
{
|
||||
template<typename NamedExpression>
|
||||
void add_column_ntc(NamedExpression namedExpression)
|
||||
void add_ntc(NamedExpression namedExpression)
|
||||
{
|
||||
add_column<NamedExpression, std::false_type>(namedExpression);
|
||||
add<NamedExpression, std::false_type>(namedExpression);
|
||||
}
|
||||
|
||||
template<typename NamedExpression, typename TableCheckRequired = std::true_type>
|
||||
void add_column(NamedExpression namedExpression)
|
||||
void add(NamedExpression namedExpression)
|
||||
{
|
||||
static_assert(_is_dynamic::value, "add_column can only be called for dynamic_column");
|
||||
static_assert(is_named_expression_t<NamedExpression>::value, "invalid named expression argument in add_column()");
|
||||
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<NamedExpression>::value, "named expression uses tables unknown to this statement in add_column()");
|
||||
static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column");
|
||||
static_assert(is_named_expression_t<NamedExpression>::value, "invalid named expression argument in selected_columns::add()");
|
||||
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<NamedExpression>::value, "named expression uses tables unknown to this statement in selected_columns::add()");
|
||||
using column_names = ::sqlpp::detail::make_type_set_t<typename Columns::_name_t...>;
|
||||
static_assert(not ::sqlpp::detail::is_element_of<typename NamedExpression::_name_t, column_names>::value, "a column of this name is present in the select already");
|
||||
|
||||
@ -196,12 +196,12 @@ namespace sqlpp
|
||||
is_named_expression_t<NamedExpression>::value
|
||||
>;
|
||||
|
||||
_add_column_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert
|
||||
_add_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert
|
||||
}
|
||||
|
||||
//private:
|
||||
template<typename NamedExpression>
|
||||
void _add_column_impl(NamedExpression namedExpression, const std::true_type&)
|
||||
void _add_impl(NamedExpression namedExpression, const std::true_type&)
|
||||
{
|
||||
return _data._dynamic_columns.emplace_back(namedExpression);
|
||||
}
|
||||
@ -217,9 +217,17 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _member_t
|
||||
{
|
||||
using _data_t = select_column_list_data_t<Database, Columns...>;
|
||||
|
||||
_impl_t<Policies> selected_columns;
|
||||
_impl_t<Policies>& operator()() { return selected_columns; }
|
||||
const _impl_t<Policies>& operator()() const { return selected_columns; }
|
||||
|
||||
template<typename T>
|
||||
static auto _get_member(T t) -> decltype(t.selected_columns)
|
||||
{
|
||||
return t.selected_columns;
|
||||
}
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
@ -333,9 +341,7 @@ namespace sqlpp
|
||||
struct _name_t {};
|
||||
|
||||
// Data
|
||||
struct _data_t
|
||||
{
|
||||
};
|
||||
using _data_t = no_data_t;
|
||||
|
||||
// Member implementation with data and methods
|
||||
template<typename Policies>
|
||||
@ -348,9 +354,17 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _member_t
|
||||
{
|
||||
using _data_t = no_data_t;
|
||||
|
||||
_impl_t<Policies> no_selected_columns;
|
||||
_impl_t<Policies>& operator()() { return no_selected_columns; }
|
||||
const _impl_t<Policies>& operator()() const { return no_selected_columns; }
|
||||
|
||||
template<typename T>
|
||||
static auto _get_member(T t) -> decltype(t.no_selected_columns)
|
||||
{
|
||||
return t.no_selected_columns;
|
||||
}
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
@ -397,16 +411,6 @@ namespace sqlpp
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Context>
|
||||
struct serializer_t<Context, typename no_select_column_list_t::_data_t>
|
||||
{
|
||||
using T = typename no_select_column_list_t::_data_t;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
125
include/sqlpp11/vendor/select_flag_list.h
vendored
125
include/sqlpp11/vendor/select_flag_list.h
vendored
@ -38,6 +38,24 @@ namespace sqlpp
|
||||
{
|
||||
namespace vendor
|
||||
{
|
||||
// SELECTED COLUMNS DATA
|
||||
template<typename Database, typename... Flags>
|
||||
struct select_flag_list_data_t
|
||||
{
|
||||
select_flag_list_data_t(Flags... flags):
|
||||
_flags(flags...)
|
||||
{}
|
||||
|
||||
select_flag_list_data_t(const select_flag_list_data_t&) = default;
|
||||
select_flag_list_data_t(select_flag_list_data_t&&) = default;
|
||||
select_flag_list_data_t& operator=(const select_flag_list_data_t&) = default;
|
||||
select_flag_list_data_t& operator=(select_flag_list_data_t&&) = default;
|
||||
~select_flag_list_data_t() = default;
|
||||
|
||||
std::tuple<Flags...> _flags;
|
||||
vendor::interpretable_list_t<Database> _dynamic_flags;
|
||||
};
|
||||
|
||||
// SELECT FLAGS
|
||||
template<typename Database, typename... Flags>
|
||||
struct select_flag_list_t
|
||||
@ -51,53 +69,67 @@ namespace sqlpp
|
||||
|
||||
static_assert(::sqlpp::detail::all_t<is_select_flag_t<Flags>::value...>::value, "at least one argument is not a select flag in select flag list");
|
||||
|
||||
select_flag_list_t& _select_flag_list() { return *this; }
|
||||
|
||||
select_flag_list_t(Flags... flags):
|
||||
_flags(flags...)
|
||||
{}
|
||||
|
||||
select_flag_list_t(const select_flag_list_t&) = default;
|
||||
select_flag_list_t(select_flag_list_t&&) = default;
|
||||
select_flag_list_t& operator=(const select_flag_list_t&) = default;
|
||||
select_flag_list_t& operator=(select_flag_list_t&&) = default;
|
||||
~select_flag_list_t() = default;
|
||||
// Data
|
||||
using _data_t = select_flag_list_data_t<Database, Flags...>;
|
||||
|
||||
// Member implementation with data and methods
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
struct _impl_t
|
||||
{
|
||||
template<typename Flag>
|
||||
void add_flag_ntc(Flag flag)
|
||||
void add_ntc(Flag flag)
|
||||
{
|
||||
add_flag<Flag, std::false_type>(flag);
|
||||
add<Flag, std::false_type>(flag);
|
||||
}
|
||||
|
||||
template<typename Flag, typename TableCheckRequired = std::true_type>
|
||||
void add_flag(Flag flag)
|
||||
void add(Flag flag)
|
||||
{
|
||||
static_assert(_is_dynamic::value, "add_flag must not be called for static select flags");
|
||||
static_assert(is_select_flag_t<Flag>::value, "invalid select flag argument in add_flag()");
|
||||
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Flag>::value, "flag uses tables unknown to this statement in add_flag()");
|
||||
static_assert(_is_dynamic::value, "select_flags::add() must not be called for static select flags");
|
||||
static_assert(is_select_flag_t<Flag>::value, "invalid select flag argument in select_flags::add()");
|
||||
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Flag>::value, "flag uses tables unknown to this statement in select_flags::add()");
|
||||
|
||||
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_select_flag_t<Flag>::value>;
|
||||
|
||||
_add_flag_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert
|
||||
_add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename Flag>
|
||||
void _add_flag_impl(Flag flag, const std::true_type&)
|
||||
void _add_impl(Flag flag, const std::true_type&)
|
||||
{
|
||||
return static_cast<typename Policies::_statement_t*>(this)->_select_flag_list()._dynamic_flags.emplace_back(flag);
|
||||
}
|
||||
|
||||
template<typename Flag>
|
||||
void _add_flag_impl(Flag flag, const std::false_type&);
|
||||
void _add_impl(Flag flag, const std::false_type&);
|
||||
public:
|
||||
_data_t _data;
|
||||
};
|
||||
|
||||
// Member template for adding the named member to a statement
|
||||
template<typename Policies>
|
||||
struct _member_t
|
||||
{
|
||||
using _data_t = select_flag_list_data_t<Database, Flags...>;
|
||||
|
||||
_impl_t<Policies> select_flags;
|
||||
_impl_t<Policies>& operator()() { return select_flags; }
|
||||
const _impl_t<Policies>& operator()() const { return select_flags; }
|
||||
|
||||
template<typename T>
|
||||
static auto _get_member(T t) -> decltype(t.select_flags)
|
||||
{
|
||||
return t.select_flags;
|
||||
}
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
};
|
||||
|
||||
const select_flag_list_t& _flag_list() const { return *this; }
|
||||
std::tuple<Flags...> _flags;
|
||||
vendor::interpretable_list_t<Database> _dynamic_flags;
|
||||
};
|
||||
|
||||
struct no_select_flag_list_t
|
||||
@ -105,6 +137,33 @@ namespace sqlpp
|
||||
using _traits = make_traits<no_value_t, ::sqlpp::tag::noop>;
|
||||
using _recursive_traits = make_recursive_traits<>;
|
||||
|
||||
// Data
|
||||
using _data_t = no_data_t;
|
||||
|
||||
// Member implementation with data and methods
|
||||
template<typename Policies>
|
||||
struct _impl_t
|
||||
{
|
||||
_data_t _data;
|
||||
};
|
||||
|
||||
// Member template for adding the named member to a statement
|
||||
template<typename Policies>
|
||||
struct _member_t
|
||||
{
|
||||
using _data_t = no_data_t;
|
||||
|
||||
_impl_t<Policies> no_select_flags;
|
||||
_impl_t<Policies>& operator()() { return no_select_flags; }
|
||||
const _impl_t<Policies>& operator()() const { return no_select_flags; }
|
||||
|
||||
template<typename T>
|
||||
static auto _get_member(T t) -> decltype(t.no_select_flags)
|
||||
{
|
||||
return t.no_select_flags;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
@ -116,7 +175,7 @@ namespace sqlpp
|
||||
auto flags(Args... args)
|
||||
-> _new_statement_t<select_flag_list_t<void, Args...>>
|
||||
{
|
||||
return { *static_cast<typename Policies::_statement_t*>(this), select_flag_list_t<void, Args...>{args...} };
|
||||
return { *static_cast<typename Policies::_statement_t*>(this), select_flag_list_data_t<void, Args...>{args...} };
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
@ -124,7 +183,7 @@ namespace sqlpp
|
||||
-> _new_statement_t<select_flag_list_t<_database_t, Args...>>
|
||||
{
|
||||
static_assert(not std::is_same<_database_t, void>::value, "dynamic_flags must not be called in a static statement");
|
||||
return { *static_cast<typename Policies::_statement_t*>(this), vendor::select_flag_list_t<_database_t, Args...>{args...} };
|
||||
return { *static_cast<typename Policies::_statement_t*>(this), select_flag_list_data_t<_database_t, Args...>{args...} };
|
||||
}
|
||||
};
|
||||
};
|
||||
@ -132,9 +191,9 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template<typename Context, typename Database, typename... Flags>
|
||||
struct serializer_t<Context, select_flag_list_t<Database, Flags...>>
|
||||
struct serializer_t<Context, select_flag_list_data_t<Database, Flags...>>
|
||||
{
|
||||
using T = select_flag_list_t<Database, Flags...>;
|
||||
using T = select_flag_list_data_t<Database, Flags...>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
@ -148,16 +207,6 @@ namespace sqlpp
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Context>
|
||||
struct serializer_t<Context, no_select_flag_list_t>
|
||||
{
|
||||
using T = no_select_flag_list_t;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
91
include/sqlpp11/vendor/where.h
vendored
91
include/sqlpp11/vendor/where.h
vendored
@ -75,38 +75,40 @@ namespace sqlpp
|
||||
// Member implementation with data and methods
|
||||
template <typename Policies>
|
||||
struct _impl_t
|
||||
{
|
||||
template<typename Expression>
|
||||
void add_ntc(Expression expression)
|
||||
{
|
||||
add<Expression, std::false_type>(expression);
|
||||
}
|
||||
{
|
||||
using _data_t = where_data_t<Database, Expressions...>;
|
||||
|
||||
template<typename Expression, typename TableCheckRequired = std::true_type>
|
||||
void add(Expression expression)
|
||||
{
|
||||
static_assert(_is_dynamic::value, "where::add() can only be called for dynamic_where");
|
||||
static_assert(is_expression_t<Expression>::value, "invalid expression argument in where::add()");
|
||||
static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in where::add()");
|
||||
template<typename Expression>
|
||||
void add_ntc(Expression expression)
|
||||
{
|
||||
add<Expression, std::false_type>(expression);
|
||||
}
|
||||
|
||||
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
|
||||
template<typename Expression, typename TableCheckRequired = std::true_type>
|
||||
void add(Expression expression)
|
||||
{
|
||||
static_assert(_is_dynamic::value, "where::add() can only be called for dynamic_where");
|
||||
static_assert(is_expression_t<Expression>::value, "invalid expression argument in where::add()");
|
||||
static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in where::add()");
|
||||
|
||||
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
|
||||
}
|
||||
using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
|
||||
|
||||
private:
|
||||
template<typename Expression>
|
||||
void _add_impl(Expression expression, const std::true_type&)
|
||||
{
|
||||
return _data._dynamic_expressions.emplace_back(expression);
|
||||
}
|
||||
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
|
||||
}
|
||||
|
||||
template<typename Expression>
|
||||
void _add_impl(Expression expression, const std::false_type&);
|
||||
private:
|
||||
template<typename Expression>
|
||||
void _add_impl(Expression expression, const std::true_type&)
|
||||
{
|
||||
return _data._dynamic_expressions.emplace_back(expression);
|
||||
}
|
||||
|
||||
public:
|
||||
_data_t _data;
|
||||
};
|
||||
template<typename Expression>
|
||||
void _add_impl(Expression expression, const std::false_type&);
|
||||
|
||||
public:
|
||||
_data_t _data;
|
||||
};
|
||||
|
||||
// Member template for adding the named member to a statement
|
||||
template<typename Policies>
|
||||
@ -115,6 +117,12 @@ namespace sqlpp
|
||||
_impl_t<Policies> where;
|
||||
_impl_t<Policies>& operator()() { return where; }
|
||||
const _impl_t<Policies>& operator()() const { return where; }
|
||||
|
||||
template<typename T>
|
||||
static auto _get_member(T t) -> decltype(t.where)
|
||||
{
|
||||
return t.where;
|
||||
}
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
@ -151,9 +159,17 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _member_t
|
||||
{
|
||||
using _data_t = where_data_t<void, bool>;
|
||||
|
||||
_impl_t<Policies> where;
|
||||
_impl_t<Policies>& operator()() { return where; }
|
||||
const _impl_t<Policies>& operator()() const { return where; }
|
||||
|
||||
template<typename T>
|
||||
static auto _get_member(T t) -> decltype(t.where)
|
||||
{
|
||||
return t.where;
|
||||
}
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
@ -171,9 +187,7 @@ namespace sqlpp
|
||||
using _recursive_traits = make_recursive_traits<>;
|
||||
|
||||
// Data
|
||||
struct _data_t
|
||||
{
|
||||
};
|
||||
using _data_t = no_data_t;
|
||||
|
||||
// Member implementation with data and methods
|
||||
template<typename Policies>
|
||||
@ -186,9 +200,17 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _member_t
|
||||
{
|
||||
using _data_t = no_data_t;
|
||||
|
||||
_impl_t<Policies> no_where;
|
||||
_impl_t<Policies>& operator()() { return no_where; }
|
||||
const _impl_t<Policies>& operator()() const { return no_where; }
|
||||
|
||||
template<typename T>
|
||||
static auto _get_member(T t) -> decltype(t.no_where)
|
||||
{
|
||||
return t.no_where;
|
||||
}
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
@ -248,17 +270,6 @@ namespace sqlpp
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Context>
|
||||
struct serializer_t<Context, typename no_where_t::_data_t>
|
||||
{
|
||||
using T = typename no_where_t::_data_t;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,14 @@ int main()
|
||||
test::TabFoo f;
|
||||
test::TabBar t;
|
||||
|
||||
sqlpp::select(t.alpha).flags(sqlpp::all).from(t);
|
||||
for (const auto& row : db(select(all_of(t)).from(t).where(true)))
|
||||
{
|
||||
int64_t a = row.alpha;
|
||||
const std::string b = row.beta;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
for (const auto& row : db(select(all_of(t).as(t)).from(t).where(true)))
|
||||
{
|
||||
int64_t a = row.tabBar.alpha;
|
||||
@ -69,16 +70,16 @@ int main()
|
||||
const bool g = row.gamma;
|
||||
}
|
||||
|
||||
auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where().dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset();
|
||||
s.add_flag(sqlpp::distinct);
|
||||
s.add_column(f.omega);
|
||||
s.add_from(f);
|
||||
s.add_where(t.alpha > 7);
|
||||
s.add_having(t.alpha > 7);
|
||||
s.set_limit(3);
|
||||
s.set_offset(3);
|
||||
s.add_group_by(t.beta);
|
||||
s.add_order_by(t.beta.asc());
|
||||
auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where()/*.dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset()*/;
|
||||
s.select_flags.add(sqlpp::distinct);
|
||||
s.selected_columns.add(f.omega);
|
||||
s.from.add(f);
|
||||
s.where.add(t.alpha > 7);
|
||||
s.having.add(t.alpha > 7);
|
||||
s.limit.set(3);
|
||||
s.offset.set(3);
|
||||
s.group_by.add(t.beta);
|
||||
s.order_by.add(t.beta.asc());
|
||||
for (const auto& row : db(s))
|
||||
{
|
||||
int64_t a = row.alpha;
|
||||
|
Loading…
Reference in New Issue
Block a user