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

Finished replacing serializer_t

This commit is contained in:
Roland Bock 2021-08-01 12:54:46 +02:00
parent 2cab1fa681
commit 68021772c2
55 changed files with 416 additions and 826 deletions

View File

@ -47,17 +47,9 @@ namespace sqlpp
SQLPP_PORTABLE_STATIC_ASSERT(assert_no_stand_alone_all_of_t, "all_of(table) seems to be used outside of select");
// FIXME: Do we need this?
template <typename Context, typename Table>
struct serializer_t<Context, all_of_t<Table>>
{
using _serialize_check = assert_no_stand_alone_all_of_t;
using T = all_of_t<Table>;
static Context& _(const T& /*unused*/, const Context& /*unused*/)
{
_serialize_check{};
}
};
Context& serialize(const all_of_t<Table>& t, Context& context);
} // namespace sqlpp
#endif

View File

@ -53,19 +53,13 @@ namespace sqlpp
};
template <typename Context, typename Select>
struct serializer_t<Context, any_t<Select>>
{
using _serialize_check = serialize_check_of<Context, Select>;
using T = any_t<Select>;
static Context& _(const T& t, Context& context)
Context& serialize(const any_t<Select>& t, Context& context)
{
context << "ANY(";
serialize(t._select, context);
context << ")";
return context;
}
};
template <typename T>
auto any(T t) -> any_t<wrap_operand_t<T>>

View File

@ -62,19 +62,13 @@ namespace sqlpp
};
template <typename Context, typename Lhs, typename Rhs>
struct serializer_t<Context, assignment_t<Lhs, Rhs>>
{
using T = assignment_t<Lhs, Rhs>;
using _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
static Context& _(const T& t, Context& context)
Context& serialize(const assignment_t<Lhs, Rhs>& t, Context& context)
{
serialize(simple_column(t._lhs), context);
context << "=";
serialize_operand(t._rhs, context);
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -46,13 +46,7 @@ namespace sqlpp
};
template <typename Context, typename ValueType>
struct serializer_t<Context, bad_expression<ValueType>>
{
using _serialize_check = assert_valid_operands;
using T = bad_expression<ValueType>;
static Context& _(const T&, Context&);
};
Context serialize(const bad_expression<ValueType>& t, Context& context);
} // namespace sqlpp
#endif

View File

@ -68,16 +68,10 @@ namespace sqlpp
}
template <typename Context, typename Database>
struct serializer_t<Context, boolean_expression_t<Database>>
{
using _serialize_check = consistent_t;
using T = boolean_expression_t<Database>;
static Context& _(const T& t, Context& context)
Context& serialize(const boolean_expression_t<Database>& t, Context& context)
{
return serialize(t._expr, context);
}
};
} // namespace sqlpp
#endif

View File

@ -151,12 +151,7 @@ namespace sqlpp
};
template <typename Context, typename When, typename Then, typename Else>
struct serializer_t<Context, case_t<When, Then, Else>>
{
using _serialize_check = serialize_check_of<When, Then, Else>;
using T = case_t<When, Then, Else>;
static Context& _(const T& t, Context& context)
Context& serialize(const case_t<When, Then, Else>& t, Context& context)
{
context << "(CASE WHEN ";
serialize(t._when, context);
@ -167,7 +162,6 @@ namespace sqlpp
context << " END)";
return context;
}
};
namespace detail
{

View File

@ -63,12 +63,7 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Flag, typename Lhs, typename Rhs>
struct serializer_t<Context, cte_union_t<Flag, Lhs, Rhs>>
{
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
using T = cte_union_t<Flag, Lhs, Rhs>;
static Context& _(const T& t, Context& context)
Context& serialize(const cte_union_t<Flag, Lhs, Rhs>& t, Context& context)
{
serialize(t._lhs, context);
context << " UNION ";
@ -77,7 +72,6 @@ namespace sqlpp
serialize(t._rhs, context);
return context;
}
};
template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct cte_t;
@ -229,19 +223,14 @@ namespace sqlpp
};
template <typename Context, typename AliasProvider, typename Statement, typename... ColumnSpecs>
struct serializer_t<Context, cte_t<AliasProvider, Statement, ColumnSpecs...>>
Context& serialize(const cte_t<AliasProvider, Statement, ColumnSpecs...>& t, Context& context)
{
using _serialize_check = serialize_check_of<Context, Statement>;
using T = cte_t<AliasProvider, Statement, ColumnSpecs...>;
static Context& _(const T& t, Context& context)
{
context << name_of<T>::template char_ptr<Context>() << " AS (";
serialize(t._statement, context);
context << ")";
return context;
}
};
// The cte_t is displayed as AliasProviderName except within the with:
// - the with needs the
@ -273,17 +262,11 @@ namespace sqlpp
};
template <typename Context, typename AliasProvider>
struct serializer_t<Context, cte_ref_t<AliasProvider>>
Context& serialize(const cte_ref_t<AliasProvider>&, Context& context)
{
using _serialize_check = consistent_t;
using T = cte_ref_t<AliasProvider>;
static Context& _(const T& /*unused*/, Context& context)
{
context << name_of<T>::template char_ptr<Context>();
context << name_of<cte_ref_t<AliasProvider>>::template char_ptr<Context>();
return context;
}
};
template <typename AliasProvider>
auto cte(const AliasProvider & /*unused*/) -> cte_ref_t<AliasProvider>

View File

@ -123,17 +123,11 @@ namespace sqlpp
};
template <typename Context, typename Database, typename... Parts>
struct serializer_t<Context, custom_query_t<Database, Parts...>>
{
using _serialize_check = serialize_check_of<Context, Parts...>;
using T = custom_query_t<Database, Parts...>;
static Context& _(const T& t, Context& context)
Context serialize(const custom_query_t<Database, Parts...>& t, Context& context)
{
interpret_tuple_without_braces(t._parts, " ", context);
return context;
}
};
template <typename... Parts>
auto custom_query(Parts... parts) -> custom_query_t<void, wrap_operand_t<Parts>...>

View File

@ -38,17 +38,11 @@ namespace sqlpp
};
template <typename Context>
struct serializer_t<Context, default_value_t>
{
using _serialize_check = consistent_t;
using Operand = default_value_t;
static Context& _(const Operand& /*unused*/, Context& context)
Context& serialize(const default_value_t&, Context& context)
{
context << "DEFAULT";
return context;
}
};
constexpr default_value_t default_value = {};
} // namespace sqlpp

View File

@ -157,17 +157,11 @@ namespace sqlpp
// Interpreters
template <typename Context>
struct serializer_t<Context, for_update_data_t>
{
using _serialize_check = serialize_check_of<Context>;
using T = for_update_data_t;
static Context& _(const T& /*unused*/, Context& context)
Context& serialize(const for_update_data_t&, Context& context)
{
context << " FOR UPDATE ";
return context;
}
};
template <typename T>
auto for_update(T&& t) -> decltype(statement_t<void, no_for_update_t>().for_update(std::forward<T>(t)))

View File

@ -85,8 +85,6 @@ namespace sqlpp
assert_from_add_unique_names>,
static_check_t<detail::is_subset_of<_required_tables, _known_tables>::value,
assert_from_add_no_required_tables>
// FIXME: Replace this with consistency check?
// sqlpp::serialize_check_t<serializer_context_of<typename From::_database_t>, DynamicJoin>
>;
};

View File

@ -96,12 +96,7 @@ namespace sqlpp
};
template <typename Context, typename Container>
struct serializer_t<Context, value_list_t<Container>>
{
using _serialize_check = serialize_check_of<Context, wrap_operand_t<typename Container::value_type>>;
using T = value_list_t<Container>;
static Context& _(const T& t, Context& context)
Context& serialize(const value_list_t<Container>& t, Context& context)
{
if (t._container.size() == 1)
{
@ -124,7 +119,6 @@ namespace sqlpp
}
return context;
}
};
template <typename Container>
auto value_list(Container c) -> value_list_t<Container>

View File

@ -90,10 +90,7 @@ namespace sqlpp
static_assert(is_expression_t<Expression>::value, "invalid expression argument in group_by::add()");
static_assert(Policies::template _no_unknown_tables<Expression>::value,
"expression uses tables unknown to this statement in group_by::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
_serialize_check{};
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -91,10 +91,7 @@ namespace sqlpp
static_assert(is_expression_t<Expr>::value, "invalid expression argument in having::add()");
static_assert(Policies::template _no_unknown_tables<Expr>::value,
"expression uses tables unknown to this statement in having::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expr>;
_serialize_check{};
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
@ -292,12 +289,7 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Database, typename Expression>
struct serializer_t<Context, having_data_t<Database, Expression>>
{
using _serialize_check = serialize_check_of<Context, Expression>;
using T = having_data_t<Database, Expression>;
static Context& _(const T& t, Context& context)
Context& serialize(const having_data_t<Database, Expression>& t, Context& context)
{
context << " HAVING ";
serialize(t._expression, context);
@ -308,7 +300,6 @@ namespace sqlpp
interpret_list(t._dynamic_expressions, " AND ", context);
return context;
}
};
template <typename T>
auto having(T&& t) -> decltype(statement_t<void, no_having_t>().having(std::forward<T>(t)))

View File

@ -46,16 +46,10 @@ namespace sqlpp
};
template <typename Context, typename Clause>
struct serializer_t<Context, hidden_t<Clause>>
{
using _serialize_check = consistent_t;
using T = hidden_t<Clause>;
static Context& _(const T& /*unused*/, Context& context)
Context& serialize(const hidden_t<Clause>&, Context& context)
{
return context;
}
};
template <typename Clause>
auto hidden(Clause part) -> hidden_t<Clause>

View File

@ -73,12 +73,7 @@ namespace sqlpp
};
template <typename Context, typename Operand, typename... Args>
struct serializer_t<Context, in_t<Operand, Args...>>
{
using _serialize_check = serialize_check_of<Context, Args...>;
using T = in_t<Operand, Args...>;
static Context& _(const T& t, Context& context)
Context& serialize(const in_t<Operand, Args...>& t, Context& context)
{
serialize(t._operand, context);
context << " IN(";
@ -93,31 +88,19 @@ namespace sqlpp
context << ')';
return context;
}
};
template <typename Context, typename Operand>
struct serializer_t<Context, in_t<Operand>>
{
using _serialize_check = consistent_t;
using T = in_t<Operand>;
static Context& _(const T& /*unused*/, Context& context)
Context& serialize(const in_t<Operand>&, Context& context)
{
serialize(boolean_operand{false}, context);
return context;
}
};
template <typename Container>
struct value_list_t;
template <typename Context, typename Operand, typename Container>
struct serializer_t<Context, in_t<Operand, value_list_t<Container>>>
{
using _serialize_check = serialize_check_of<Context, value_list_t<Container>>;
using T = in_t<Operand, value_list_t<Container>>;
static Context& _(const T& t, Context& context)
Context& serialize(const in_t<Operand, value_list_t<Container>>& t, Context& context)
{
const auto& value_list = std::get<0>(t._args);
if (value_list._container.empty())
@ -133,7 +116,6 @@ namespace sqlpp
}
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -89,18 +89,12 @@ namespace sqlpp
};
template <typename Context>
struct serializer_t<Context, insert_name_t>
{
using _serialize_check = consistent_t;
using T = insert_name_t;
static Context& _(const T& /*unused*/, Context& context)
Context& serialize(const insert_name_t&, Context& context)
{
context << "INSERT";
return context;
}
};
template <typename Database>
using blank_insert_t = statement_t<Database, insert_t, no_into_t, no_insert_value_list_t>;

View File

@ -96,12 +96,7 @@ namespace sqlpp
};
template <typename Context, typename ValueType>
struct serializer_t<Context, insert_value_t<ValueType>>
{
using _serialize_check = serialize_check_of<Context, ValueType>;
using T = insert_value_t<ValueType>;
static Context& _(const T& t, Context& context)
Context& serialize(const insert_value_t<ValueType>& t, Context& context)
{
if (t._is_null)
{
@ -117,7 +112,6 @@ namespace sqlpp
}
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -290,10 +290,7 @@ namespace sqlpp
static_assert(not must_not_insert_t<lhs_t<Assignment>>::value, "add() argument must not be used in insert");
static_assert(Policies::template _no_unknown_tables<Assignment>::value,
"add() contains a column from a foreign table");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Assignment>;
_serialize_check{};
using ok = logic::all_t<_is_dynamic::value, is_assignment_t<Assignment>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_assignment_t<Assignment>::value>;
_add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert
}
@ -604,25 +601,15 @@ namespace sqlpp
// Interpreters
template <typename Context>
struct serializer_t<Context, insert_default_values_data_t>
{
using _serialize_check = consistent_t;
using T = insert_default_values_data_t;
static Context& _(const T& /*unused*/, Context& context)
Context& serialize(const insert_default_values_data_t&, Context& context)
{
context << " DEFAULT VALUES";
return context;
}
};
template <typename Context, typename... Columns>
struct serializer_t<Context, column_list_data_t<Columns...>>
{
using _serialize_check = serialize_check_of<Context, Columns...>;
using T = column_list_data_t<Columns...>;
static Context& _(const T& t, Context& context)
Context& serialize(const column_list_data_t<Columns...>& t, Context& context)
{
context << " (";
interpret_tuple(t._columns, ",", context);
@ -646,15 +633,9 @@ namespace sqlpp
return context;
}
};
template <typename Context, typename Database, typename... Assignments>
struct serializer_t<Context, insert_list_data_t<Database, Assignments...>>
{
using _serialize_check = serialize_check_of<Context, Assignments...>;
using T = insert_list_data_t<Database, Assignments...>;
static Context& _(const T& t, Context& context)
Context& serialize(const insert_list_data_t<Database, Assignments...>& t, Context& context)
{
if (sizeof...(Assignments) + t._dynamic_columns.size() == 0)
{
@ -684,7 +665,6 @@ namespace sqlpp
}
return context;
}
};
template <typename... Assignments>
auto insert_set(Assignments... assignments)

View File

@ -192,18 +192,12 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Database, typename Table>
struct serializer_t<Context, into_data_t<Database, Table>>
{
using _serialize_check = serialize_check_of<Context, Table>;
using T = into_data_t<Database, Table>;
static Context& _(const T& t, Context& context)
Context& serialize(const into_data_t<Database, Table>& t, Context& context)
{
context << " INTO ";
serialize(t._table, context);
return context;
}
};
template <typename T>
auto into(T&& t) -> decltype(statement_t<void, no_into_t>().into(std::forward<T>(t)))

View File

@ -54,12 +54,7 @@ namespace sqlpp
};
template <typename Context, typename Expr, typename ValueType>
struct serializer_t<Context, is_equal_to_or_null_t<Expr, ValueType>>
{
using _serialize_check = consistent_t;
using Operand = is_equal_to_or_null_t<Expr, ValueType>;
static Context& _(const Operand& t, Context& context)
Context& serialize(const is_equal_to_or_null_t<Expr, ValueType>& t, Context& context)
{
if (t._value._is_null)
serialize(t._expr.is_null(), context);
@ -68,7 +63,6 @@ namespace sqlpp
return context;
}
};
template <typename Expr, typename ValueType>
auto is_equal_to_or_null(Expr expr, value_or_null_t<ValueType> value) -> is_equal_to_or_null_t<Expr, ValueType>

View File

@ -287,12 +287,7 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Database>
struct serializer_t<Context, dynamic_limit_data_t<Database>>
{
using _serialize_check = consistent_t;
using T = dynamic_limit_data_t<Database>;
static Context& _(const T& t, Context& context)
Context& serialize(const dynamic_limit_data_t<Database>& t, Context& context)
{
if (t._initialized)
{
@ -301,21 +296,14 @@ namespace sqlpp
}
return context;
}
};
template <typename Context, typename Limit>
struct serializer_t<Context, limit_data_t<Limit>>
{
using _serialize_check = serialize_check_of<Context, Limit>;
using T = limit_data_t<Limit>;
static Context& _(const T& t, Context& context)
Context& serialize(const limit_data_t<Limit>& t, Context& context)
{
context << " LIMIT ";
serialize_operand(t._value, context);
return context;
}
};
template <typename T>
auto limit(T&& t) -> decltype(statement_t<void, no_limit_t>().limit(std::forward<T>(t)))

View File

@ -79,7 +79,7 @@ namespace sqlpp
_serializer_context_t& interpret(_serializer_context_t& context) const
{
interpret(_t, context);
serialize(_t, context);
return context;
}

View File

@ -38,17 +38,11 @@ namespace sqlpp
};
template <typename Context>
struct serializer_t<Context, null_t>
{
using _serialize_check = consistent_t;
using Operand = null_t;
static Context& _(const Operand& /*unused*/, Context& context)
Context& serialize(const null_t&, Context& context)
{
context << "NULL";
return context;
}
};
constexpr null_t null = {};
} // namespace sqlpp

View File

@ -301,26 +301,15 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Offset>
struct serializer_t<Context, offset_data_t<Offset>>
{
using _serialize_check = serialize_check_of<Context, Offset>;
using T = offset_data_t<Offset>;
static Context& _(const T& t, Context& context)
Context& serialize(const offset_data_t<Offset>& t, Context& context)
{
context << " OFFSET ";
serialize_operand(t._value, context);
return context;
}
};
template <typename Context, typename Database>
struct serializer_t<Context, dynamic_offset_data_t<Database>>
{
using _serialize_check = consistent_t;
using T = dynamic_offset_data_t<Database>;
static Context& _(const T& t, Context& context)
Context& serialize(const dynamic_offset_data_t<Database>& t, Context& context)
{
if (t._initialized)
{
@ -329,7 +318,6 @@ namespace sqlpp
}
return context;
}
};
template <typename T>
auto offset(T&& t) -> decltype(statement_t<void, no_offset_t>().offset(std::forward<T>(t)))

View File

@ -88,10 +88,7 @@ namespace sqlpp
static_assert(is_sort_order_t<Expression>::value, "invalid expression argument in order_by::add()");
static_assert(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 = logic::all_t<_is_dynamic::value, is_sort_order_t<Expression>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_sort_order_t<Expression>::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
@ -250,12 +247,7 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, order_by_data_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = order_by_data_t<Database, Expressions...>;
static Context& _(const T& t, Context& context)
Context& serialize(const order_by_data_t<Database, Expressions...>& t, Context& context)
{
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
{
@ -270,7 +262,6 @@ namespace sqlpp
interpret_list(t._dynamic_expressions, ',', context);
return context;
}
};
template <typename... T>
auto order_by(T&&... t) -> decltype(statement_t<void, no_order_by_t>().order_by(std::forward<T>(t)...))

View File

@ -56,18 +56,12 @@ namespace sqlpp
};
template <typename Context, typename AggregateExpr>
struct serializer_t<Context, over_t<AggregateExpr>>
{
using _serialize_check = serialize_check_of<Context, AggregateExpr>;
using T = over_t<AggregateExpr>;
static Context& _(const T& t, Context& context)
Context& serialize(const over_t<AggregateExpr>& t, Context& context)
{
serialize_operand(t._aggregate_expression, context);
context << " OVER()";
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -57,17 +57,11 @@ namespace sqlpp
};
template <typename Context, typename ValueType, typename NameType>
struct serializer_t<Context, parameter_t<ValueType, NameType>>
{
using _serialize_check = consistent_t;
using T = parameter_t<ValueType, NameType>;
static Context& _(const T& /*unused*/, Context& context)
Context& serialize(const parameter_t<ValueType, NameType>&, Context& context)
{
context << "?";
return context;
}
};
template <typename NamedExpr>
auto parameter(const NamedExpr & /*unused*/) -> parameter_t<value_type_of<NamedExpr>, NamedExpr>

View File

@ -59,19 +59,13 @@ namespace sqlpp
};
template <typename Context, typename ValueType, typename Expr>
struct serializer_t<Context, parameterized_verbatim_t<ValueType, Expr>>
{
using _serialize_check = consistent_t;
using T = parameterized_verbatim_t<ValueType, Expr>;
static Context& _(const T& t, Context& context)
Context& serialize(const parameterized_verbatim_t<ValueType, Expr>& t, Context& context)
{
context << t._verbatim_lhs;
serialize(t._expr, context);
context << t._verbatim_rhs;
return context;
}
};
template <typename ValueType, typename Expr>
auto parameterized_verbatim(std::string lhs, Expr expr, std::string rhs)

View File

@ -88,18 +88,12 @@ namespace sqlpp
};
template <typename Context>
struct serializer_t<Context, remove_name_t>
{
using _serialize_check = consistent_t;
using T = remove_name_t;
static Context& _(const T& /*unused*/, Context& context)
Context& serialize(const remove_name_t&, Context& context)
{
context << "DELETE";
return context;
}
};
template <typename Database>
using blank_remove_t = statement_t<Database, remove_t, no_from_t, no_using_t, no_where_t<true>>;

View File

@ -42,12 +42,7 @@ namespace sqlpp
};
template <typename Context, typename Db, typename FieldSpec>
struct serializer_t<Context, result_field_t<Db, FieldSpec>>
{
using _serialize_check = consistent_t;
using T = result_field_t<Db, FieldSpec>;
static Context& _(const T& t, Context& context)
Context& serialize(const result_field_t<Db, FieldSpec>& t, Context& context)
{
if (t.is_null())
{
@ -59,7 +54,6 @@ namespace sqlpp
}
return context;
}
};
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<Db, FieldSpec>& rf)

View File

@ -40,17 +40,11 @@ namespace sqlpp
};
template <typename Context>
struct serializer_t<Context, schema_t>
{
using _serialize_check = consistent_t;
using T = schema_t;
static Context& _(const T& t, Context& context)
Context& serialize(const schema_t& t, Context& context)
{
context << t._name;
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -63,19 +63,13 @@ namespace sqlpp
};
template <typename Context, typename Table>
struct serializer_t<Context, schema_qualified_table_t<Table>>
{
using _serialize_check = serialize_check_of<Context, Table>;
using T = schema_qualified_table_t<Table>;
static Context& _(const T& t, Context& context)
Context& serialize(const schema_qualified_table_t<Table>& t, Context& context)
{
serialize(t._schema, context);
context << '.';
serialize(t._table, context);
return context;
}
};
template <typename Table>
auto schema_qualified_table(schema_t schema, Table table) -> schema_qualified_table_t<Table>

View File

@ -84,10 +84,7 @@ namespace sqlpp
static_assert(is_select_flag_t<Flag>::value, "invalid select flag argument in select_flags::add()");
static_assert(Policies::template _no_unknown_tables<Flag>::value,
"flag uses tables unknown to this statement in select_flags::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Flag>;
_serialize_check{};
using ok = logic::all_t<_is_dynamic::value, is_select_flag_t<Flag>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_select_flag_t<Flag>::value>;
_add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert
}
@ -240,12 +237,7 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Database, typename... Flags>
struct serializer_t<Context, select_flag_list_data_t<Database, Flags...>>
{
using _serialize_check = serialize_check_of<Context, Flags...>;
using T = select_flag_list_data_t<Database, Flags...>;
static Context& _(const T& t, Context& context)
Context& serialize(const select_flag_list_data_t<Database, Flags...>& t, Context& context)
{
interpret_tuple(t._flags, ' ', context);
if (sizeof...(Flags) != 0u)
@ -259,7 +251,6 @@ namespace sqlpp
}
return context;
}
};
template <typename T>
auto select_flags(T&& t) -> decltype(statement_t<void, no_select_flag_list_t>().flags(std::forward<T>(t)))

View File

@ -43,16 +43,11 @@ namespace sqlpp
static constexpr all_t all = {};
template <typename Context>
struct serializer_t<Context, all_t>
{
using _serialize_check = consistent_t;
static Context& _(const all_t& /*unused*/, Context& context)
Context& serialize(const all_t&, Context& context)
{
context << "ALL";
return context;
}
};
struct distinct_t
{
@ -62,16 +57,11 @@ namespace sqlpp
static constexpr distinct_t distinct = {};
template <typename Context>
struct serializer_t<Context, distinct_t>
{
using _serialize_check = consistent_t;
static Context& _(const distinct_t& /*unused*/, Context& context)
Context& serialize(const distinct_t&, Context& context)
{
context << "DISTINCT";
return context;
}
};
struct straight_join_t
{
@ -81,16 +71,11 @@ namespace sqlpp
static constexpr straight_join_t straight_join = {};
template <typename Context>
struct serializer_t<Context, straight_join_t>
{
using _serialize_check = consistent_t;
static Context& _(const straight_join_t& /*unused*/, Context& context)
Context& serialize(const straight_join_t&, Context& context)
{
context << "STRAIGHT_JOIN";
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -27,29 +27,16 @@
#ifndef SQLPP11_SERIALIZER_H
#define SQLPP11_SERIALIZER_H
#include <sqlpp11/portable_static_assert.h>
#include <sqlpp11/wrong.h>
#include <type_traits>
namespace sqlpp
{
SQLPP_PORTABLE_STATIC_ASSERT(assert_serializer_specialization_t, "missing serializer specialization");
// FIXME: Move to type_traits.h, for instance
template <typename Context>
std::integral_constant<char, '"'> get_quote_left(const Context&);
template <typename Context>
std::integral_constant<char, '"'> get_quote_right(const Context&);
template <typename Context, typename T, typename Enable = void>
struct serializer_t
{
using _serialize_check = assert_serializer_specialization_t;
static void _(const T& t, Context& /*unused*/)
{
_serialize_check{t};
}
};
} // namespace sqlpp
#endif

View File

@ -49,17 +49,11 @@ namespace sqlpp
};
template <typename Context, typename Column>
struct serializer_t<Context, simple_column_t<Column>>
Context& serialize(const simple_column_t<Column>&, Context& context)
{
using _serialize_check = serialize_check_of<Context, Column>;
using T = simple_column_t<Column>;
static Context& _(const T& /*unused*/, Context& context)
{
context << name_of<typename T::_column_t>::template char_ptr<Context>();
context << name_of<typename simple_column_t<Column>::_column_t>::template char_ptr<Context>();
return context;
}
};
template <typename Column>
simple_column_t<Column> simple_column(Column c)

View File

@ -192,17 +192,11 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Database, typename Table>
struct serializer_t<Context, single_table_data_t<Database, Table>>
{
using _serialize_check = serialize_check_of<Context, Table>;
using T = single_table_data_t<Database, Table>;
static Context& _(const T& t, Context& context)
Context& serialize(const single_table_data_t<Database, Table>& t, Context& context)
{
serialize(t._table, context);
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -53,19 +53,13 @@ namespace sqlpp
};
template <typename Context, typename Select>
struct serializer_t<Context, some_t<Select>>
{
using _serialize_check = serialize_check_of<Context, Select>;
using T = some_t<Select>;
static Context& _(const T& t, Context& context)
Context& serialize(const some_t<Select>& t, Context& context)
{
context << "SOME(";
serialize(t._select, context);
context << ")";
return context;
}
};
template <typename T>
auto some(T t) -> some_t<wrap_operand_t<T>>

View File

@ -50,12 +50,7 @@ namespace sqlpp
};
template <typename Context, typename Expression>
struct serializer_t<Context, sort_order_t<Expression>>
{
using _serialize_check = serialize_check_of<Context, Expression>;
using T = sort_order_t<Expression>;
static Context& _(const T& t, Context& context)
Context& serialize(const sort_order_t<Expression>& t, Context& context)
{
serialize_operand(t._expression, context);
switch (t._sort_type)
@ -69,7 +64,6 @@ namespace sqlpp
}
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -81,19 +81,13 @@ namespace sqlpp
};
template <typename Context, typename Flag, typename Expr>
struct serializer_t<Context, trim_t<Flag, Expr>>
{
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
using T = trim_t<Flag, Expr>;
static Context& _(const T& t, Context& context)
Context& serialize(const trim_t<Flag, Expr>& t, Context& context)
{
context << "TRIM(";
serialize(t._expr, context);
context << ")";
return context;
}
};
template <typename T>
auto trim(T t) -> trim_t<noop, wrap_operand_t<T>>

View File

@ -30,6 +30,7 @@
#include <type_traits>
#include <tuple>
#include <sqlpp11/consistent.h>
#include <sqlpp11/portable_static_assert.h>
#include <sqlpp11/serializer.h>
#include <sqlpp11/detail/type_vector.h>
#include <sqlpp11/detail/type_set.h>
@ -391,10 +392,6 @@ namespace sqlpp
using is_inconsistent_t =
typename std::conditional<std::is_same<consistent_t, T>::value, std::false_type, std::true_type>::type;
template <typename Context, typename... T>
using serialize_check_of =
detail::get_first_if<is_inconsistent_t, consistent_t, typename serializer_t<Context, T>::_serialize_check...>;
SQLPP_PORTABLE_STATIC_ASSERT(assert_sqlpp_type_t, "expression is not an sqlpp type, consistency cannot be verified");
SQLPP_PORTABLE_STATIC_ASSERT(assert_run_statement_or_prepared_t,
"connection cannot run something that is neither statement nor prepared statement");
@ -416,21 +413,6 @@ namespace sqlpp
template <typename T>
using consistency_check_t = typename consistency_check<T>::type;
template <typename Context, typename T, typename Enable = void>
struct serialize_check
{
using type = serialize_check_of<Context, T>;
};
template <typename Context, typename T>
struct serialize_check<Context, T, typename std::enable_if<is_prepared_statement_t<T>::value>::type>
{
using type = consistent_t; // this is already serialized
};
template <typename Context, typename T>
using serialize_check_t = typename serialize_check<Context, T>::type;
template <typename Context, typename T, typename Enable = void>
struct run_check
{
@ -459,7 +441,7 @@ namespace sqlpp
struct prepare_check<Context, T, typename std::enable_if<is_statement_t<T>::value>::type>
{
using type = detail::
get_first_if<is_inconsistent_t, consistent_t, typename T::_prepare_check, serialize_check_t<Context, T>>;
get_first_if<is_inconsistent_t, consistent_t, typename T::_prepare_check>;
};
template <typename Context, typename T>

View File

@ -50,12 +50,7 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Database, typename Flag, typename Lhs, typename Rhs>
struct serializer_t<Context, union_data_t<Database, Flag, Lhs, Rhs>>
{
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
using T = union_data_t<Database, Flag, Lhs, Rhs>;
static Context& _(const T& t, Context& context)
Context& serialize(const union_data_t<Database, Flag, Lhs, Rhs>& t, Context& context)
{
serialize(t._lhs, context);
context << " UNION ";
@ -64,7 +59,6 @@ namespace sqlpp
serialize(t._rhs, context);
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -42,16 +42,11 @@ namespace sqlpp
};
template <typename Context>
struct serializer_t<Context, union_all_t>
{
using _serialize_check = consistent_t;
static Context& _(const union_all_t& /*unused*/, Context& context)
Context& serialize(const union_all_t&, Context& context)
{
context << "ALL";
return context;
}
};
struct union_distinct_t
{
@ -60,15 +55,10 @@ namespace sqlpp
};
template <typename Context>
struct serializer_t<Context, union_distinct_t>
{
using _serialize_check = consistent_t;
static Context& _(const union_distinct_t& /*unused*/, Context& context)
Context& serialize(const union_distinct_t&, Context& context)
{
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -89,18 +89,11 @@ namespace sqlpp
};
template <typename Context>
struct serializer_t<Context, update_name_t>
{
using _serialize_check = consistent_t;
using T = update_name_t;
static Context& _(const T& /*unused*/, Context& context)
Context& serialize(const update_name_t&, Context& context)
{
context << "UPDATE ";
return context;
}
};
template <typename Database>
using blank_update_t = statement_t<Database, update_t, no_single_table_t, no_update_list_t, no_where_t<true>>;

View File

@ -88,10 +88,7 @@ namespace sqlpp
static_assert(logic::not_t<must_not_update_t, lhs_t<Assignment>>::value, "add() argument must not be updated");
static_assert(Policies::template _no_unknown_tables<Assignment>::value,
"assignment uses tables unknown to this statement in add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Assignment>;
_serialize_check{};
using ok = logic::all_t<_is_dynamic::value, is_assignment_t<Assignment>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_assignment_t<Assignment>::value>;
_add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert
}
@ -294,12 +291,7 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Database, typename... Assignments>
struct serializer_t<Context, update_list_data_t<Database, Assignments...>>
{
using _serialize_check = serialize_check_of<Context, Assignments...>;
using T = update_list_data_t<Database, Assignments...>;
static Context& _(const T& t, Context& context)
Context& serialize(const update_list_data_t<Database, Assignments...>& t, Context& context)
{
context << " SET ";
interpret_tuple(t._assignments, ",", context);
@ -310,7 +302,6 @@ namespace sqlpp
interpret_list(t._dynamic_assignments, ',', context);
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -80,10 +80,7 @@ namespace sqlpp
{
static_assert(_is_dynamic::value, "add must not be called for static using()");
static_assert(is_table_t<Table>::value, "invalid table argument in add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Table>;
_serialize_check{};
using ok = logic::all_t<_is_dynamic::value, is_table_t<Table>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_table_t<Table>::value>;
_add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert
}
@ -240,12 +237,7 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Database, typename... Tables>
struct serializer_t<Context, using_data_t<Database, Tables...>>
{
using _serialize_check = serialize_check_of<Context, Tables...>;
using T = using_data_t<Database, Tables...>;
static Context& _(const T& t, Context& context)
Context& serialize(const using_data_t<Database, Tables...>& t, Context& context)
{
if (sizeof...(Tables) == 0 and t._dynamic_tables.empty())
{
@ -260,7 +252,6 @@ namespace sqlpp
interpret_list(t._dynamic_tables, ',', context);
return context;
}
};
} // namespace sqlpp
#endif

View File

@ -57,17 +57,11 @@ namespace sqlpp
};
template <typename Context, typename ValueType>
struct serializer_t<Context, verbatim_t<ValueType>>
{
using _serialize_check = consistent_t;
using T = verbatim_t<ValueType>;
static Context& _(const T& t, Context& context)
Context& serialize(const verbatim_t<ValueType>& t, Context& context)
{
context << t._verbatim;
return context;
}
};
template <typename ValueType, typename StringType>
auto verbatim(StringType s) -> verbatim_t<ValueType>

View File

@ -76,17 +76,11 @@ namespace sqlpp
};
template <typename Context>
struct serializer_t<Context, verbatim_table_t>
{
using _serialize_check = consistent_t;
using T = verbatim_table_t;
static Context& _(const T& t, Context& context)
Context& serialize(const verbatim_table_t& t, Context& context)
{
context << t._representation;
return context;
}
};
inline verbatim_table_t verbatim_table(std::string name)
{

View File

@ -93,10 +93,7 @@ namespace sqlpp
"expression uses tables unknown to this statement in where::add()");
static_assert(not contains_aggregate_function_t<Expr>::value,
"where expression must not contain aggregate functions");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expr>;
_serialize_check{};
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}

View File

@ -191,13 +191,9 @@ namespace sqlpp
// Interpreters
template <typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, with_data_t<Database, Expressions...>>
Context& serialize(const with_data_t<Database, Expressions...>& t, Context& context)
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = with_data_t<Database, Expressions...>;
static Context& _(const T& t, Context& context)
{
// FIXME: If there is a recursive CTE, add a "RECURSIVE" here
context << " WITH ";
if (T::_is_recursive::value)
@ -208,7 +204,6 @@ namespace sqlpp
context << ' ';
return context;
}
};
template <typename... Expressions>
auto with(Expressions... cte) -> blank_with_t<void, Expressions...>

View File

@ -33,27 +33,23 @@
namespace sqlpp
{
template <typename Expression>
struct without_table_check_t : Expression
struct without_table_check_t: public Expression
{
using _required_tables = detail::type_set<>;
without_table_check_t(Expression expression) : Expression(expression)
{
}
const Expression& expr() const { return *this; }
};
template <typename Context, typename Expression>
struct serializer_t<Context, without_table_check_t<Expression>>
Context& serialize(const without_table_check_t<Expression>& t, Context& context)
{
using _serialize_check = serialize_check_of<Context, Expression>;
using T = without_table_check_t<Expression>;
static Context& _(const T& t, Context& context)
{
serialize<Expression>(t, context);
serialize(t.expr(), context);
return context;
}
};
template <typename Expression>
auto without_table_check(Expression expr) -> without_table_check_t<Expression>

View File

@ -30,21 +30,21 @@ target_compile_options(sqlpp11_testing INTERFACE -Wall -Wextra -pedantic)
endif ()
set(test_names
#BooleanExpression
#CustomQuery
#DateTime
#Interpret
#Insert
#Remove
#Update
BooleanExpression
CustomQuery
DateTime
Interpret
Insert
Remove
Update
Select
#SelectType
#Function
#Prepared
#Minimalistic
#Result
#Union
#With
SelectType
Function
Prepared
Minimalistic
Result
Union
With
)
find_package(Boost 1.50)

View File

@ -142,11 +142,6 @@ namespace test
};
};
};
template <typename Context>
Context& serialize(const TabFoo&, Context& context)
{
return serialize(sqlpp::table_t<TabFoo, TabFoo_::Delta, TabFoo_::Epsilon, TabFoo_::Omega, TabFoo_::Psi, TabFoo_::Book>{}, context);
}
namespace TabBar_
{
struct Alpha
@ -261,11 +256,6 @@ namespace test
};
};
};
template <typename Context>
Context& serialize(const TabBar&, Context& context)
{
return serialize(sqlpp::table_t<TabBar, TabBar_::Alpha, TabBar_::Beta, TabBar_::Gamma, TabBar_::Delta>{}, context);
}
namespace TabDateTime_
{
struct ColDayPoint
@ -358,11 +348,5 @@ namespace test
};
};
};
template <typename Context>
Context& serialize(const TabDateTime&, Context& context)
{
return serialize(sqlpp::table_t<TabDateTime, TabDateTime_::ColDayPoint, TabDateTime_::ColTimePoint, TabDateTime_::ColTimeOfDay>{}, context);
}
} // namespace test
#endif

View File

@ -74,7 +74,6 @@ int Select(int, char*[])
select(count(t.alpha));
std::cerr << serialize(select(sqlpp::value(false).as(sqlpp::alias::a)), printer).str() << std::endl;
/*
for (const auto& row : db(select(sqlpp::value(false).as(sqlpp::alias::a))))
{
std::cout << row.a << std::endl;
@ -210,7 +209,6 @@ int Select(int, char*[])
std::cout << "Error: transaction isolation level does not match default level" << std::endl;
}
}
*/
return 0;
}