mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Migrated remove to being variadic
This commit is contained in:
parent
22e1e7c531
commit
2a215905fd
@ -32,16 +32,11 @@
|
|||||||
#include <sqlpp11/vendor/expression_fwd.h>
|
#include <sqlpp11/vendor/expression_fwd.h>
|
||||||
#include <sqlpp11/vendor/in_fwd.h>
|
#include <sqlpp11/vendor/in_fwd.h>
|
||||||
#include <sqlpp11/vendor/is_null_fwd.h>
|
#include <sqlpp11/vendor/is_null_fwd.h>
|
||||||
|
#include <sqlpp11/vendor/wrap_operand.h>
|
||||||
#include <sqlpp11/detail/logic.h>
|
#include <sqlpp11/detail/logic.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
struct boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
// basic operators
|
// basic operators
|
||||||
template<typename Base, template<typename> class IsCorrectValueType>
|
template<typename Base, template<typename> class IsCorrectValueType>
|
||||||
struct basic_expression_operators
|
struct basic_expression_operators
|
||||||
|
@ -104,16 +104,14 @@ namespace sqlpp
|
|||||||
|
|
||||||
using _is_dynamic = typename std::conditional<std::is_same<_database_t, void>::value, std::false_type, std::true_type>::type;
|
using _is_dynamic = typename std::conditional<std::is_same<_database_t, void>::value, std::false_type, std::true_type>::type;
|
||||||
|
|
||||||
using _parameter_tuple_t = std::tuple<Policies...>;
|
|
||||||
using _parameter_list_t = typename make_parameter_list_t<insert_t>::type;
|
using _parameter_list_t = typename make_parameter_list_t<insert_t>::type;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
insert_t()
|
constexpr insert_t()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename Statement, typename T>
|
template<typename Statement, typename Term>
|
||||||
insert_t(Statement statement, T term):
|
insert_t(Statement statement, Term term):
|
||||||
Policies(detail::pick_arg<Policies>(statement, term))...
|
Policies(detail::pick_arg<Policies>(statement, term))...
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -181,6 +179,12 @@ namespace sqlpp
|
|||||||
vendor::no_single_table_t,
|
vendor::no_single_table_t,
|
||||||
vendor::no_insert_value_list_t>;
|
vendor::no_insert_value_list_t>;
|
||||||
|
|
||||||
|
constexpr auto insert()
|
||||||
|
-> blank_insert_t<void>
|
||||||
|
{
|
||||||
|
return { blank_insert_t<void>() };
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Table>
|
template<typename Table>
|
||||||
constexpr auto insert_into(Table table)
|
constexpr auto insert_into(Table table)
|
||||||
-> decltype(blank_insert_t<void>().into(table))
|
-> decltype(blank_insert_t<void>().into(table))
|
||||||
@ -188,6 +192,13 @@ namespace sqlpp
|
|||||||
return { blank_insert_t<void>().into(table) };
|
return { blank_insert_t<void>().into(table) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Database>
|
||||||
|
constexpr auto dynamic_insert(const Database&)
|
||||||
|
-> decltype(blank_insert_t<Database>())
|
||||||
|
{
|
||||||
|
return { blank_insert_t<Database>() };
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Database, typename Table>
|
template<typename Database, typename Table>
|
||||||
constexpr auto dynamic_insert_into(const Database&, Table table)
|
constexpr auto dynamic_insert_into(const Database&, Table table)
|
||||||
-> decltype(blank_insert_t<Database>().into(table))
|
-> decltype(blank_insert_t<Database>().into(table))
|
||||||
|
@ -31,88 +31,90 @@
|
|||||||
#include <sqlpp11/parameter_list.h>
|
#include <sqlpp11/parameter_list.h>
|
||||||
#include <sqlpp11/prepared_remove.h>
|
#include <sqlpp11/prepared_remove.h>
|
||||||
#include <sqlpp11/vendor/noop.h>
|
#include <sqlpp11/vendor/noop.h>
|
||||||
|
#warning: need to use another table provider, since delete can be used with several tables
|
||||||
#include <sqlpp11/vendor/single_table.h>
|
#include <sqlpp11/vendor/single_table.h>
|
||||||
#include <sqlpp11/vendor/extra_tables.h>
|
#include <sqlpp11/vendor/extra_tables.h>
|
||||||
#include <sqlpp11/vendor/using.h>
|
#include <sqlpp11/vendor/using.h>
|
||||||
#include <sqlpp11/vendor/where.h>
|
#include <sqlpp11/vendor/where.h>
|
||||||
#include <sqlpp11/vendor/policy_update.h>
|
#include <sqlpp11/vendor/policy_update.h>
|
||||||
#include <sqlpp11/detail/arg_selector.h>
|
|
||||||
|
#include <sqlpp11/detail/get_last.h>
|
||||||
|
#include <sqlpp11/detail/pick_arg.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
template<typename Db,
|
template<typename Db, typename... Policies>
|
||||||
typename... Policies
|
|
||||||
>
|
|
||||||
struct remove_t;
|
struct remove_t;
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template<typename Db = void,
|
template<typename Db = void, typename... Policies>
|
||||||
typename Table = vendor::no_single_table_t,
|
|
||||||
typename Using = vendor::no_using_t,
|
|
||||||
typename ExtraTables = vendor::no_extra_tables_t,
|
|
||||||
typename Where = vendor::no_where_t
|
|
||||||
>
|
|
||||||
struct remove_policies_t
|
struct remove_policies_t
|
||||||
{
|
{
|
||||||
using _database_t = Db;
|
using _database_t = Db;
|
||||||
using _table_t = Table;
|
|
||||||
using _using_t = Using;
|
|
||||||
using _extra_tables_t = ExtraTables;
|
|
||||||
using _where_t = Where;
|
|
||||||
|
|
||||||
using _statement_t = remove_t<Db, Table, Using, ExtraTables, Where>;
|
using _statement_t = remove_t<Db, Policies...>;
|
||||||
|
|
||||||
struct _methods_t:
|
struct _methods_t: public Policies::template _methods_t<remove_policies_t>...
|
||||||
public _using_t::template _methods_t<remove_policies_t>,
|
|
||||||
public _extra_tables_t::template _methods_t<remove_policies_t>,
|
|
||||||
public _where_t::template _methods_t<remove_policies_t>
|
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename Needle, typename Replacement, typename... Policies>
|
template<typename Needle, typename Replacement>
|
||||||
struct _policies_update_t
|
struct _policies_update_t
|
||||||
{
|
{
|
||||||
|
static_assert(detail::is_element_of<Needle, make_type_set_t<Policies...>>::value, "policies update for non-policy class detected");
|
||||||
using type = remove_t<Db, vendor::policy_update_t<Policies, Needle, Replacement>...>;
|
using type = remove_t<Db, vendor::policy_update_t<Policies, Needle, Replacement>...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Needle, typename Replacement>
|
template<typename Needle, typename Replacement>
|
||||||
using _new_statement_t = typename _policies_update_t<Needle, Replacement, Table, Using, ExtraTables, Where>::type;
|
using _new_statement_t = typename _policies_update_t<Needle, Replacement>::type;
|
||||||
|
|
||||||
using _known_tables = detail::make_joined_set_t<typename _table_t::_table_set, typename _using_t::_table_set, typename _extra_tables_t::_table_set>;
|
using _all_required_tables = detail::make_joined_set_t<required_tables_of<Policies>...>;
|
||||||
|
using _all_provided_tables = detail::make_joined_set_t<provided_tables_of<Policies>...>;
|
||||||
|
using _all_extra_tables = detail::make_joined_set_t<extra_tables_of<Policies>...>;
|
||||||
|
|
||||||
|
using _known_tables = detail::make_joined_set_t<_all_provided_tables, _all_extra_tables>;
|
||||||
|
|
||||||
template<typename Expression>
|
template<typename Expression>
|
||||||
using _no_unknown_tables = detail::is_subset_of<typename Expression::_table_set, _known_tables>;
|
using _no_unknown_tables = detail::is_subset_of<required_tables_of<Expression>, _known_tables>;
|
||||||
|
|
||||||
|
// The tables not covered by the from.
|
||||||
|
using _required_tables = detail::make_difference_set_t<
|
||||||
|
_all_required_tables,
|
||||||
|
_all_provided_tables // Hint: extra_tables are not used here because they are just a helper for dynamic .add_*()
|
||||||
|
>;
|
||||||
|
|
||||||
|
using _traits = make_traits<no_value_t>; // FIXME
|
||||||
|
|
||||||
|
struct _recursive_traits
|
||||||
|
{
|
||||||
|
using _parameters = std::tuple<>; // FIXME
|
||||||
|
using _required_tables = _required_tables;
|
||||||
|
using _provided_tables = detail::type_set<>;
|
||||||
|
using _extra_tables = detail::type_set<>;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// REMOVE
|
// REMOVE
|
||||||
template<typename Db,
|
template<typename Db, typename... Policies>
|
||||||
typename... Policies
|
|
||||||
>
|
|
||||||
struct remove_t:
|
struct remove_t:
|
||||||
|
public Policies...,
|
||||||
public detail::remove_policies_t<Db, Policies...>::_methods_t
|
public detail::remove_policies_t<Db, Policies...>::_methods_t
|
||||||
{
|
{
|
||||||
using _policies_t = typename detail::remove_policies_t<Db, Policies...>;
|
using _policies_t = typename detail::remove_policies_t<Db, Policies...>;
|
||||||
using _database_t = typename _policies_t::_database_t;
|
using _database_t = typename _policies_t::_database_t;
|
||||||
using _table_t = typename _policies_t::_table_t;
|
|
||||||
using _using_t = typename _policies_t::_using_t;
|
|
||||||
using _extra_tables_t = typename _policies_t::_extra_tables_t;
|
|
||||||
using _where_t = typename _policies_t::_where_t;
|
|
||||||
|
|
||||||
using _is_dynamic = typename std::conditional<std::is_same<_database_t, void>::value, std::false_type, std::true_type>::type;
|
using _is_dynamic = typename std::conditional<std::is_same<_database_t, void>::value, std::false_type, std::true_type>::type;
|
||||||
|
|
||||||
using _parameter_tuple_t = std::tuple<Policies...>;
|
|
||||||
using _parameter_list_t = typename make_parameter_list_t<remove_t>::type;
|
using _parameter_list_t = typename make_parameter_list_t<remove_t>::type;
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
remove_t()
|
constexpr remove_t()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename Statement, typename T>
|
template<typename Statement, typename Term>
|
||||||
remove_t(Statement s, T t):
|
remove_t(Statement statement, Term term):
|
||||||
_table(detail::arg_selector<_table_t>::_(s._table, t)),
|
Policies(detail::pick_arg<Policies>(statement, term))...
|
||||||
_using(detail::arg_selector<_using_t>::_(s._using, t)),
|
|
||||||
_where(detail::arg_selector<_where_t>::_(s._where, t))
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
remove_t(const remove_t&) = default;
|
remove_t(const remove_t&) = default;
|
||||||
@ -132,18 +134,15 @@ namespace sqlpp
|
|||||||
return _parameter_list_t::size::value;
|
return _parameter_list_t::size::value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename A>
|
|
||||||
struct is_table_subset_of_table
|
|
||||||
{
|
|
||||||
static constexpr bool value = ::sqlpp::detail::is_subset_of<typename A::_table_set, typename _table_t::_table_set>::value;
|
|
||||||
};
|
|
||||||
|
|
||||||
void _check_consistency() const
|
void _check_consistency() const
|
||||||
{
|
{
|
||||||
|
#warning reactivate checks
|
||||||
|
#if 0
|
||||||
static_assert(is_where_t<_where_t>::value, "cannot run update without having a where condition, use .where(true) to update all rows");
|
static_assert(is_where_t<_where_t>::value, "cannot run update without having a where condition, use .where(true) to update all rows");
|
||||||
|
|
||||||
// FIXME: Read more details about what is allowed and what not in SQL DELETE
|
// FIXME: Read more details about what is allowed and what not in SQL DELETE
|
||||||
static_assert(is_table_subset_of_table<_where_t>::value, "where requires additional tables");
|
static_assert(is_table_subset_of_table<_where_t>::value, "where requires additional tables");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Database>
|
template<typename Database>
|
||||||
@ -163,10 +162,6 @@ namespace sqlpp
|
|||||||
|
|
||||||
return {{}, db.prepare_remove(*this)};
|
return {{}, db.prepare_remove(*this)};
|
||||||
}
|
}
|
||||||
|
|
||||||
_table_t _table;
|
|
||||||
_using_t _using;
|
|
||||||
_where_t _where;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace vendor
|
namespace vendor
|
||||||
@ -179,31 +174,46 @@ namespace sqlpp
|
|||||||
static Context& _(const T& t, Context& context)
|
static Context& _(const T& t, Context& context)
|
||||||
{
|
{
|
||||||
context << "DELETE FROM ";
|
context << "DELETE FROM ";
|
||||||
serialize(t._table, context);
|
using swallow = int[];
|
||||||
serialize(t._using, context);
|
(void) swallow{(serialize(static_cast<const Policies&>(t), context), 0)...};
|
||||||
serialize(t._where, context);
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Database, typename... Policies>
|
template<typename Database>
|
||||||
using make_remove_t = typename detail::remove_policies_t<Database, Policies...>::_statement_t;
|
using blank_remove_t = remove_t<Database,
|
||||||
|
vendor::no_single_table_t,
|
||||||
|
vendor::no_using_t,
|
||||||
|
vendor::no_extra_tables_t,
|
||||||
|
vendor::no_where_t>;
|
||||||
|
|
||||||
|
constexpr auto remove()
|
||||||
|
-> blank_remove_t<void>
|
||||||
|
{
|
||||||
|
return { blank_remove_t<void>() };
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Table>
|
template<typename Table>
|
||||||
constexpr auto remove_from(Table table)
|
constexpr auto remove_from(Table table)
|
||||||
-> make_remove_t<void, vendor::single_table_t<void, Table>>
|
-> decltype(blank_remove_t<void>().from(table))
|
||||||
{
|
{
|
||||||
return { make_remove_t<void>(), vendor::single_table_t<void, Table>{table} };
|
return { blank_remove_t<void>().from(table) };
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Database>
|
||||||
|
constexpr auto dynamic_remove(const Database&)
|
||||||
|
-> decltype(blank_remove_t<Database>())
|
||||||
|
{
|
||||||
|
return { blank_remove_t<Database>() };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Database, typename Table>
|
template<typename Database, typename Table>
|
||||||
constexpr auto dynamic_remove_from(const Database&, Table table)
|
constexpr auto dynamic_remove_from(const Database&, Table table)
|
||||||
-> make_remove_t<Database, vendor::single_table_t<void, Table>>
|
-> decltype(blank_remove_t<Database>().from(table))
|
||||||
{
|
{
|
||||||
return { make_remove_t<Database>(), vendor::single_table_t<void, Table>{table} };
|
return { blank_remove_t<Database>().from(table) };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
7
include/sqlpp11/vendor/expression_fwd.h
vendored
7
include/sqlpp11/vendor/expression_fwd.h
vendored
@ -29,6 +29,13 @@
|
|||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
struct boolean;
|
||||||
|
struct integral;
|
||||||
|
struct floating_point;
|
||||||
|
}
|
||||||
|
|
||||||
namespace vendor
|
namespace vendor
|
||||||
{
|
{
|
||||||
namespace op
|
namespace op
|
||||||
|
2
include/sqlpp11/vendor/noop.h
vendored
2
include/sqlpp11/vendor/noop.h
vendored
@ -28,6 +28,8 @@
|
|||||||
#define SQLPP_NOOP_H
|
#define SQLPP_NOOP_H
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <sqlpp11/no_value.h>
|
||||||
|
#include <sqlpp11/vendor/serializer.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
8
include/sqlpp11/vendor/single_table.h
vendored
8
include/sqlpp11/vendor/single_table.h
vendored
@ -80,6 +80,14 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
return { *static_cast<typename Policies::_statement_t*>(this), single_table_t<void, Args...>{args...} };
|
return { *static_cast<typename Policies::_statement_t*>(this), single_table_t<void, Args...>{args...} };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#warning: remove can operate on several tables at once, so it should not use single_table anyway
|
||||||
|
template<typename... Args>
|
||||||
|
auto from(Args... args)
|
||||||
|
-> _new_statement_t<single_table_t<void, Args...>>
|
||||||
|
{
|
||||||
|
return { *static_cast<typename Policies::_statement_t*>(this), single_table_t<void, Args...>{args...} };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
17
include/sqlpp11/vendor/using.h
vendored
17
include/sqlpp11/vendor/using.h
vendored
@ -41,9 +41,10 @@ namespace sqlpp
|
|||||||
template<typename Database, typename... Tables>
|
template<typename Database, typename... Tables>
|
||||||
struct using_t
|
struct using_t
|
||||||
{
|
{
|
||||||
using _is_using = std::true_type;
|
using _traits = make_traits<no_value_t, ::sqlpp::tag::using_>;
|
||||||
|
using _recursive_traits = make_recursive_traits<Tables...>;
|
||||||
|
|
||||||
using _is_dynamic = typename std::conditional<std::is_same<Database, void>::value, std::false_type, std::true_type>::type;
|
using _is_dynamic = typename std::conditional<std::is_same<Database, void>::value, std::false_type, std::true_type>::type;
|
||||||
using _parameter_tuple_t = std::tuple<Tables...>;
|
|
||||||
|
|
||||||
static_assert(_is_dynamic::value or sizeof...(Tables), "at least one table argument required in using()");
|
static_assert(_is_dynamic::value or sizeof...(Tables), "at least one table argument required in using()");
|
||||||
|
|
||||||
@ -51,8 +52,7 @@ namespace sqlpp
|
|||||||
|
|
||||||
static_assert(::sqlpp::detail::all_t<is_table_t<Tables>::value...>::value, "at least one argument is not an table in using()");
|
static_assert(::sqlpp::detail::all_t<is_table_t<Tables>::value...>::value, "at least one argument is not an table in using()");
|
||||||
|
|
||||||
using _provided_tables = detail::type_set<>;
|
using_t& _using() { return *this; }
|
||||||
using _required_tables = ::sqlpp::detail::make_joined_set_t<typename Tables::_required_tables...>;
|
|
||||||
|
|
||||||
using_t(Tables... tables):
|
using_t(Tables... tables):
|
||||||
_tables(tables...)
|
_tables(tables...)
|
||||||
@ -82,7 +82,7 @@ namespace sqlpp
|
|||||||
template<typename Table>
|
template<typename Table>
|
||||||
void _add_using_impl(Table table, const std::true_type&)
|
void _add_using_impl(Table table, const std::true_type&)
|
||||||
{
|
{
|
||||||
return static_cast<typename Policies::_statement_t*>(this)->_using._dynamic_tables.emplace_back(table);
|
return static_cast<typename Policies::_statement_t*>(this)->_using()._dynamic_tables.emplace_back(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Table>
|
template<typename Table>
|
||||||
@ -90,15 +90,14 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
_parameter_tuple_t _tables;
|
std::tuple<Tables...> _tables;
|
||||||
vendor::interpretable_list_t<Database> _dynamic_tables;
|
vendor::interpretable_list_t<Database> _dynamic_tables;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct no_using_t
|
struct no_using_t
|
||||||
{
|
{
|
||||||
using _is_noop = std::true_type;
|
using _traits = make_traits<no_value_t, ::sqlpp::tag::where>;
|
||||||
using _provided_tables = detail::type_set<>;
|
using _recursive_traits = make_recursive_traits<>;
|
||||||
using _required_tables = ::sqlpp::detail::type_set<>;
|
|
||||||
|
|
||||||
template<typename Policies>
|
template<typename Policies>
|
||||||
struct _methods_t
|
struct _methods_t
|
||||||
|
@ -7,8 +7,8 @@ macro (build_and_run arg)
|
|||||||
endmacro ()
|
endmacro ()
|
||||||
|
|
||||||
#build_and_run(InterpretTest)
|
#build_and_run(InterpretTest)
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user