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

Added _check_consistency call to all statement parts

For instance, enforce where() to be called
This commit is contained in:
rbock 2014-06-24 21:53:25 +02:00
parent 0b27373314
commit 1267aa252f
19 changed files with 118 additions and 87 deletions

View File

@ -97,6 +97,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -139,6 +140,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_extra_tables_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_extra_tables_t, T>;
static void _check_consistency() {}
template<typename... Args> template<typename... Args>
auto extra_tables(Args...) auto extra_tables(Args...)
-> _new_statement_t<extra_tables_t<Args...>> -> _new_statement_t<extra_tables_t<Args...>>

View File

@ -126,6 +126,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -169,6 +170,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_from_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_from_t, T>;
static void _check_consistency() {}
template<typename... Args> template<typename... Args>
auto from(Args... args) auto from(Args... args)
-> _new_statement_t<from_t<void, Args...>> -> _new_statement_t<from_t<void, Args...>>

View File

@ -128,6 +128,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -171,6 +172,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_group_by_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_group_by_t, T>;
static void _check_consistency() {}
template<typename... Args> template<typename... Args>
auto group_by(Args... args) auto group_by(Args... args)
-> _new_statement_t<group_by_t<void, Args...>> -> _new_statement_t<group_by_t<void, Args...>>

View File

@ -126,6 +126,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -169,6 +170,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_having_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_having_t, T>;
static void _check_consistency() {}
template<typename... Args> template<typename... Args>
auto having(Args... args) auto having(Args... args)
-> _new_statement_t<having_t<void, Args...>> -> _new_statement_t<having_t<void, Args...>>

View File

@ -76,7 +76,9 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{}; {
static void _check_consistency() {}
};
}; };
template<typename Database, typename... Assignments> template<typename Database, typename... Assignments>
@ -197,10 +199,9 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
template<typename... Columns> template<typename... Columns>
@ -296,6 +297,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
/* /*
@ -347,6 +349,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_insert_value_list_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_insert_value_list_t, T>;
static void _check_consistency() {}
auto default_values() auto default_values()
-> _new_statement_t<insert_default_values_t> -> _new_statement_t<insert_default_values_t>
{ {

View File

@ -57,7 +57,7 @@ namespace sqlpp
template<typename Database, typename Table> template<typename Database, typename Table>
struct into_t struct into_t
{ {
using _traits = make_traits<no_value_t, ::sqlpp::tag::into, tag::return_value>; using _traits = make_traits<no_value_t, ::sqlpp::tag::into>;
using _recursive_traits = make_recursive_traits<Table>; using _recursive_traits = make_recursive_traits<Table>;
static_assert(is_table_t<Table>::value, "argument has to be a table"); static_assert(is_table_t<Table>::value, "argument has to be a table");
@ -95,36 +95,9 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
template<typename Policies>
struct _result_methods_t
{
using _statement_t = typename Policies::_statement_t;
const _statement_t& _get_statement() const
{
return static_cast<const _statement_t&>(*this);
}
template<typename Db>
auto _run(Db& db) const -> decltype(db.insert(this->_get_statement()))
{
_statement_t::_check_consistency();
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead");
return db.insert(_get_statement());
}
template<typename Db>
auto _prepare(Db& db) const
-> prepared_insert_t<Db, _statement_t>
{
_statement_t::_check_consistency();
return {{}, db.prepare_insert(_get_statement())};
}
};
}; };
// NO INTO YET // NO INTO YET
@ -167,6 +140,11 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_into_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_into_t, T>;
static void _check_consistency()
{
static_assert(wrong_t<Policies>::value, "into() required");
}
template<typename... Args> template<typename... Args>
auto into(Args... args) auto into(Args... args)
-> _new_statement_t<into_t<void, Args...>> -> _new_statement_t<into_t<void, Args...>>

View File

@ -89,6 +89,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -165,6 +166,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -207,6 +209,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_limit_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_limit_t, T>;
static void _check_consistency() {}
template<typename Arg> template<typename Arg>
auto limit(Arg arg) auto limit(Arg arg)
-> _new_statement_t<limit_t<typename wrap_operand<Arg>::type>> -> _new_statement_t<limit_t<typename wrap_operand<Arg>::type>>

View File

@ -89,6 +89,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -164,6 +165,8 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
template<typename Offset> template<typename Offset>
void set_offset(Offset value) void set_offset(Offset value)
{ {
@ -217,6 +220,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_offset_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_offset_t, T>;
static void _check_consistency() {}
template<typename Arg> template<typename Arg>
auto offset(Arg arg) auto offset(Arg arg)
-> _new_statement_t<offset_t<typename wrap_operand<Arg>::type>> -> _new_statement_t<offset_t<typename wrap_operand<Arg>::type>>

View File

@ -128,6 +128,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -171,6 +172,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_order_by_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_order_by_t, T>;
static void _check_consistency() {}
template<typename... Args> template<typename... Args>
auto order_by(Args... args) auto order_by(Args... args)
-> _new_statement_t<order_by_t<void, Args...>> -> _new_statement_t<order_by_t<void, Args...>>

View File

@ -96,7 +96,8 @@ namespace sqlpp
no_from_t, no_from_t,
no_using_t, no_using_t,
no_extra_tables_t, no_extra_tables_t,
no_where_t>; no_where_t<true>
>;
auto remove() auto remove()
-> blank_remove_t<void> -> blank_remove_t<void>

View File

@ -71,7 +71,7 @@ namespace sqlpp
no_select_column_list_t, no_select_column_list_t,
no_from_t, no_from_t,
no_extra_tables_t, no_extra_tables_t,
no_where_t, no_where_t<true>,
no_group_by_t, no_group_by_t,
no_having_t, no_having_t,
no_order_by_t, no_order_by_t,

View File

@ -231,6 +231,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
// Result methods // Result methods
@ -355,6 +356,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_select_column_list_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_select_column_list_t, T>;
static void _check_consistency() {}
template<typename... Args> template<typename... Args>
auto columns(Args... args) auto columns(Args... args)
-> _new_statement_t<::sqlpp::detail::make_select_column_list_t<void, Args...>> -> _new_statement_t<::sqlpp::detail::make_select_column_list_t<void, Args...>>

View File

@ -127,6 +127,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -170,6 +171,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_select_flag_list_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_select_flag_list_t, T>;
static void _check_consistency() {}
template<typename... Args> template<typename... Args>
auto flags(Args... args) auto flags(Args... args)
-> _new_statement_t<select_flag_list_t<void, Args...>> -> _new_statement_t<select_flag_list_t<void, Args...>>

View File

@ -95,6 +95,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -139,6 +140,7 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_single_table_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_single_table_t, T>;
static void _check_consistency() {}
#warning: remove can operate on several tables at once, so it should not use single_table anyway #warning: remove can operate on several tables at once, so it should not use single_table anyway
template<typename... Args> template<typename... Args>
auto from(Args... args) auto from(Args... args)

View File

@ -52,9 +52,6 @@ namespace sqlpp
using _database_t = Db; using _database_t = Db;
using _statement_t = statement_t<Db, Policies...>; using _statement_t = statement_t<Db, Policies...>;
struct _methods_t: public Policies::template _methods_t<statement_policies_t>...
{};
template<typename Needle, typename Replacement> template<typename Needle, typename Replacement>
struct _policies_update_t struct _policies_update_t
{ {
@ -125,7 +122,7 @@ namespace sqlpp
public Policies::template _member_t<detail::statement_policies_t<Db, Policies...>>..., public Policies::template _member_t<detail::statement_policies_t<Db, Policies...>>...,
public detail::statement_policies_t<Db, Policies...>::_value_type::template expression_operators<statement_t<Db, Policies...>>, public detail::statement_policies_t<Db, Policies...>::_value_type::template expression_operators<statement_t<Db, Policies...>>,
public detail::statement_policies_t<Db, Policies...>::_result_methods_t, public detail::statement_policies_t<Db, Policies...>::_result_methods_t,
public detail::statement_policies_t<Db, Policies...>::_methods_t public Policies::template _methods_t<detail::statement_policies_t<Db, Policies...>>...
{ {
using _policies_t = typename detail::statement_policies_t<Db, Policies...>; using _policies_t = typename detail::statement_policies_t<Db, Policies...>;
@ -172,6 +169,9 @@ namespace sqlpp
// FIXME: Check each "methods" or each member... // FIXME: Check each "methods" or each member...
#warning check for missing terms here, and for missing tables #warning check for missing terms here, and for missing tables
static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement"); static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement");
using swallow = int[];
(void) swallow{(Policies::template _methods_t<detail::statement_policies_t<Db, Policies...>>::_check_consistency(), 0)...};
} }
@ -229,6 +229,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };

View File

@ -95,7 +95,8 @@ namespace sqlpp
update_t, update_t,
no_single_table_t, no_single_table_t,
no_update_list_t, no_update_list_t,
no_where_t>; no_where_t<true>
>;
template<typename Table> template<typename Table>
constexpr auto update(Table table) constexpr auto update(Table table)

View File

@ -140,6 +140,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -182,6 +183,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_update_list_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_update_list_t, T>;
static void _check_consistency() {}
template<typename... Args> template<typename... Args>
auto set(Args... args) auto set(Args... args)
-> _new_statement_t<update_list_t<void, Args...>> -> _new_statement_t<update_list_t<void, Args...>>

View File

@ -121,6 +121,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -164,6 +165,8 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_using_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_using_t, T>;
static void _check_consistency() {}
template<typename... Args> template<typename... Args>
auto using_(Args... args) auto using_(Args... args)
-> _new_statement_t<using_t<void, Args...>> -> _new_statement_t<using_t<void, Args...>>

View File

@ -127,6 +127,7 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
@ -174,11 +175,13 @@ namespace sqlpp
template<typename Policies> template<typename Policies>
struct _methods_t struct _methods_t
{ {
static void _check_consistency() {}
}; };
}; };
// NO WHERE YET // NO WHERE YET
template<bool Required>
struct no_where_t struct no_where_t
{ {
using _traits = make_traits<no_value_t, ::sqlpp::tag::where>; using _traits = make_traits<no_value_t, ::sqlpp::tag::where>;
@ -219,6 +222,11 @@ namespace sqlpp
template<typename T> template<typename T>
using _new_statement_t = typename Policies::template _new_statement_t<no_where_t, T>; using _new_statement_t = typename Policies::template _new_statement_t<no_where_t, T>;
static void _check_consistency()
{
static_assert(Required ? wrong_t<Policies>::value : true, "where expression required, e.g. where(true)");
}
template<typename... Args> template<typename... Args>
auto where(Args... args) auto where(Args... args)
-> _new_statement_t<where_t<void, Args...>> -> _new_statement_t<where_t<void, Args...>>