mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Added _check_consistency call to all statement parts
For instance, enforce where() to be called
This commit is contained in:
parent
0b27373314
commit
1267aa252f
@ -97,6 +97,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -139,6 +140,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_extra_tables_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename... Args>
|
||||
auto extra_tables(Args...)
|
||||
-> _new_statement_t<extra_tables_t<Args...>>
|
||||
|
@ -126,6 +126,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -169,6 +170,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_from_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename... Args>
|
||||
auto from(Args... args)
|
||||
-> _new_statement_t<from_t<void, Args...>>
|
||||
|
@ -128,6 +128,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -171,6 +172,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_group_by_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename... Args>
|
||||
auto group_by(Args... args)
|
||||
-> _new_statement_t<group_by_t<void, Args...>>
|
||||
|
@ -126,6 +126,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -169,6 +170,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_having_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename... Args>
|
||||
auto having(Args... args)
|
||||
-> _new_statement_t<having_t<void, Args...>>
|
||||
|
@ -76,7 +76,9 @@ namespace sqlpp
|
||||
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{};
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Database, typename... Assignments>
|
||||
@ -197,10 +199,9 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
template<typename... Columns>
|
||||
@ -296,6 +297,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -347,6 +349,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_insert_value_list_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
auto default_values()
|
||||
-> _new_statement_t<insert_default_values_t>
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ namespace sqlpp
|
||||
template<typename Database, typename Table>
|
||||
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>;
|
||||
|
||||
static_assert(is_table_t<Table>::value, "argument has to be a table");
|
||||
@ -95,36 +95,9 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
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
|
||||
@ -167,6 +140,11 @@ namespace sqlpp
|
||||
template<typename 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>
|
||||
auto into(Args... args)
|
||||
-> _new_statement_t<into_t<void, Args...>>
|
||||
|
@ -89,6 +89,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -165,6 +166,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -207,6 +209,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_limit_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename Arg>
|
||||
auto limit(Arg arg)
|
||||
-> _new_statement_t<limit_t<typename wrap_operand<Arg>::type>>
|
||||
|
@ -89,6 +89,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -164,6 +165,8 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename Offset>
|
||||
void set_offset(Offset value)
|
||||
{
|
||||
@ -217,6 +220,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_offset_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename Arg>
|
||||
auto offset(Arg arg)
|
||||
-> _new_statement_t<offset_t<typename wrap_operand<Arg>::type>>
|
||||
|
@ -128,6 +128,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -171,6 +172,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_order_by_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename... Args>
|
||||
auto order_by(Args... args)
|
||||
-> _new_statement_t<order_by_t<void, Args...>>
|
||||
|
@ -96,7 +96,8 @@ namespace sqlpp
|
||||
no_from_t,
|
||||
no_using_t,
|
||||
no_extra_tables_t,
|
||||
no_where_t>;
|
||||
no_where_t<true>
|
||||
>;
|
||||
|
||||
auto remove()
|
||||
-> blank_remove_t<void>
|
||||
|
@ -71,7 +71,7 @@ namespace sqlpp
|
||||
no_select_column_list_t,
|
||||
no_from_t,
|
||||
no_extra_tables_t,
|
||||
no_where_t,
|
||||
no_where_t<true>,
|
||||
no_group_by_t,
|
||||
no_having_t,
|
||||
no_order_by_t,
|
||||
|
@ -231,6 +231,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
|
||||
// Result methods
|
||||
@ -355,6 +356,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_select_column_list_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename... Args>
|
||||
auto columns(Args... args)
|
||||
-> _new_statement_t<::sqlpp::detail::make_select_column_list_t<void, Args...>>
|
||||
|
@ -127,6 +127,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
|
||||
};
|
||||
@ -170,6 +171,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_select_flag_list_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename... Args>
|
||||
auto flags(Args... args)
|
||||
-> _new_statement_t<select_flag_list_t<void, Args...>>
|
||||
|
@ -95,6 +95,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
|
||||
};
|
||||
@ -139,6 +140,7 @@ namespace sqlpp
|
||||
template<typename 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
|
||||
template<typename... Args>
|
||||
auto from(Args... args)
|
||||
|
@ -52,9 +52,6 @@ namespace sqlpp
|
||||
using _database_t = Db;
|
||||
using _statement_t = statement_t<Db, Policies...>;
|
||||
|
||||
struct _methods_t: public Policies::template _methods_t<statement_policies_t>...
|
||||
{};
|
||||
|
||||
template<typename Needle, typename Replacement>
|
||||
struct _policies_update_t
|
||||
{
|
||||
@ -125,7 +122,7 @@ namespace sqlpp
|
||||
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...>::_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...>;
|
||||
|
||||
@ -172,6 +169,9 @@ namespace sqlpp
|
||||
// FIXME: Check each "methods" or each member...
|
||||
#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");
|
||||
|
||||
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>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -95,7 +95,8 @@ namespace sqlpp
|
||||
update_t,
|
||||
no_single_table_t,
|
||||
no_update_list_t,
|
||||
no_where_t>;
|
||||
no_where_t<true>
|
||||
>;
|
||||
|
||||
template<typename Table>
|
||||
constexpr auto update(Table table)
|
||||
|
@ -140,6 +140,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -182,6 +183,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_update_list_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename... Args>
|
||||
auto set(Args... args)
|
||||
-> _new_statement_t<update_list_t<void, Args...>>
|
||||
|
@ -121,6 +121,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -164,6 +165,8 @@ namespace sqlpp
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_using_t, T>;
|
||||
|
||||
static void _check_consistency() {}
|
||||
|
||||
template<typename... Args>
|
||||
auto using_(Args... args)
|
||||
-> _new_statement_t<using_t<void, Args...>>
|
||||
|
@ -127,6 +127,7 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
};
|
||||
|
||||
@ -174,67 +175,74 @@ namespace sqlpp
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static void _check_consistency() {}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// NO WHERE YET
|
||||
struct no_where_t
|
||||
{
|
||||
using _traits = make_traits<no_value_t, ::sqlpp::tag::where>;
|
||||
using _recursive_traits = make_recursive_traits<>;
|
||||
template<bool Required>
|
||||
struct no_where_t
|
||||
{
|
||||
using _traits = make_traits<no_value_t, ::sqlpp::tag::where>;
|
||||
using _recursive_traits = make_recursive_traits<>;
|
||||
|
||||
// Data
|
||||
using _data_t = no_data_t;
|
||||
// Data
|
||||
using _data_t = no_data_t;
|
||||
|
||||
// Member implementation with data and methods
|
||||
template<typename Policies>
|
||||
struct _impl_t
|
||||
{
|
||||
_data_t _data;
|
||||
};
|
||||
// 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;
|
||||
// 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_where;
|
||||
_impl_t<Policies>& operator()() { return no_where; }
|
||||
const _impl_t<Policies>& operator()() const { return no_where; }
|
||||
_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)
|
||||
template<typename T>
|
||||
static auto _get_member(T t) -> decltype(t.no_where)
|
||||
{
|
||||
return t.no_where;
|
||||
}
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
using _database_t = typename Policies::_database_t;
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_where_t, T>;
|
||||
|
||||
static void _check_consistency()
|
||||
{
|
||||
return t.no_where;
|
||||
}
|
||||
};
|
||||
|
||||
// Additional methods for the statement
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
using _database_t = typename Policies::_database_t;
|
||||
template<typename T>
|
||||
using _new_statement_t = typename Policies::template _new_statement_t<no_where_t, T>;
|
||||
|
||||
template<typename... Args>
|
||||
auto where(Args... args)
|
||||
-> _new_statement_t<where_t<void, Args...>>
|
||||
{
|
||||
return { *static_cast<typename Policies::_statement_t*>(this), where_data_t<void, Args...>{args...} };
|
||||
static_assert(Required ? wrong_t<Policies>::value : true, "where expression required, e.g. where(true)");
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
auto dynamic_where(Args... args)
|
||||
-> _new_statement_t<where_t<_database_t, Args...>>
|
||||
{
|
||||
static_assert(not std::is_same<_database_t, void>::value, "dynamic_where must not be called in a static statement");
|
||||
return { *static_cast<typename Policies::_statement_t*>(this), where_data_t<_database_t, Args...>{args...} };
|
||||
}
|
||||
};
|
||||
};
|
||||
template<typename... Args>
|
||||
auto where(Args... args)
|
||||
-> _new_statement_t<where_t<void, Args...>>
|
||||
{
|
||||
return { *static_cast<typename Policies::_statement_t*>(this), where_data_t<void, Args...>{args...} };
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
auto dynamic_where(Args... args)
|
||||
-> _new_statement_t<where_t<_database_t, Args...>>
|
||||
{
|
||||
static_assert(not std::is_same<_database_t, void>::value, "dynamic_where must not be called in a static statement");
|
||||
return { *static_cast<typename Policies::_statement_t*>(this), where_data_t<_database_t, Args...>{args...} };
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
template<typename Context, typename Database, typename... Expressions>
|
||||
|
Loading…
Reference in New Issue
Block a user