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:
parent
2cab1fa681
commit
68021772c2
@ -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");
|
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>
|
template <typename Context, typename Table>
|
||||||
struct serializer_t<Context, all_of_t<Table>>
|
Context& serialize(const all_of_t<Table>& t, Context& context);
|
||||||
{
|
|
||||||
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{};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -53,19 +53,13 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Select>
|
template <typename Context, typename Select>
|
||||||
struct serializer_t<Context, any_t<Select>>
|
Context& serialize(const any_t<Select>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Select>;
|
context << "ANY(";
|
||||||
using T = any_t<Select>;
|
serialize(t._select, context);
|
||||||
|
context << ")";
|
||||||
static Context& _(const T& t, Context& context)
|
return context;
|
||||||
{
|
}
|
||||||
context << "ANY(";
|
|
||||||
serialize(t._select, context);
|
|
||||||
context << ")";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto any(T t) -> any_t<wrap_operand_t<T>>
|
auto any(T t) -> any_t<wrap_operand_t<T>>
|
||||||
|
@ -62,19 +62,13 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Lhs, typename Rhs>
|
template <typename Context, typename Lhs, typename Rhs>
|
||||||
struct serializer_t<Context, assignment_t<Lhs, Rhs>>
|
Context& serialize(const assignment_t<Lhs, Rhs>& t, Context& context)
|
||||||
{
|
{
|
||||||
using T = assignment_t<Lhs, Rhs>;
|
serialize(simple_column(t._lhs), context);
|
||||||
using _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
|
context << "=";
|
||||||
|
serialize_operand(t._rhs, context);
|
||||||
static Context& _(const T& t, Context& context)
|
return context;
|
||||||
{
|
}
|
||||||
serialize(simple_column(t._lhs), context);
|
|
||||||
context << "=";
|
|
||||||
serialize_operand(t._rhs, context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -46,13 +46,7 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename ValueType>
|
template <typename Context, typename ValueType>
|
||||||
struct serializer_t<Context, bad_expression<ValueType>>
|
Context serialize(const bad_expression<ValueType>& t, Context& context);
|
||||||
{
|
|
||||||
using _serialize_check = assert_valid_operands;
|
|
||||||
using T = bad_expression<ValueType>;
|
|
||||||
|
|
||||||
static Context& _(const T&, Context&);
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -68,16 +68,10 @@ namespace sqlpp
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Context, typename Database>
|
template <typename Context, typename Database>
|
||||||
struct serializer_t<Context, boolean_expression_t<Database>>
|
Context& serialize(const boolean_expression_t<Database>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
return serialize(t._expr, context);
|
||||||
using T = boolean_expression_t<Database>;
|
}
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
|
||||||
return serialize(t._expr, context);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -151,23 +151,17 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename When, typename Then, typename Else>
|
template <typename Context, typename When, typename Then, typename Else>
|
||||||
struct serializer_t<Context, case_t<When, Then, Else>>
|
Context& serialize(const case_t<When, Then, Else>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<When, Then, Else>;
|
context << "(CASE WHEN ";
|
||||||
using T = case_t<When, Then, Else>;
|
serialize(t._when, context);
|
||||||
|
context << " THEN ";
|
||||||
static Context& _(const T& t, Context& context)
|
serialize(t._then, context);
|
||||||
{
|
context << " ELSE ";
|
||||||
context << "(CASE WHEN ";
|
serialize(t._else, context);
|
||||||
serialize(t._when, context);
|
context << " END)";
|
||||||
context << " THEN ";
|
return context;
|
||||||
serialize(t._then, context);
|
}
|
||||||
context << " ELSE ";
|
|
||||||
serialize(t._else, context);
|
|
||||||
context << " END)";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
@ -63,21 +63,15 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Flag, typename Lhs, typename Rhs>
|
template <typename Context, typename Flag, typename Lhs, typename Rhs>
|
||||||
struct serializer_t<Context, cte_union_t<Flag, Lhs, Rhs>>
|
Context& serialize(const cte_union_t<Flag, Lhs, Rhs>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
|
serialize(t._lhs, context);
|
||||||
using T = cte_union_t<Flag, Lhs, Rhs>;
|
context << " UNION ";
|
||||||
|
serialize(Flag{}, context);
|
||||||
static Context& _(const T& t, Context& context)
|
context << " ";
|
||||||
{
|
serialize(t._rhs, context);
|
||||||
serialize(t._lhs, context);
|
return context;
|
||||||
context << " UNION ";
|
}
|
||||||
serialize(Flag{}, context);
|
|
||||||
context << " ";
|
|
||||||
serialize(t._rhs, context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename AliasProvider, typename Statement, typename... FieldSpecs>
|
template <typename AliasProvider, typename Statement, typename... FieldSpecs>
|
||||||
struct cte_t;
|
struct cte_t;
|
||||||
@ -229,19 +223,14 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename AliasProvider, typename Statement, typename... ColumnSpecs>
|
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...>;
|
using T = cte_t<AliasProvider, Statement, ColumnSpecs...>;
|
||||||
|
context << name_of<T>::template char_ptr<Context>() << " AS (";
|
||||||
static Context& _(const T& t, Context& context)
|
serialize(t._statement, context);
|
||||||
{
|
context << ")";
|
||||||
context << name_of<T>::template char_ptr<Context>() << " AS (";
|
return context;
|
||||||
serialize(t._statement, context);
|
}
|
||||||
context << ")";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// The cte_t is displayed as AliasProviderName except within the with:
|
// The cte_t is displayed as AliasProviderName except within the with:
|
||||||
// - the with needs the
|
// - the with needs the
|
||||||
@ -273,17 +262,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename AliasProvider>
|
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;
|
context << name_of<cte_ref_t<AliasProvider>>::template char_ptr<Context>();
|
||||||
using T = cte_ref_t<AliasProvider>;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
context << name_of<T>::template char_ptr<Context>();
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename AliasProvider>
|
template <typename AliasProvider>
|
||||||
auto cte(const AliasProvider & /*unused*/) -> cte_ref_t<AliasProvider>
|
auto cte(const AliasProvider & /*unused*/) -> cte_ref_t<AliasProvider>
|
||||||
|
@ -123,17 +123,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Database, typename... Parts>
|
template <typename Context, typename Database, typename... Parts>
|
||||||
struct serializer_t<Context, custom_query_t<Database, Parts...>>
|
Context serialize(const custom_query_t<Database, Parts...>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Parts...>;
|
interpret_tuple_without_braces(t._parts, " ", context);
|
||||||
using T = custom_query_t<Database, Parts...>;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
|
||||||
interpret_tuple_without_braces(t._parts, " ", context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... Parts>
|
template <typename... Parts>
|
||||||
auto custom_query(Parts... parts) -> custom_query_t<void, wrap_operand_t<Parts>...>
|
auto custom_query(Parts... parts) -> custom_query_t<void, wrap_operand_t<Parts>...>
|
||||||
|
@ -38,17 +38,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, default_value_t>
|
Context& serialize(const default_value_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << "DEFAULT";
|
||||||
using Operand = default_value_t;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const Operand& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
context << "DEFAULT";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr default_value_t default_value = {};
|
constexpr default_value_t default_value = {};
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
@ -157,17 +157,11 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, for_update_data_t>
|
Context& serialize(const for_update_data_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context>;
|
context << " FOR UPDATE ";
|
||||||
using T = for_update_data_t;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
context << " FOR UPDATE ";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto for_update(T&& t) -> decltype(statement_t<void, no_for_update_t>().for_update(std::forward<T>(t)))
|
auto for_update(T&& t) -> decltype(statement_t<void, no_for_update_t>().for_update(std::forward<T>(t)))
|
||||||
|
@ -85,8 +85,6 @@ namespace sqlpp
|
|||||||
assert_from_add_unique_names>,
|
assert_from_add_unique_names>,
|
||||||
static_check_t<detail::is_subset_of<_required_tables, _known_tables>::value,
|
static_check_t<detail::is_subset_of<_required_tables, _known_tables>::value,
|
||||||
assert_from_add_no_required_tables>
|
assert_from_add_no_required_tables>
|
||||||
// FIXME: Replace this with consistency check?
|
|
||||||
// sqlpp::serialize_check_t<serializer_context_of<typename From::_database_t>, DynamicJoin>
|
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -96,35 +96,29 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Container>
|
template <typename Context, typename Container>
|
||||||
struct serializer_t<Context, value_list_t<Container>>
|
Context& serialize(const value_list_t<Container>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, wrap_operand_t<typename Container::value_type>>;
|
if (t._container.size() == 1)
|
||||||
using T = value_list_t<Container>;
|
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
if (t._container.size() == 1)
|
return serialize(value(*begin(t._container)), context);
|
||||||
{
|
|
||||||
return serialize(value(*begin(t._container)), context);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool first = true;
|
|
||||||
for (const auto& entry : t._container)
|
|
||||||
{
|
|
||||||
if (first)
|
|
||||||
{
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context << ',';
|
|
||||||
}
|
|
||||||
|
|
||||||
serialize_operand(value(entry), context);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
bool first = true;
|
||||||
|
for (const auto& entry : t._container)
|
||||||
|
{
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context << ',';
|
||||||
|
}
|
||||||
|
|
||||||
|
serialize_operand(value(entry), context);
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
auto value_list(Container c) -> value_list_t<Container>
|
auto value_list(Container c) -> value_list_t<Container>
|
||||||
|
@ -90,10 +90,7 @@ namespace sqlpp
|
|||||||
static_assert(is_expression_t<Expression>::value, "invalid expression argument in group_by::add()");
|
static_assert(is_expression_t<Expression>::value, "invalid expression argument in group_by::add()");
|
||||||
static_assert(Policies::template _no_unknown_tables<Expression>::value,
|
static_assert(Policies::template _no_unknown_tables<Expression>::value,
|
||||||
"expression uses tables unknown to this statement in group_by::add()");
|
"expression uses tables unknown to this statement in group_by::add()");
|
||||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
|
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expression>::value>;
|
||||||
_serialize_check{};
|
|
||||||
|
|
||||||
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
|
|
||||||
|
|
||||||
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
|
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
|
||||||
}
|
}
|
||||||
|
@ -91,10 +91,7 @@ namespace sqlpp
|
|||||||
static_assert(is_expression_t<Expr>::value, "invalid expression argument in having::add()");
|
static_assert(is_expression_t<Expr>::value, "invalid expression argument in having::add()");
|
||||||
static_assert(Policies::template _no_unknown_tables<Expr>::value,
|
static_assert(Policies::template _no_unknown_tables<Expr>::value,
|
||||||
"expression uses tables unknown to this statement in having::add()");
|
"expression uses tables unknown to this statement in having::add()");
|
||||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expr>;
|
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value>;
|
||||||
_serialize_check{};
|
|
||||||
|
|
||||||
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value, _serialize_check::type::value>;
|
|
||||||
|
|
||||||
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
|
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
|
||||||
}
|
}
|
||||||
@ -292,23 +289,17 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Database, typename Expression>
|
template <typename Context, typename Database, typename Expression>
|
||||||
struct serializer_t<Context, having_data_t<Database, Expression>>
|
Context& serialize(const having_data_t<Database, Expression>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Expression>;
|
context << " HAVING ";
|
||||||
using T = having_data_t<Database, Expression>;
|
serialize(t._expression, context);
|
||||||
|
if (not t._dynamic_expressions.empty())
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
context << " HAVING ";
|
context << " AND ";
|
||||||
serialize(t._expression, context);
|
|
||||||
if (not t._dynamic_expressions.empty())
|
|
||||||
{
|
|
||||||
context << " AND ";
|
|
||||||
}
|
|
||||||
interpret_list(t._dynamic_expressions, " AND ", context);
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
interpret_list(t._dynamic_expressions, " AND ", context);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto having(T&& t) -> decltype(statement_t<void, no_having_t>().having(std::forward<T>(t)))
|
auto having(T&& t) -> decltype(statement_t<void, no_having_t>().having(std::forward<T>(t)))
|
||||||
|
@ -46,16 +46,10 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Clause>
|
template <typename Context, typename Clause>
|
||||||
struct serializer_t<Context, hidden_t<Clause>>
|
Context& serialize(const hidden_t<Clause>&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
return context;
|
||||||
using T = hidden_t<Clause>;
|
}
|
||||||
|
|
||||||
static Context& _(const T& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Clause>
|
template <typename Clause>
|
||||||
auto hidden(Clause part) -> hidden_t<Clause>
|
auto hidden(Clause part) -> hidden_t<Clause>
|
||||||
|
@ -73,67 +73,49 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Operand, typename... Args>
|
template <typename Context, typename Operand, typename... Args>
|
||||||
struct serializer_t<Context, in_t<Operand, Args...>>
|
Context& serialize(const in_t<Operand, Args...>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Args...>;
|
serialize(t._operand, context);
|
||||||
using T = in_t<Operand, Args...>;
|
context << " IN(";
|
||||||
|
if (sizeof...(Args) == 1)
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
serialize(t._operand, context);
|
serialize(std::get<0>(t._args), context);
|
||||||
context << " IN(";
|
|
||||||
if (sizeof...(Args) == 1)
|
|
||||||
{
|
|
||||||
serialize(std::get<0>(t._args), context);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
interpret_tuple(t._args, ',', context);
|
|
||||||
}
|
|
||||||
context << ')';
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
else
|
||||||
|
{
|
||||||
|
interpret_tuple(t._args, ',', context);
|
||||||
|
}
|
||||||
|
context << ')';
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Context, typename Operand>
|
template <typename Context, typename Operand>
|
||||||
struct serializer_t<Context, in_t<Operand>>
|
Context& serialize(const in_t<Operand>&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
serialize(boolean_operand{false}, context);
|
||||||
using T = in_t<Operand>;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
serialize(boolean_operand{false}, context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
struct value_list_t;
|
struct value_list_t;
|
||||||
|
|
||||||
template <typename Context, typename Operand, typename Container>
|
template <typename Context, typename Operand, typename Container>
|
||||||
struct serializer_t<Context, in_t<Operand, value_list_t<Container>>>
|
Context& serialize(const in_t<Operand, value_list_t<Container>>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, value_list_t<Container>>;
|
const auto& value_list = std::get<0>(t._args);
|
||||||
using T = in_t<Operand, value_list_t<Container>>;
|
if (value_list._container.empty())
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
const auto& value_list = std::get<0>(t._args);
|
serialize(boolean_operand{false}, context);
|
||||||
if (value_list._container.empty())
|
|
||||||
{
|
|
||||||
serialize(boolean_operand{false}, context);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
serialize(t._operand, context);
|
|
||||||
context << " IN(";
|
|
||||||
serialize(value_list, context);
|
|
||||||
context << ')';
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
else
|
||||||
|
{
|
||||||
|
serialize(t._operand, context);
|
||||||
|
context << " IN(";
|
||||||
|
serialize(value_list, context);
|
||||||
|
context << ')';
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -89,18 +89,12 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, insert_name_t>
|
Context& serialize(const insert_name_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << "INSERT";
|
||||||
using T = insert_name_t;
|
|
||||||
|
|
||||||
static Context& _(const T& /*unused*/, Context& context)
|
return context;
|
||||||
{
|
}
|
||||||
context << "INSERT";
|
|
||||||
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Database>
|
template <typename Database>
|
||||||
using blank_insert_t = statement_t<Database, insert_t, no_into_t, no_insert_value_list_t>;
|
using blank_insert_t = statement_t<Database, insert_t, no_into_t, no_insert_value_list_t>;
|
||||||
|
@ -96,28 +96,22 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename ValueType>
|
template <typename Context, typename ValueType>
|
||||||
struct serializer_t<Context, insert_value_t<ValueType>>
|
Context& serialize(const insert_value_t<ValueType>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, ValueType>;
|
if (t._is_null)
|
||||||
using T = insert_value_t<ValueType>;
|
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
if (t._is_null)
|
context << "NULL";
|
||||||
{
|
|
||||||
context << "NULL";
|
|
||||||
}
|
|
||||||
else if (t._is_default)
|
|
||||||
{
|
|
||||||
context << "DEFAULT";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
serialize_operand(t._value, context);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
else if (t._is_default)
|
||||||
|
{
|
||||||
|
context << "DEFAULT";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serialize_operand(t._value, context);
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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(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,
|
static_assert(Policies::template _no_unknown_tables<Assignment>::value,
|
||||||
"add() contains a column from a foreign table");
|
"add() contains a column from a foreign table");
|
||||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Assignment>;
|
using ok = logic::all_t<_is_dynamic::value, is_assignment_t<Assignment>::value>;
|
||||||
_serialize_check{};
|
|
||||||
|
|
||||||
using ok = logic::all_t<_is_dynamic::value, is_assignment_t<Assignment>::value, _serialize_check::type::value>;
|
|
||||||
|
|
||||||
_add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert
|
_add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert
|
||||||
}
|
}
|
||||||
@ -604,87 +601,70 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, insert_default_values_data_t>
|
Context& serialize(const insert_default_values_data_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << " DEFAULT VALUES";
|
||||||
using T = insert_default_values_data_t;
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
static Context& _(const T& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
context << " DEFAULT VALUES";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Context, typename... Columns>
|
template <typename Context, typename... Columns>
|
||||||
struct serializer_t<Context, column_list_data_t<Columns...>>
|
Context& serialize(const column_list_data_t<Columns...>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Columns...>;
|
context << " (";
|
||||||
using T = column_list_data_t<Columns...>;
|
interpret_tuple(t._columns, ",", context);
|
||||||
|
context << ")";
|
||||||
static Context& _(const T& t, Context& context)
|
bool first = true;
|
||||||
|
for (const auto& row : t._insert_values)
|
||||||
{
|
{
|
||||||
context << " (";
|
if (first)
|
||||||
interpret_tuple(t._columns, ",", context);
|
|
||||||
context << ")";
|
|
||||||
bool first = true;
|
|
||||||
for (const auto& row : t._insert_values)
|
|
||||||
{
|
{
|
||||||
if (first)
|
context << " VALUES ";
|
||||||
{
|
first = false;
|
||||||
context << " VALUES ";
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context << ',';
|
|
||||||
}
|
|
||||||
context << '(';
|
|
||||||
interpret_tuple(row, ",", context);
|
|
||||||
context << ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
if (sizeof...(Assignments) + t._dynamic_columns.size() == 0)
|
|
||||||
{
|
|
||||||
serialize(insert_default_values_data_t(), context);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
context << " (";
|
context << ',';
|
||||||
interpret_tuple(t._columns, ",", context);
|
}
|
||||||
if (sizeof...(Assignments) and not t._dynamic_columns.empty())
|
context << '(';
|
||||||
|
interpret_tuple(row, ",", context);
|
||||||
|
context << ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Context, typename Database, typename... Assignments>
|
||||||
|
Context& serialize(const insert_list_data_t<Database, Assignments...>& t, Context& context)
|
||||||
|
{
|
||||||
|
if (sizeof...(Assignments) + t._dynamic_columns.size() == 0)
|
||||||
|
{
|
||||||
|
serialize(insert_default_values_data_t(), context);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context << " (";
|
||||||
|
interpret_tuple(t._columns, ",", context);
|
||||||
|
if (sizeof...(Assignments) and not t._dynamic_columns.empty())
|
||||||
|
{
|
||||||
|
context << ',';
|
||||||
|
}
|
||||||
|
interpret_list(t._dynamic_columns, ',', context);
|
||||||
|
context << ")";
|
||||||
|
if (sizeof...(Assignments) or not t._dynamic_values.empty())
|
||||||
|
{
|
||||||
|
context << " VALUES(";
|
||||||
|
interpret_tuple(t._values, ",", context);
|
||||||
|
if (sizeof...(Assignments) and not t._dynamic_values.empty())
|
||||||
{
|
{
|
||||||
context << ',';
|
context << ',';
|
||||||
}
|
}
|
||||||
interpret_list(t._dynamic_columns, ',', context);
|
interpret_list(t._dynamic_values, ',', context);
|
||||||
context << ")";
|
context << ")";
|
||||||
if (sizeof...(Assignments) or not t._dynamic_values.empty())
|
|
||||||
{
|
|
||||||
context << " VALUES(";
|
|
||||||
interpret_tuple(t._values, ",", context);
|
|
||||||
if (sizeof...(Assignments) and not t._dynamic_values.empty())
|
|
||||||
{
|
|
||||||
context << ',';
|
|
||||||
}
|
|
||||||
interpret_list(t._dynamic_values, ',', context);
|
|
||||||
context << ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename... Assignments>
|
template <typename... Assignments>
|
||||||
auto insert_set(Assignments... assignments)
|
auto insert_set(Assignments... assignments)
|
||||||
|
@ -192,18 +192,12 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Database, typename Table>
|
template <typename Context, typename Database, typename Table>
|
||||||
struct serializer_t<Context, into_data_t<Database, Table>>
|
Context& serialize(const into_data_t<Database, Table>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Table>;
|
context << " INTO ";
|
||||||
using T = into_data_t<Database, Table>;
|
serialize(t._table, context);
|
||||||
|
return context;
|
||||||
static Context& _(const T& t, Context& context)
|
}
|
||||||
{
|
|
||||||
context << " INTO ";
|
|
||||||
serialize(t._table, context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto into(T&& t) -> decltype(statement_t<void, no_into_t>().into(std::forward<T>(t)))
|
auto into(T&& t) -> decltype(statement_t<void, no_into_t>().into(std::forward<T>(t)))
|
||||||
|
@ -54,21 +54,15 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Expr, typename ValueType>
|
template <typename Context, typename Expr, typename ValueType>
|
||||||
struct serializer_t<Context, is_equal_to_or_null_t<Expr, ValueType>>
|
Context& serialize(const is_equal_to_or_null_t<Expr, ValueType>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
if (t._value._is_null)
|
||||||
using Operand = is_equal_to_or_null_t<Expr, ValueType>;
|
serialize(t._expr.is_null(), context);
|
||||||
|
else
|
||||||
|
serialize(t._expr == t._value, context);
|
||||||
|
|
||||||
static Context& _(const Operand& t, Context& context)
|
return context;
|
||||||
{
|
}
|
||||||
if (t._value._is_null)
|
|
||||||
serialize(t._expr.is_null(), context);
|
|
||||||
else
|
|
||||||
serialize(t._expr == t._value, context);
|
|
||||||
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Expr, typename ValueType>
|
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>
|
auto is_equal_to_or_null(Expr expr, value_or_null_t<ValueType> value) -> is_equal_to_or_null_t<Expr, ValueType>
|
||||||
|
@ -287,35 +287,23 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Database>
|
template <typename Context, typename Database>
|
||||||
struct serializer_t<Context, dynamic_limit_data_t<Database>>
|
Context& serialize(const dynamic_limit_data_t<Database>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
if (t._initialized)
|
||||||
using T = dynamic_limit_data_t<Database>;
|
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
|
||||||
if (t._initialized)
|
|
||||||
{
|
|
||||||
context << " LIMIT ";
|
|
||||||
serialize(t._value, context);
|
|
||||||
}
|
|
||||||
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 << " LIMIT ";
|
context << " LIMIT ";
|
||||||
serialize_operand(t._value, context);
|
serialize(t._value, context);
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Context, typename Limit>
|
||||||
|
Context& serialize(const limit_data_t<Limit>& t, Context& context)
|
||||||
|
{
|
||||||
|
context << " LIMIT ";
|
||||||
|
serialize_operand(t._value, context);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto limit(T&& t) -> decltype(statement_t<void, no_limit_t>().limit(std::forward<T>(t)))
|
auto limit(T&& t) -> decltype(statement_t<void, no_limit_t>().limit(std::forward<T>(t)))
|
||||||
|
@ -79,7 +79,7 @@ namespace sqlpp
|
|||||||
|
|
||||||
_serializer_context_t& interpret(_serializer_context_t& context) const
|
_serializer_context_t& interpret(_serializer_context_t& context) const
|
||||||
{
|
{
|
||||||
interpret(_t, context);
|
serialize(_t, context);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,17 +38,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, null_t>
|
Context& serialize(const null_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << "NULL";
|
||||||
using Operand = null_t;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const Operand& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
context << "NULL";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr null_t null = {};
|
constexpr null_t null = {};
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
@ -301,35 +301,23 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Offset>
|
template <typename Context, typename Offset>
|
||||||
struct serializer_t<Context, offset_data_t<Offset>>
|
Context& serialize(const offset_data_t<Offset>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Offset>;
|
context << " OFFSET ";
|
||||||
using T = offset_data_t<Offset>;
|
serialize_operand(t._value, context);
|
||||||
|
return context;
|
||||||
static Context& _(const T& t, Context& context)
|
}
|
||||||
{
|
|
||||||
context << " OFFSET ";
|
|
||||||
serialize_operand(t._value, context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Context, typename Database>
|
template <typename Context, typename Database>
|
||||||
struct serializer_t<Context, dynamic_offset_data_t<Database>>
|
Context& serialize(const dynamic_offset_data_t<Database>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
if (t._initialized)
|
||||||
using T = dynamic_offset_data_t<Database>;
|
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
if (t._initialized)
|
context << " OFFSET ";
|
||||||
{
|
serialize(t._value, context);
|
||||||
context << " OFFSET ";
|
|
||||||
serialize(t._value, context);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto offset(T&& t) -> decltype(statement_t<void, no_offset_t>().offset(std::forward<T>(t)))
|
auto offset(T&& t) -> decltype(statement_t<void, no_offset_t>().offset(std::forward<T>(t)))
|
||||||
|
@ -88,10 +88,7 @@ namespace sqlpp
|
|||||||
static_assert(is_sort_order_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(Policies::template _no_unknown_tables<Expression>::value,
|
static_assert(Policies::template _no_unknown_tables<Expression>::value,
|
||||||
"expression uses tables unknown to this statement in order_by::add()");
|
"expression uses tables unknown to this statement in order_by::add()");
|
||||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
|
using ok = logic::all_t<_is_dynamic::value, is_sort_order_t<Expression>::value>;
|
||||||
_serialize_check{};
|
|
||||||
|
|
||||||
using ok = logic::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
|
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
|
||||||
}
|
}
|
||||||
@ -250,27 +247,21 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Database, typename... Expressions>
|
template <typename Context, typename Database, typename... Expressions>
|
||||||
struct serializer_t<Context, order_by_data_t<Database, Expressions...>>
|
Context& serialize(const order_by_data_t<Database, Expressions...>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Expressions...>;
|
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
|
||||||
using T = order_by_data_t<Database, Expressions...>;
|
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
|
|
||||||
{
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
context << " ORDER BY ";
|
|
||||||
interpret_tuple(t._expressions, ',', context);
|
|
||||||
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
|
|
||||||
{
|
|
||||||
context << ',';
|
|
||||||
}
|
|
||||||
interpret_list(t._dynamic_expressions, ',', context);
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
};
|
context << " ORDER BY ";
|
||||||
|
interpret_tuple(t._expressions, ',', context);
|
||||||
|
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
|
||||||
|
{
|
||||||
|
context << ',';
|
||||||
|
}
|
||||||
|
interpret_list(t._dynamic_expressions, ',', context);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
auto order_by(T&&... t) -> decltype(statement_t<void, no_order_by_t>().order_by(std::forward<T>(t)...))
|
auto order_by(T&&... t) -> decltype(statement_t<void, no_order_by_t>().order_by(std::forward<T>(t)...))
|
||||||
|
@ -56,18 +56,12 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename AggregateExpr>
|
template <typename Context, typename AggregateExpr>
|
||||||
struct serializer_t<Context, over_t<AggregateExpr>>
|
Context& serialize(const over_t<AggregateExpr>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, AggregateExpr>;
|
serialize_operand(t._aggregate_expression, context);
|
||||||
using T = over_t<AggregateExpr>;
|
context << " OVER()";
|
||||||
|
return context;
|
||||||
static Context& _(const T& t, Context& context)
|
}
|
||||||
{
|
|
||||||
serialize_operand(t._aggregate_expression, context);
|
|
||||||
context << " OVER()";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,17 +57,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename ValueType, typename NameType>
|
template <typename Context, typename ValueType, typename NameType>
|
||||||
struct serializer_t<Context, parameter_t<ValueType, NameType>>
|
Context& serialize(const parameter_t<ValueType, NameType>&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << "?";
|
||||||
using T = parameter_t<ValueType, NameType>;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
context << "?";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename NamedExpr>
|
template <typename NamedExpr>
|
||||||
auto parameter(const NamedExpr & /*unused*/) -> parameter_t<value_type_of<NamedExpr>, NamedExpr>
|
auto parameter(const NamedExpr & /*unused*/) -> parameter_t<value_type_of<NamedExpr>, NamedExpr>
|
||||||
|
@ -59,19 +59,13 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename ValueType, typename Expr>
|
template <typename Context, typename ValueType, typename Expr>
|
||||||
struct serializer_t<Context, parameterized_verbatim_t<ValueType, Expr>>
|
Context& serialize(const parameterized_verbatim_t<ValueType, Expr>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << t._verbatim_lhs;
|
||||||
using T = parameterized_verbatim_t<ValueType, Expr>;
|
serialize(t._expr, context);
|
||||||
|
context << t._verbatim_rhs;
|
||||||
static Context& _(const T& t, Context& context)
|
return context;
|
||||||
{
|
}
|
||||||
context << t._verbatim_lhs;
|
|
||||||
serialize(t._expr, context);
|
|
||||||
context << t._verbatim_rhs;
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename ValueType, typename Expr>
|
template <typename ValueType, typename Expr>
|
||||||
auto parameterized_verbatim(std::string lhs, Expr expr, std::string rhs)
|
auto parameterized_verbatim(std::string lhs, Expr expr, std::string rhs)
|
||||||
|
@ -88,18 +88,12 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, remove_name_t>
|
Context& serialize(const remove_name_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << "DELETE";
|
||||||
using T = remove_name_t;
|
|
||||||
|
|
||||||
static Context& _(const T& /*unused*/, Context& context)
|
return context;
|
||||||
{
|
}
|
||||||
context << "DELETE";
|
|
||||||
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Database>
|
template <typename Database>
|
||||||
using blank_remove_t = statement_t<Database, remove_t, no_from_t, no_using_t, no_where_t<true>>;
|
using blank_remove_t = statement_t<Database, remove_t, no_from_t, no_using_t, no_where_t<true>>;
|
||||||
|
@ -42,24 +42,18 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Db, typename FieldSpec>
|
template <typename Context, typename Db, typename FieldSpec>
|
||||||
struct serializer_t<Context, result_field_t<Db, FieldSpec>>
|
Context& serialize(const result_field_t<Db, FieldSpec>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
if (t.is_null())
|
||||||
using T = result_field_t<Db, FieldSpec>;
|
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
if (t.is_null())
|
context << "NULL";
|
||||||
{
|
|
||||||
context << "NULL";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
serialize(wrap_operand_t<cpp_value_type_of<FieldSpec>>(t.value()), context);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
else
|
||||||
|
{
|
||||||
|
serialize(wrap_operand_t<cpp_value_type_of<FieldSpec>>(t.value()), context);
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Db, typename FieldSpec>
|
template <typename Db, typename FieldSpec>
|
||||||
inline std::ostream& operator<<(std::ostream& os, const result_field_t<Db, FieldSpec>& rf)
|
inline std::ostream& operator<<(std::ostream& os, const result_field_t<Db, FieldSpec>& rf)
|
||||||
|
@ -40,17 +40,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, schema_t>
|
Context& serialize(const schema_t& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << t._name;
|
||||||
using T = schema_t;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
|
||||||
context << t._name;
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -63,19 +63,13 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Table>
|
template <typename Context, typename Table>
|
||||||
struct serializer_t<Context, schema_qualified_table_t<Table>>
|
Context& serialize(const schema_qualified_table_t<Table>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Table>;
|
serialize(t._schema, context);
|
||||||
using T = schema_qualified_table_t<Table>;
|
context << '.';
|
||||||
|
serialize(t._table, context);
|
||||||
static Context& _(const T& t, Context& context)
|
return context;
|
||||||
{
|
}
|
||||||
serialize(t._schema, context);
|
|
||||||
context << '.';
|
|
||||||
serialize(t._table, context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Table>
|
template <typename Table>
|
||||||
auto schema_qualified_table(schema_t schema, Table table) -> schema_qualified_table_t<Table>
|
auto schema_qualified_table(schema_t schema, Table table) -> schema_qualified_table_t<Table>
|
||||||
|
@ -84,10 +84,7 @@ namespace sqlpp
|
|||||||
static_assert(is_select_flag_t<Flag>::value, "invalid select flag argument in select_flags::add()");
|
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,
|
static_assert(Policies::template _no_unknown_tables<Flag>::value,
|
||||||
"flag uses tables unknown to this statement in select_flags::add()");
|
"flag uses tables unknown to this statement in select_flags::add()");
|
||||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Flag>;
|
using ok = logic::all_t<_is_dynamic::value, is_select_flag_t<Flag>::value>;
|
||||||
_serialize_check{};
|
|
||||||
|
|
||||||
using ok = logic::all_t<_is_dynamic::value, is_select_flag_t<Flag>::value, _serialize_check::type::value>;
|
|
||||||
|
|
||||||
_add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert
|
_add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert
|
||||||
}
|
}
|
||||||
@ -240,26 +237,20 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Database, typename... Flags>
|
template <typename Context, typename Database, typename... Flags>
|
||||||
struct serializer_t<Context, select_flag_list_data_t<Database, Flags...>>
|
Context& serialize(const select_flag_list_data_t<Database, Flags...>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Flags...>;
|
interpret_tuple(t._flags, ' ', context);
|
||||||
using T = select_flag_list_data_t<Database, Flags...>;
|
if (sizeof...(Flags) != 0u)
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
interpret_tuple(t._flags, ' ', context);
|
context << ' ';
|
||||||
if (sizeof...(Flags) != 0u)
|
|
||||||
{
|
|
||||||
context << ' ';
|
|
||||||
}
|
|
||||||
interpret_list(t._dynamic_flags, ',', context);
|
|
||||||
if (not t._dynamic_flags.empty())
|
|
||||||
{
|
|
||||||
context << ' ';
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
interpret_list(t._dynamic_flags, ',', context);
|
||||||
|
if (not t._dynamic_flags.empty())
|
||||||
|
{
|
||||||
|
context << ' ';
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto select_flags(T&& t) -> decltype(statement_t<void, no_select_flag_list_t>().flags(std::forward<T>(t)))
|
auto select_flags(T&& t) -> decltype(statement_t<void, no_select_flag_list_t>().flags(std::forward<T>(t)))
|
||||||
|
@ -43,16 +43,11 @@ namespace sqlpp
|
|||||||
static constexpr all_t all = {};
|
static constexpr all_t all = {};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, all_t>
|
Context& serialize(const all_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << "ALL";
|
||||||
|
return context;
|
||||||
static Context& _(const all_t& /*unused*/, Context& context)
|
}
|
||||||
{
|
|
||||||
context << "ALL";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct distinct_t
|
struct distinct_t
|
||||||
{
|
{
|
||||||
@ -62,16 +57,11 @@ namespace sqlpp
|
|||||||
static constexpr distinct_t distinct = {};
|
static constexpr distinct_t distinct = {};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, distinct_t>
|
Context& serialize(const distinct_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << "DISTINCT";
|
||||||
|
return context;
|
||||||
static Context& _(const distinct_t& /*unused*/, Context& context)
|
}
|
||||||
{
|
|
||||||
context << "DISTINCT";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct straight_join_t
|
struct straight_join_t
|
||||||
{
|
{
|
||||||
@ -81,16 +71,11 @@ namespace sqlpp
|
|||||||
static constexpr straight_join_t straight_join = {};
|
static constexpr straight_join_t straight_join = {};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, straight_join_t>
|
Context& serialize(const straight_join_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << "STRAIGHT_JOIN";
|
||||||
|
return context;
|
||||||
static Context& _(const straight_join_t& /*unused*/, Context& context)
|
}
|
||||||
{
|
|
||||||
context << "STRAIGHT_JOIN";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,29 +27,16 @@
|
|||||||
#ifndef SQLPP11_SERIALIZER_H
|
#ifndef SQLPP11_SERIALIZER_H
|
||||||
#define SQLPP11_SERIALIZER_H
|
#define SQLPP11_SERIALIZER_H
|
||||||
|
|
||||||
#include <sqlpp11/portable_static_assert.h>
|
#include <type_traits>
|
||||||
#include <sqlpp11/wrong.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_serializer_specialization_t, "missing serializer specialization");
|
// FIXME: Move to type_traits.h, for instance
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
std::integral_constant<char, '"'> get_quote_left(const Context&);
|
std::integral_constant<char, '"'> get_quote_left(const Context&);
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
std::integral_constant<char, '"'> get_quote_right(const 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
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -49,17 +49,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Column>
|
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>;
|
context << name_of<typename simple_column_t<Column>::_column_t>::template char_ptr<Context>();
|
||||||
using T = simple_column_t<Column>;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
context << name_of<typename T::_column_t>::template char_ptr<Context>();
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Column>
|
template <typename Column>
|
||||||
simple_column_t<Column> simple_column(Column c)
|
simple_column_t<Column> simple_column(Column c)
|
||||||
|
@ -192,17 +192,11 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Database, typename Table>
|
template <typename Context, typename Database, typename Table>
|
||||||
struct serializer_t<Context, single_table_data_t<Database, Table>>
|
Context& serialize(const single_table_data_t<Database, Table>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Table>;
|
serialize(t._table, context);
|
||||||
using T = single_table_data_t<Database, Table>;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
|
||||||
serialize(t._table, context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -53,19 +53,13 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Select>
|
template <typename Context, typename Select>
|
||||||
struct serializer_t<Context, some_t<Select>>
|
Context& serialize(const some_t<Select>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Select>;
|
context << "SOME(";
|
||||||
using T = some_t<Select>;
|
serialize(t._select, context);
|
||||||
|
context << ")";
|
||||||
static Context& _(const T& t, Context& context)
|
return context;
|
||||||
{
|
}
|
||||||
context << "SOME(";
|
|
||||||
serialize(t._select, context);
|
|
||||||
context << ")";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto some(T t) -> some_t<wrap_operand_t<T>>
|
auto some(T t) -> some_t<wrap_operand_t<T>>
|
||||||
|
@ -50,26 +50,20 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Expression>
|
template <typename Context, typename Expression>
|
||||||
struct serializer_t<Context, sort_order_t<Expression>>
|
Context& serialize(const sort_order_t<Expression>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Expression>;
|
serialize_operand(t._expression, context);
|
||||||
using T = sort_order_t<Expression>;
|
switch (t._sort_type)
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
serialize_operand(t._expression, context);
|
case sort_type::asc:
|
||||||
switch (t._sort_type)
|
context << " ASC";
|
||||||
{
|
break;
|
||||||
case sort_type::asc:
|
default:
|
||||||
context << " ASC";
|
context << " DESC";
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
context << " DESC";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
return context;
|
||||||
|
}
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,19 +81,13 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Flag, typename Expr>
|
template <typename Context, typename Flag, typename Expr>
|
||||||
struct serializer_t<Context, trim_t<Flag, Expr>>
|
Context& serialize(const trim_t<Flag, Expr>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
|
context << "TRIM(";
|
||||||
using T = trim_t<Flag, Expr>;
|
serialize(t._expr, context);
|
||||||
|
context << ")";
|
||||||
static Context& _(const T& t, Context& context)
|
return context;
|
||||||
{
|
}
|
||||||
context << "TRIM(";
|
|
||||||
serialize(t._expr, context);
|
|
||||||
context << ")";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto trim(T t) -> trim_t<noop, wrap_operand_t<T>>
|
auto trim(T t) -> trim_t<noop, wrap_operand_t<T>>
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <sqlpp11/consistent.h>
|
#include <sqlpp11/consistent.h>
|
||||||
|
#include <sqlpp11/portable_static_assert.h>
|
||||||
#include <sqlpp11/serializer.h>
|
#include <sqlpp11/serializer.h>
|
||||||
#include <sqlpp11/detail/type_vector.h>
|
#include <sqlpp11/detail/type_vector.h>
|
||||||
#include <sqlpp11/detail/type_set.h>
|
#include <sqlpp11/detail/type_set.h>
|
||||||
@ -391,10 +392,6 @@ namespace sqlpp
|
|||||||
using is_inconsistent_t =
|
using is_inconsistent_t =
|
||||||
typename std::conditional<std::is_same<consistent_t, T>::value, std::false_type, std::true_type>::type;
|
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_sqlpp_type_t, "expression is not an sqlpp type, consistency cannot be verified");
|
||||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_run_statement_or_prepared_t,
|
SQLPP_PORTABLE_STATIC_ASSERT(assert_run_statement_or_prepared_t,
|
||||||
"connection cannot run something that is neither statement nor prepared statement");
|
"connection cannot run something that is neither statement nor prepared statement");
|
||||||
@ -416,21 +413,6 @@ namespace sqlpp
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
using consistency_check_t = typename consistency_check<T>::type;
|
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>
|
template <typename Context, typename T, typename Enable = void>
|
||||||
struct run_check
|
struct run_check
|
||||||
{
|
{
|
||||||
@ -459,7 +441,7 @@ namespace sqlpp
|
|||||||
struct prepare_check<Context, T, typename std::enable_if<is_statement_t<T>::value>::type>
|
struct prepare_check<Context, T, typename std::enable_if<is_statement_t<T>::value>::type>
|
||||||
{
|
{
|
||||||
using type = detail::
|
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>
|
template <typename Context, typename T>
|
||||||
|
@ -50,21 +50,15 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Database, typename Flag, typename Lhs, typename Rhs>
|
template <typename Context, typename Database, typename Flag, typename Lhs, typename Rhs>
|
||||||
struct serializer_t<Context, union_data_t<Database, Flag, Lhs, Rhs>>
|
Context& serialize(const union_data_t<Database, Flag, Lhs, Rhs>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
|
serialize(t._lhs, context);
|
||||||
using T = union_data_t<Database, Flag, Lhs, Rhs>;
|
context << " UNION ";
|
||||||
|
serialize(Flag{}, context);
|
||||||
static Context& _(const T& t, Context& context)
|
context << " ";
|
||||||
{
|
serialize(t._rhs, context);
|
||||||
serialize(t._lhs, context);
|
return context;
|
||||||
context << " UNION ";
|
}
|
||||||
serialize(Flag{}, context);
|
|
||||||
context << " ";
|
|
||||||
serialize(t._rhs, context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,16 +42,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, union_all_t>
|
Context& serialize(const union_all_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << "ALL";
|
||||||
|
return context;
|
||||||
static Context& _(const union_all_t& /*unused*/, Context& context)
|
}
|
||||||
{
|
|
||||||
context << "ALL";
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct union_distinct_t
|
struct union_distinct_t
|
||||||
{
|
{
|
||||||
@ -60,15 +55,10 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, union_distinct_t>
|
Context& serialize(const union_distinct_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const union_distinct_t& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -89,18 +89,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, update_name_t>
|
Context& serialize(const update_name_t&, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << "UPDATE ";
|
||||||
using T = update_name_t;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& /*unused*/, Context& context)
|
|
||||||
{
|
|
||||||
context << "UPDATE ";
|
|
||||||
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Database>
|
template <typename Database>
|
||||||
using blank_update_t = statement_t<Database, update_t, no_single_table_t, no_update_list_t, no_where_t<true>>;
|
using blank_update_t = statement_t<Database, update_t, no_single_table_t, no_update_list_t, no_where_t<true>>;
|
||||||
|
@ -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(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,
|
static_assert(Policies::template _no_unknown_tables<Assignment>::value,
|
||||||
"assignment uses tables unknown to this statement in add()");
|
"assignment uses tables unknown to this statement in add()");
|
||||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Assignment>;
|
using ok = logic::all_t<_is_dynamic::value, is_assignment_t<Assignment>::value>;
|
||||||
_serialize_check{};
|
|
||||||
|
|
||||||
using ok = logic::all_t<_is_dynamic::value, is_assignment_t<Assignment>::value, _serialize_check::type::value>;
|
|
||||||
|
|
||||||
_add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert
|
_add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert
|
||||||
}
|
}
|
||||||
@ -294,23 +291,17 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Database, typename... Assignments>
|
template <typename Context, typename Database, typename... Assignments>
|
||||||
struct serializer_t<Context, update_list_data_t<Database, Assignments...>>
|
Context& serialize(const update_list_data_t<Database, Assignments...>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Assignments...>;
|
context << " SET ";
|
||||||
using T = update_list_data_t<Database, Assignments...>;
|
interpret_tuple(t._assignments, ",", context);
|
||||||
|
if (sizeof...(Assignments) and not t._dynamic_assignments.empty())
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
context << " SET ";
|
context << ',';
|
||||||
interpret_tuple(t._assignments, ",", context);
|
|
||||||
if (sizeof...(Assignments) and not t._dynamic_assignments.empty())
|
|
||||||
{
|
|
||||||
context << ',';
|
|
||||||
}
|
|
||||||
interpret_list(t._dynamic_assignments, ',', context);
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
interpret_list(t._dynamic_assignments, ',', context);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -80,10 +80,7 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
static_assert(_is_dynamic::value, "add must not be called for static using()");
|
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()");
|
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>;
|
using ok = logic::all_t<_is_dynamic::value, is_table_t<Table>::value>;
|
||||||
_serialize_check{};
|
|
||||||
|
|
||||||
using ok = logic::all_t<_is_dynamic::value, is_table_t<Table>::value, _serialize_check::type::value>;
|
|
||||||
|
|
||||||
_add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert
|
_add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert
|
||||||
}
|
}
|
||||||
@ -240,27 +237,21 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Database, typename... Tables>
|
template <typename Context, typename Database, typename... Tables>
|
||||||
struct serializer_t<Context, using_data_t<Database, Tables...>>
|
Context& serialize(const using_data_t<Database, Tables...>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Tables...>;
|
if (sizeof...(Tables) == 0 and t._dynamic_tables.empty())
|
||||||
using T = using_data_t<Database, Tables...>;
|
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
{
|
||||||
if (sizeof...(Tables) == 0 and t._dynamic_tables.empty())
|
|
||||||
{
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
context << " USING ";
|
|
||||||
interpret_tuple(t._tables, ',', context);
|
|
||||||
if (sizeof...(Tables) and not t._dynamic_tables.empty())
|
|
||||||
{
|
|
||||||
context << ',';
|
|
||||||
}
|
|
||||||
interpret_list(t._dynamic_tables, ',', context);
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
};
|
context << " USING ";
|
||||||
|
interpret_tuple(t._tables, ',', context);
|
||||||
|
if (sizeof...(Tables) and not t._dynamic_tables.empty())
|
||||||
|
{
|
||||||
|
context << ',';
|
||||||
|
}
|
||||||
|
interpret_list(t._dynamic_tables, ',', context);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,17 +57,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename ValueType>
|
template <typename Context, typename ValueType>
|
||||||
struct serializer_t<Context, verbatim_t<ValueType>>
|
Context& serialize(const verbatim_t<ValueType>& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << t._verbatim;
|
||||||
using T = verbatim_t<ValueType>;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
|
||||||
context << t._verbatim;
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename ValueType, typename StringType>
|
template <typename ValueType, typename StringType>
|
||||||
auto verbatim(StringType s) -> verbatim_t<ValueType>
|
auto verbatim(StringType s) -> verbatim_t<ValueType>
|
||||||
|
@ -76,17 +76,11 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct serializer_t<Context, verbatim_table_t>
|
Context& serialize(const verbatim_table_t& t, Context& context)
|
||||||
{
|
{
|
||||||
using _serialize_check = consistent_t;
|
context << t._representation;
|
||||||
using T = verbatim_table_t;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
|
||||||
context << t._representation;
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline verbatim_table_t verbatim_table(std::string name)
|
inline verbatim_table_t verbatim_table(std::string name)
|
||||||
{
|
{
|
||||||
|
@ -93,10 +93,7 @@ namespace sqlpp
|
|||||||
"expression uses tables unknown to this statement in where::add()");
|
"expression uses tables unknown to this statement in where::add()");
|
||||||
static_assert(not contains_aggregate_function_t<Expr>::value,
|
static_assert(not contains_aggregate_function_t<Expr>::value,
|
||||||
"where expression must not contain aggregate functions");
|
"where expression must not contain aggregate functions");
|
||||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expr>;
|
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value>;
|
||||||
_serialize_check{};
|
|
||||||
|
|
||||||
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value, _serialize_check::type::value>;
|
|
||||||
|
|
||||||
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
|
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
|
||||||
}
|
}
|
||||||
|
@ -191,24 +191,19 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Interpreters
|
// Interpreters
|
||||||
template <typename Context, typename Database, typename... Expressions>
|
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...>;
|
using T = with_data_t<Database, Expressions...>;
|
||||||
|
// FIXME: If there is a recursive CTE, add a "RECURSIVE" here
|
||||||
static Context& _(const T& t, Context& context)
|
context << " WITH ";
|
||||||
|
if (T::_is_recursive::value)
|
||||||
{
|
{
|
||||||
// FIXME: If there is a recursive CTE, add a "RECURSIVE" here
|
context << "RECURSIVE ";
|
||||||
context << " WITH ";
|
|
||||||
if (T::_is_recursive::value)
|
|
||||||
{
|
|
||||||
context << "RECURSIVE ";
|
|
||||||
}
|
|
||||||
interpret_tuple(t._expressions, ',', context);
|
|
||||||
context << ' ';
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
};
|
interpret_tuple(t._expressions, ',', context);
|
||||||
|
context << ' ';
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename... Expressions>
|
template <typename... Expressions>
|
||||||
auto with(Expressions... cte) -> blank_with_t<void, Expressions...>
|
auto with(Expressions... cte) -> blank_with_t<void, Expressions...>
|
||||||
|
@ -33,27 +33,23 @@
|
|||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
template <typename Expression>
|
template <typename Expression>
|
||||||
struct without_table_check_t : Expression
|
struct without_table_check_t: public Expression
|
||||||
{
|
{
|
||||||
using _required_tables = detail::type_set<>;
|
using _required_tables = detail::type_set<>;
|
||||||
|
|
||||||
without_table_check_t(Expression expression) : Expression(expression)
|
without_table_check_t(Expression expression) : Expression(expression)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Expression& expr() const { return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Expression>
|
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>;
|
serialize(t.expr(), context);
|
||||||
using T = without_table_check_t<Expression>;
|
return context;
|
||||||
|
}
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
|
||||||
serialize<Expression>(t, context);
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Expression>
|
template <typename Expression>
|
||||||
auto without_table_check(Expression expr) -> without_table_check_t<Expression>
|
auto without_table_check(Expression expr) -> without_table_check_t<Expression>
|
||||||
|
@ -30,21 +30,21 @@ target_compile_options(sqlpp11_testing INTERFACE -Wall -Wextra -pedantic)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
set(test_names
|
set(test_names
|
||||||
#BooleanExpression
|
BooleanExpression
|
||||||
#CustomQuery
|
CustomQuery
|
||||||
#DateTime
|
DateTime
|
||||||
#Interpret
|
Interpret
|
||||||
#Insert
|
Insert
|
||||||
#Remove
|
Remove
|
||||||
#Update
|
Update
|
||||||
Select
|
Select
|
||||||
#SelectType
|
SelectType
|
||||||
#Function
|
Function
|
||||||
#Prepared
|
Prepared
|
||||||
#Minimalistic
|
Minimalistic
|
||||||
#Result
|
Result
|
||||||
#Union
|
Union
|
||||||
#With
|
With
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(Boost 1.50)
|
find_package(Boost 1.50)
|
||||||
|
@ -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_
|
namespace TabBar_
|
||||||
{
|
{
|
||||||
struct Alpha
|
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_
|
namespace TabDateTime_
|
||||||
{
|
{
|
||||||
struct ColDayPoint
|
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
|
} // namespace test
|
||||||
#endif
|
#endif
|
||||||
|
@ -74,7 +74,6 @@ int Select(int, char*[])
|
|||||||
select(count(t.alpha));
|
select(count(t.alpha));
|
||||||
|
|
||||||
std::cerr << serialize(select(sqlpp::value(false).as(sqlpp::alias::a)), printer).str() << std::endl;
|
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))))
|
for (const auto& row : db(select(sqlpp::value(false).as(sqlpp::alias::a))))
|
||||||
{
|
{
|
||||||
std::cout << row.a << std::endl;
|
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;
|
std::cout << "Error: transaction isolation level does not match default level" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user