0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Reduced compiler error spew dramatically for from and having.

This commit is contained in:
rbock 2014-11-27 22:16:12 +01:00
parent 0e27cd7138
commit 443614a0e7
8 changed files with 169 additions and 65 deletions

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2013-2014, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_BAD_STATEMENT_H
#define SQLPP_BAD_STATEMENT_H
namespace sqlpp
{
struct bad_statement
{
template<typename... T>
bad_statement(T&&...) {}
};
}
#endif

View File

@ -163,33 +163,42 @@ namespace sqlpp
struct _methods_t
{
using _database_t = typename Policies::_database_t;
template<typename T>
using _new_statement_t = new_statement<Policies, no_from_t, T>;
template<typename... T>
using _check = detail::all_t<is_table_t<T>::value...>;
template<typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_from_t, T>;
using _consistency_check = consistent_t;
template<typename... Tables>
auto from(Tables... tables) const
-> _new_statement_t<from_t<void, Tables...>>
-> _new_statement_t<_check<Tables...>, from_t<void, Tables...>>
{
static_assert(_check<Tables...>::value, "at least one argument is not a table or join in from()");
static_assert(sizeof...(Tables), "at least one table or join argument required in from()");
return _from_impl<void>(tables...);
return _from_impl<void>(_check<Tables...>{}, tables...);
}
template<typename... Tables>
auto dynamic_from(Tables... tables) const
-> _new_statement_t<from_t<_database_t, Tables...>>
-> _new_statement_t<_check<Tables...>, from_t<_database_t, Tables...>>
{
static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement");
return _from_impl<_database_t>(tables...);
static_assert(_check<Tables...>::value, "at least one argument is not a table or join in from()");
return _from_impl<_database_t>(_check<Tables...>{}, tables...);
}
private:
template<typename Database, typename... Tables>
auto _from_impl(Tables... tables) const
-> _new_statement_t<from_t<Database, Tables...>>
auto _from_impl(const std::false_type&, Tables... tables) const
-> _new_statement_t<std::false_type, from_t<Database, Tables...>>;
template<typename Database, typename... Tables>
auto _from_impl(const std::true_type&, Tables... tables) const
-> _new_statement_t<std::true_type, from_t<Database, Tables...>>
{
static_assert(detail::all_t<is_table_t<Tables>::value...>::value, "at least one argument is not a table or join in from()");
static_assert(required_tables_of<from_t<Database, Tables...>>::size::value == 0, "at least one table depends on another table");
static constexpr std::size_t _number_of_tables = detail::sum(provided_tables_of<Tables>::size::value...);

View File

@ -75,12 +75,6 @@ namespace sqlpp
using _is_dynamic = is_database<Database>;
static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()");
static_assert(not detail::has_duplicates<Expressions...>::value, "at least one duplicate argument detected in group_by()");
static_assert(detail::all_t<is_expression_t<Expressions>::value...>::value, "at least one argument is not an expression in group_by()");
// Data
using _data_t = group_by_data_t<Database, Expressions...>;
@ -189,20 +183,32 @@ namespace sqlpp
using _consistency_check = consistent_t;
template<typename... Args>
auto group_by(Args... args) const
-> _new_statement_t<group_by_t<void, Args...>>
template<typename... Expressions>
auto group_by(Expressions... expressions) const
-> _new_statement_t<group_by_t<void, Expressions...>>
{
return { static_cast<const derived_statement_t<Policies>&>(*this), group_by_data_t<void, Args...>{args...} };
static_assert(sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()");
return _group_by_impl<void>(expressions...);
}
template<typename... Args>
auto dynamic_group_by(Args... args) const
-> _new_statement_t<group_by_t<_database_t, Args...>>
template<typename... Expressions>
auto dynamic_group_by(Expressions... expressions) const
-> _new_statement_t<group_by_t<_database_t, Expressions...>>
{
static_assert(not std::is_same<_database_t, void>::value, "dynamic_group_by must not be called in a static statement");
return { static_cast<const derived_statement_t<Policies>&>(*this), group_by_data_t<_database_t, Args...>{args...} };
return _group_by_impl<_database_t>(expressions...);
}
private:
template<typename Database, typename... Expressions>
auto _group_by_impl(Expressions... expressions) const
-> _new_statement_t<group_by_t<_database_t, Expressions...>>
{
static_assert(not detail::has_duplicates<Expressions...>::value, "at least one duplicate argument detected in group_by()");
static_assert(detail::all_t<is_expression_t<Expressions>::value...>::value, "at least one argument is not an expression in group_by()");
return { static_cast<const derived_statement_t<Policies>&>(*this), group_by_data_t<Database, Expressions...>{expressions...} };
};
};
};

View File

@ -74,9 +74,6 @@ namespace sqlpp
using _is_dynamic = is_database<Database>;
static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in having()");
static_assert(detail::all_t<is_expression_t<Expressions>::value...>::value, "at least one argument is not an expression in having()");
// Data
using _data_t = having_data_t<Database, Expressions...>;
@ -182,25 +179,46 @@ namespace sqlpp
struct _methods_t
{
using _database_t = typename Policies::_database_t;
template<typename T>
using _new_statement_t = new_statement<Policies, no_having_t, T>;
template<typename... T>
using _check = detail::all_t<is_expression_t<T>::value...>;
template<typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_having_t, T>;
using _consistency_check = consistent_t;
template<typename... Args>
auto having(Args... args) const
-> _new_statement_t<having_t<void, Args...>>
template<typename... Expressions>
auto having(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, having_t<void, Expressions...>>
{
return { static_cast<const derived_statement_t<Policies>&>(*this), having_data_t<void, Args...>{args...} };
static_assert(_check<Expressions...>::value, "at least one argument is not an expression in having()");
static_assert(sizeof...(Expressions), "at least one expression argument required in having()");
return _having_impl<void>(_check<Expressions...>{}, expressions...);
}
template<typename... Args>
auto dynamic_having(Args... args) const
-> _new_statement_t<having_t<_database_t, Args...>>
template<typename... Expressions>
auto dynamic_having(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, having_t<_database_t, Expressions...>>
{
static_assert(_check<Expressions...>::value, "at least one argument is not an expression in having()");
static_assert(not std::is_same<_database_t, void>::value, "dynamic_having must not be called in a static statement");
return { static_cast<const derived_statement_t<Policies>&>(*this), having_data_t<_database_t, Args...>{args...} };
return _having_impl<_database_t>(_check<Expressions...>{}, expressions...);
}
private:
template<typename Database, typename... Expressions>
auto _having_impl(const std::false_type&, Expressions... expressions) const
-> bad_statement;
template<typename Database, typename... Expressions>
auto _having_impl(const std::true_type&, Expressions... expressions) const
-> _new_statement_t<std::true_type, having_t<Database, Expressions...>>
{
return { static_cast<const derived_statement_t<Policies>&>(*this), having_data_t<_database_t, Expressions...>{expressions...} };
}
};
};

View File

@ -75,12 +75,6 @@ namespace sqlpp
using _is_dynamic = is_database<Database>;
static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in order_by()");
static_assert(not detail::has_duplicates<Expressions...>::value, "at least one duplicate argument detected in order_by()");
static_assert(detail::all_t<is_expression_t<Expressions>::value...>::value, "at least one argument is not an expression in order_by()");
// Data
using _data_t = order_by_data_t<Database, Expressions...>;
@ -98,12 +92,12 @@ namespace sqlpp
void add(Expression expression)
{
static_assert(_is_dynamic::value, "add() must not be called for static order_by");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in order_by::add()");
static_assert(is_sort_order_t<Expression>::value, "invalid expression argument in order_by::add()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in order_by::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
_serialize_check::_();
using ok = detail::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
using ok = detail::all_t<_is_dynamic::value, is_sort_order_t<Expression>::value, _serialize_check::type::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
@ -189,20 +183,32 @@ namespace sqlpp
using _consistency_check = consistent_t;
template<typename... Args>
auto order_by(Args... args) const
-> _new_statement_t<order_by_t<void, Args...>>
template<typename... Expressions>
auto order_by(Expressions... expressions) const
-> _new_statement_t<order_by_t<void, Expressions...>>
{
return { static_cast<const derived_statement_t<Policies>&>(*this), order_by_data_t<void, Args...>{args...} };
static_assert(sizeof...(Expressions), "at least one expression (e.g. a column) required in order_by()");
return _order_by_impl<void>(expressions...);
}
template<typename... Args>
auto dynamic_order_by(Args... args) const
-> _new_statement_t<order_by_t<_database_t, Args...>>
template<typename... Expressions>
auto dynamic_order_by(Expressions... expressions) const
-> _new_statement_t<order_by_t<_database_t, Expressions...>>
{
static_assert(not std::is_same<_database_t, void>::value, "dynamic_order_by must not be called in a static statement");
return { static_cast<const derived_statement_t<Policies>&>(*this), order_by_data_t<_database_t, Args...>{args...} };
return _order_by_impl<_database_t>(expressions...);
}
private:
template<typename Database, typename... Expressions>
auto _order_by_impl(Expressions... expressions) const
-> _new_statement_t<order_by_t<_database_t, Expressions...>>
{
static_assert(not detail::has_duplicates<Expressions...>::value, "at least one duplicate argument detected in order_by()");
static_assert(detail::all_t<is_sort_order_t<Expressions>::value...>::value, "at least one argument is not an expression in order_by()");
return { static_cast<const derived_statement_t<Policies>&>(*this), order_by_data_t<Database, Expressions...>{expressions...} };
};
};
};

View File

@ -28,6 +28,7 @@
#define SQLPP_POLICY_UPDATE_H
#include <sqlpp11/wrong.h>
#include <sqlpp11/bad_statement.h>
namespace sqlpp
{
@ -53,6 +54,21 @@ namespace sqlpp
template<typename Policies, typename Needle, typename Replacement>
using new_statement = typename Policies::template _new_statement_t<Needle, Replacement>;
template<bool, typename Policies, typename Needle, typename Replacement>
struct new_statement_impl
{
using type = typename Policies::template _new_statement_t<Needle, Replacement>;
};
template<typename Policies, typename Needle, typename Replacement>
struct new_statement_impl<false, Policies, Needle, Replacement>
{
using type = bad_statement;
};
template<bool Check, typename Policies, typename Needle, typename Replacement>
using new_statement_t = typename new_statement_impl<Check, Policies, Needle, Replacement>::type;
}
#endif

View File

@ -64,10 +64,6 @@ namespace sqlpp
using _is_dynamic = is_database<Database>;
static_assert(not detail::has_duplicates<Flags...>::value, "at least one duplicate argument detected in select flag list");
static_assert(detail::all_t<is_select_flag_t<Flags>::value...>::value, "at least one argument is not a select flag in select flag list");
// Data
using _data_t = select_flag_list_data_t<Database, Flags...>;
@ -175,20 +171,32 @@ namespace sqlpp
using _consistency_check = consistent_t;
template<typename... Args>
auto flags(Args... args) const
-> _new_statement_t<select_flag_list_t<void, Args...>>
template<typename... Flags>
auto flags(Flags... flags) const
-> _new_statement_t<select_flag_list_t<void, Flags...>>
{
return { static_cast<const derived_statement_t<Policies>&>(*this), select_flag_list_data_t<void, Args...>{args...} };
return _flags_impl<void>(flags...);
}
template<typename... Args>
auto dynamic_flags(Args... args) const
-> _new_statement_t<select_flag_list_t<_database_t, Args...>>
template<typename... Flags>
auto dynamic_flags(Flags... flags) const
-> _new_statement_t<select_flag_list_t<_database_t, Flags...>>
{
static_assert(not std::is_same<_database_t, void>::value, "dynamic_flags must not be called in a static statement");
return { static_cast<const derived_statement_t<Policies>&>(*this), select_flag_list_data_t<_database_t, Args...>{args...} };
return _flags_impl<_database_t>(flags...);
}
private:
template<typename Database, typename... Flags>
auto _flags_impl(Flags... flags) const
-> _new_statement_t<select_flag_list_t<Database, Flags...>>
{
static_assert(detail::all_t<is_select_flag_t<Flags>::value...>::value, "at least one argument is not a select flag in select flag list");
static_assert(not detail::has_duplicates<Flags...>::value, "at least one duplicate argument detected in select flag list");
return { static_cast<const derived_statement_t<Policies>&>(*this), select_flag_list_data_t<Database, Flags...>{flags...} };
}
};
};

View File

@ -41,7 +41,7 @@ namespace sqlpp
template<typename Expression, sort_type SortType>
struct sort_order_t
{
using _traits = make_traits<no_value_t, tag::is_sort_order, tag::is_expression>;
using _traits = make_traits<no_value_t, tag::is_sort_order>;
using _recursive_traits = make_recursive_traits<Expression>;
Expression _expression;