mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Reduce error messages for serialize, add first serialize test for dynamic AND
This commit is contained in:
parent
7cc4e45abd
commit
0f4d3b1451
@ -58,15 +58,15 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Flag, typename Expr>
|
||||
Context& serialize(const avg_t<Flag, Expr>& t, Context& context)
|
||||
Context& serialize(Context& context, const avg_t<Flag, Expr>& t)
|
||||
{
|
||||
context << "AVG(";
|
||||
if (std::is_same<distinct_t, Flag>::value)
|
||||
{
|
||||
serialize(Flag(), context);
|
||||
serialize(context, Flag());
|
||||
context << ' ';
|
||||
}
|
||||
serialize_operand(t._expr, context);
|
||||
serialize_operand(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
@ -63,15 +63,15 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Flag, typename Expr>
|
||||
Context& serialize(const count_t<Flag, Expr>& t, Context& context)
|
||||
Context& serialize(Context& context, const count_t<Flag, Expr>& t)
|
||||
{
|
||||
context << "COUNT(";
|
||||
if (std::is_same<distinct_t, Flag>::value)
|
||||
{
|
||||
serialize(Flag(), context);
|
||||
serialize(context, Flag());
|
||||
context << ' ';
|
||||
}
|
||||
serialize_operand(t._expr, context);
|
||||
serialize_operand(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
@ -59,15 +59,15 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Flag, typename Expr>
|
||||
Context& serialize(const max_t<Flag, Expr>& t, Context& context)
|
||||
Context& serialize(Context& context, const max_t<Flag, Expr>& t)
|
||||
{
|
||||
context << "MAX(";
|
||||
if (std::is_same<distinct_t, Flag>::value)
|
||||
{
|
||||
serialize(Flag(), context);
|
||||
serialize(context, Flag());
|
||||
context << ' ';
|
||||
}
|
||||
serialize_operand(t._expr, context);
|
||||
serialize_operand(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
@ -59,15 +59,15 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Flag, typename Expr>
|
||||
Context& serialize(const min_t<Flag, Expr>& t, Context& context)
|
||||
Context& serialize(Context& context, const min_t<Flag, Expr>& t)
|
||||
{
|
||||
context << "MIN(";
|
||||
if (std::is_same<distinct_t, Flag>::value)
|
||||
{
|
||||
serialize(Flag(), context);
|
||||
serialize(context, Flag());
|
||||
context << ' ';
|
||||
}
|
||||
serialize_operand(t._expr, context);
|
||||
serialize_operand(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
@ -60,15 +60,15 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Flag, typename Expr>
|
||||
Context& serialize(const sum_t<Flag, Expr>& t, Context& context)
|
||||
Context& serialize(Context& context, const sum_t<Flag, Expr>& t)
|
||||
{
|
||||
context << "SUM(";
|
||||
if (std::is_same<distinct_t, Flag>::value)
|
||||
{
|
||||
serialize(Flag(), context);
|
||||
serialize(context, Flag());
|
||||
context << ' ';
|
||||
}
|
||||
serialize_operand(t._expr, context);
|
||||
serialize_operand(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
@ -45,5 +45,5 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename ValueType>
|
||||
Context serialize(const bad_expression<ValueType>& t, Context& context);
|
||||
Context serialize(Context& context, const bad_expression<ValueType>& t);
|
||||
} // namespace sqlpp
|
||||
|
@ -147,14 +147,14 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename When, typename Then, typename Else>
|
||||
Context& serialize(const case_t<When, Then, Else>& t, Context& context)
|
||||
Context& serialize(Context& context, const case_t<When, Then, Else>& t)
|
||||
{
|
||||
context << "(CASE WHEN ";
|
||||
serialize(t._when, context);
|
||||
serialize(context, t._when);
|
||||
context << " THEN ";
|
||||
serialize(t._then, context);
|
||||
serialize(context, t._then);
|
||||
context << " ELSE ";
|
||||
serialize(t._else, context);
|
||||
serialize(context, t._else);
|
||||
context << " END)";
|
||||
return context;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Table, typename ColumnSpec>
|
||||
Context& serialize(const column_t<Table, ColumnSpec>&, Context& context)
|
||||
Context& serialize(Context& context, const column_t<Table, ColumnSpec>&)
|
||||
{
|
||||
using T = column_t<Table, ColumnSpec>;
|
||||
|
||||
|
@ -60,13 +60,13 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Flag, typename Lhs, typename Rhs>
|
||||
Context& serialize(const cte_union_t<Flag, Lhs, Rhs>& t, Context& context)
|
||||
Context& serialize(Context& context, const cte_union_t<Flag, Lhs, Rhs>& t)
|
||||
{
|
||||
serialize(t._lhs, context);
|
||||
serialize(context, t._lhs);
|
||||
context << " UNION ";
|
||||
serialize(Flag{}, context);
|
||||
serialize(context, Flag{});
|
||||
context << " ";
|
||||
serialize(t._rhs, context);
|
||||
serialize(context, t._rhs);
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -217,11 +217,11 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename AliasProvider, typename Statement, typename... ColumnSpecs>
|
||||
Context& serialize(const cte_t<AliasProvider, Statement, ColumnSpecs...>& t, Context& context)
|
||||
Context& serialize(Context& context, const cte_t<AliasProvider, Statement, ColumnSpecs...>& t)
|
||||
{
|
||||
using T = cte_t<AliasProvider, Statement, ColumnSpecs...>;
|
||||
context << name_of<T>::template char_ptr<Context>() << " AS (";
|
||||
serialize(t._statement, context);
|
||||
serialize(context, t._statement);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
@ -253,7 +253,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename AliasProvider>
|
||||
Context& serialize(const cte_ref_t<AliasProvider>&, Context& context)
|
||||
Context& serialize(Context& context, const cte_ref_t<AliasProvider>&)
|
||||
{
|
||||
context << name_of<cte_ref_t<AliasProvider>>::template char_ptr<Context>();
|
||||
return context;
|
||||
|
@ -122,7 +122,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename... Parts>
|
||||
Context& serialize(const custom_query_t<Parts...>& t, Context& context)
|
||||
Context& serialize(Context& context, const custom_query_t<Parts...>& t)
|
||||
{
|
||||
interpret_tuple_without_braces(t._parts, " ", context);
|
||||
return context;
|
||||
|
@ -37,7 +37,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const default_value_t&, Context& context)
|
||||
Context& serialize(Context& context, const default_value_t&)
|
||||
{
|
||||
context << "DEFAULT";
|
||||
return context;
|
||||
|
@ -85,11 +85,11 @@ namespace sqlpp
|
||||
using dynamic_to_optional_t = typename dynamic_to_optional<T>::type;
|
||||
|
||||
template <typename Context, typename Select>
|
||||
Context& serialize(const dynamic_t<Select>& t, Context& context)
|
||||
Context& serialize(Context& context, const dynamic_t<Select>& t)
|
||||
{
|
||||
if (t._condition)
|
||||
{
|
||||
serialize(t._expr, context);
|
||||
serialize(context, t._expr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -92,7 +92,7 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context>
|
||||
Context& serialize(const for_update_data_t&, Context& context)
|
||||
Context& serialize(Context& context, const for_update_data_t&)
|
||||
{
|
||||
context << " FOR UPDATE ";
|
||||
return context;
|
||||
|
@ -137,10 +137,10 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Table>
|
||||
Context& serialize(const from_data_t<Table>& t, Context& context)
|
||||
Context& serialize(Context& context, const from_data_t<Table>& t)
|
||||
{
|
||||
context << " FROM ";
|
||||
serialize(t._table, context);
|
||||
serialize(context, t._table);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ namespace sqlpp
|
||||
static_assert(not make_parameter_list_t<Expression>::size::value,
|
||||
"parameters are not allowed in flattened expressions");
|
||||
auto context = db.get_serializer_context();
|
||||
serialize(exp, context);
|
||||
serialize(context, exp);
|
||||
return {context.str()};
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename... Expressions>
|
||||
Context& serialize(const group_by_data_t<Expressions...>& t, Context& context)
|
||||
Context& serialize(Context& context, const group_by_data_t<Expressions...>& t)
|
||||
{
|
||||
context << " GROUP BY ";
|
||||
interpret_tuple(t._expressions, ',', context);
|
||||
|
@ -176,10 +176,10 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Expression>
|
||||
Context& serialize(const having_data_t<Expression>& t, Context& context)
|
||||
Context& serialize(Context& context, const having_data_t<Expression>& t)
|
||||
{
|
||||
context << " HAVING ";
|
||||
serialize(t._expression, context);
|
||||
serialize(context, t._expression);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Clause>
|
||||
Context& serialize(const hidden_t<Clause>&, Context& context)
|
||||
Context& serialize(Context& context, const hidden_t<Clause>&)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const insert_name_t&, Context& context)
|
||||
Context& serialize(Context& context, const insert_name_t&)
|
||||
{
|
||||
context << "INSERT";
|
||||
|
||||
|
@ -87,7 +87,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename ValueType>
|
||||
Context& serialize(const insert_value_t<ValueType>& t, Context& context)
|
||||
Context& serialize(Context& context, const insert_value_t<ValueType>& t)
|
||||
{
|
||||
if (t._is_null)
|
||||
{
|
||||
@ -99,7 +99,7 @@ namespace sqlpp
|
||||
}
|
||||
else
|
||||
{
|
||||
serialize_operand(t._value, context);
|
||||
serialize_operand(context, t._value);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context>
|
||||
Context& serialize(const insert_default_values_data_t&, Context& context)
|
||||
Context& serialize(Context& context, const insert_default_values_data_t&)
|
||||
{
|
||||
context << " DEFAULT VALUES";
|
||||
return context;
|
||||
@ -393,7 +393,7 @@ namespace sqlpp
|
||||
|
||||
|
||||
template <typename Context, typename... Columns>
|
||||
Context& serialize(const column_list_data_t<Columns...>& t, Context& context)
|
||||
Context& serialize(Context& context, const column_list_data_t<Columns...>& t)
|
||||
{
|
||||
context << " (";
|
||||
interpret_tuple(t._columns, ",", context);
|
||||
@ -419,7 +419,7 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Context, typename... Assignments>
|
||||
Context& serialize(const insert_list_data_t<Assignments...>& t, Context& context)
|
||||
Context& serialize(Context& context, const insert_list_data_t<Assignments...>& t)
|
||||
{
|
||||
context << " (";
|
||||
interpret_tuple(t._columns, ",", context);
|
||||
|
@ -43,11 +43,11 @@ namespace sqlpp
|
||||
}
|
||||
if (UseBraces::value)
|
||||
{
|
||||
serialize_operand(element, context);
|
||||
serialize_operand(context, element);
|
||||
}
|
||||
else
|
||||
{
|
||||
serialize(element, context);
|
||||
serialize(context, element);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,10 +137,10 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Table>
|
||||
Context& serialize(const into_data_t<Table>& t, Context& context)
|
||||
Context& serialize(Context& context, const into_data_t<Table>& t)
|
||||
{
|
||||
context << " INTO ";
|
||||
serialize(t._table, context);
|
||||
serialize(context, t._table);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -82,10 +82,10 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename PreJoin, typename On>
|
||||
Context& serialize(const join_t<PreJoin, On>& t, Context& context)
|
||||
Context& serialize(Context& context, const join_t<PreJoin, On>& t)
|
||||
{
|
||||
serialize(t._pre_join, context);
|
||||
serialize(t._on, context);
|
||||
serialize(context, t._pre_join);
|
||||
serialize(context, t._on);
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -128,10 +128,10 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Limit>
|
||||
Context& serialize(const limit_data_t<Limit>& t, Context& context)
|
||||
Context& serialize(Context& context, const limit_data_t<Limit>& t)
|
||||
{
|
||||
context << " LIMIT ";
|
||||
serialize_operand(t._value, context);
|
||||
serialize_operand(context, t._value);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -52,10 +52,10 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Expr>
|
||||
Context& serialize(const lower_t<Expr>& t, Context& context)
|
||||
Context& serialize(Context& context, const lower_t<Expr>& t)
|
||||
{
|
||||
context << "LOWER(";
|
||||
serialize_operand(t._expr, context);
|
||||
serialize_operand(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
@ -272,13 +272,13 @@ namespace sqlpp
|
||||
template <typename T>
|
||||
static _context_t& _serialize_interpretable(const T& t, _context_t& context)
|
||||
{
|
||||
return serialize(t, context);
|
||||
return serialize(context, t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static _context_t& _interpret_interpretable(const T& t, _context_t& context)
|
||||
{
|
||||
return serialize(t, context);
|
||||
return serialize(context, t);
|
||||
}
|
||||
|
||||
[[deprecated("Use ping_server() instead")]] bool is_valid() const
|
||||
@ -295,7 +295,7 @@ namespace sqlpp
|
||||
char_result_t select(const Select& s)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(s, context);
|
||||
serialize(context, s);
|
||||
return select_impl(context.str());
|
||||
}
|
||||
|
||||
@ -303,7 +303,7 @@ namespace sqlpp
|
||||
_prepared_statement_t prepare_select(Select& s)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(s, context);
|
||||
serialize(context, s);
|
||||
return prepare_impl(context.str(), s._get_no_of_parameters(), s.get_no_of_result_columns());
|
||||
}
|
||||
|
||||
@ -319,7 +319,7 @@ namespace sqlpp
|
||||
size_t insert(const Insert& i)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(i, context);
|
||||
serialize(context, i);
|
||||
return insert_impl(context.str());
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ namespace sqlpp
|
||||
_prepared_statement_t prepare_insert(Insert& i)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(i, context);
|
||||
serialize(context, i);
|
||||
return prepare_impl(context.str(), i._get_no_of_parameters(), 0);
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ namespace sqlpp
|
||||
size_t update(const Update& u)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(u, context);
|
||||
serialize(context, u);
|
||||
return update_impl(context.str());
|
||||
}
|
||||
|
||||
@ -351,7 +351,7 @@ namespace sqlpp
|
||||
_prepared_statement_t prepare_update(Update& u)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(u, context);
|
||||
serialize(context, u);
|
||||
return prepare_impl(context.str(), u._get_no_of_parameters(), 0);
|
||||
}
|
||||
|
||||
@ -367,7 +367,7 @@ namespace sqlpp
|
||||
size_t remove(const Remove& r)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(r, context);
|
||||
serialize(context, r);
|
||||
return remove_impl(context.str());
|
||||
}
|
||||
|
||||
@ -375,7 +375,7 @@ namespace sqlpp
|
||||
_prepared_statement_t prepare_remove(Remove& r)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(r, context);
|
||||
serialize(context, r);
|
||||
return prepare_impl(context.str(), r._get_no_of_parameters(), 0);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const no_data_t&, Context& context)
|
||||
Context& serialize(Context& context, const no_data_t&)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const noop&, Context& context)
|
||||
Context& serialize(Context& context, const noop&)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
@ -140,10 +140,10 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Offset>
|
||||
Context& serialize(const offset_data_t<Offset>& t, Context& context)
|
||||
Context& serialize(Context& context, const offset_data_t<Offset>& t)
|
||||
{
|
||||
context << " OFFSET ";
|
||||
serialize_operand(t._value, context);
|
||||
serialize_operand(context, t._value);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -62,16 +62,16 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const on_t<unconditional_t>&, Context& context)
|
||||
Context& serialize(Context& context, const on_t<unconditional_t>&)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context, typename Expression>
|
||||
Context& serialize(const on_t<Expression>& t, Context& context)
|
||||
Context& serialize(Context& context, const on_t<Expression>& t)
|
||||
{
|
||||
context << " ON ";
|
||||
serialize(t._expression, context);
|
||||
serialize(context, t._expression);
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -69,10 +69,10 @@ namespace sqlpp
|
||||
using remove_any_t = typename remove_any<T>::type;
|
||||
|
||||
template <typename Context, typename Select>
|
||||
Context& serialize(const any_t<Select>& t, Context& context)
|
||||
Context& serialize(Context& context, const any_t<Select>& t)
|
||||
{
|
||||
context << "ANY";
|
||||
serialize_operand(t._select, context);
|
||||
serialize_operand(context, t._select);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -72,9 +72,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Expression, typename AliasProvider>
|
||||
Context& serialize(const as_expression<Expression, AliasProvider>& t, Context& context)
|
||||
Context& serialize(Context& context, const as_expression<Expression, AliasProvider>& t)
|
||||
{
|
||||
serialize_operand(t._expression, context);
|
||||
serialize_operand(context, t._expression);
|
||||
context << " AS ";
|
||||
context << name_of<as_expression<Expression, AliasProvider>>::template char_ptr<Context>();
|
||||
return context;
|
||||
|
@ -88,11 +88,11 @@ namespace sqlpp
|
||||
*/
|
||||
|
||||
template <typename Context, typename L, typename R>
|
||||
Context& serialize(const assign_expression<L, R>& t, Context& context)
|
||||
Context& serialize(Context& context, const assign_expression<L, R>& t)
|
||||
{
|
||||
serialize(simple_column(t._lhs), context);
|
||||
serialize(context, simple_column(t._lhs));
|
||||
context << "=";
|
||||
serialize_operand(t._rhs, context);
|
||||
serialize_operand(context, t._rhs);
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -94,13 +94,13 @@ namespace sqlpp
|
||||
|
||||
#if 0 // original serialize implementation
|
||||
template <typename Context, typename Operand, typename Arg, typename... Args>
|
||||
Context& serialize(const between_t<Operand, Arg, Args...>& t, Context& context)
|
||||
Context& serialize(Context& context, const between_t<Operand, Arg, Args...>& t)
|
||||
{
|
||||
serialize(t._operand, context);
|
||||
serialize(context, t._operand);
|
||||
context << " IN(";
|
||||
if (sizeof...(Args) == 0)
|
||||
{
|
||||
serialize(std::get<0>(t._args), context);
|
||||
serialize(context, std::get<0>(t._args));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -111,9 +111,9 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Context, typename Operand>
|
||||
Context& serialize(const between_t<Operand>&, Context& context)
|
||||
Context& serialize(Context& context, const between_t<Operand>&)
|
||||
{
|
||||
serialize(boolean_operand{false}, context);
|
||||
serialize(context, boolean_operand{false});
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -121,18 +121,18 @@ namespace sqlpp
|
||||
struct value_list_t;
|
||||
|
||||
template <typename Context, typename Operand, typename Container>
|
||||
Context& serialize(const between_t<Operand, value_list_t<Container>>& t, Context& context)
|
||||
Context& serialize(Context& context, const between_t<Operand, value_list_t<Container>>& t)
|
||||
{
|
||||
const auto& value_list = std::get<0>(t._args);
|
||||
if (value_list._container.empty())
|
||||
{
|
||||
serialize(boolean_operand{false}, context);
|
||||
serialize(context, boolean_operand{false});
|
||||
}
|
||||
else
|
||||
{
|
||||
serialize(t._operand, context);
|
||||
serialize(context, t._operand);
|
||||
context << " IN(";
|
||||
serialize(value_list, context);
|
||||
serialize(context, value_list);
|
||||
context << ')';
|
||||
}
|
||||
return context;
|
||||
|
@ -132,13 +132,13 @@ namespace sqlpp
|
||||
|
||||
#if 0 // original serialize implementation
|
||||
template <typename Context, typename Operand, typename Arg, typename... Args>
|
||||
Context& serialize(const in_t<Operand, Arg, Args...>& t, Context& context)
|
||||
Context& serialize(Context& context, const in_t<Operand, Arg, Args...>& t)
|
||||
{
|
||||
serialize(t._operand, context);
|
||||
serialize(context, t._operand);
|
||||
context << " IN(";
|
||||
if (sizeof...(Args) == 0)
|
||||
{
|
||||
serialize(std::get<0>(t._args), context);
|
||||
serialize(context, std::get<0>(t._args));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -149,9 +149,9 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Context, typename Operand>
|
||||
Context& serialize(const in_t<Operand>&, Context& context)
|
||||
Context& serialize(Context& context, const in_t<Operand>&)
|
||||
{
|
||||
serialize(boolean_operand{false}, context);
|
||||
serialize(context, boolean_operand{false});
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -159,18 +159,18 @@ namespace sqlpp
|
||||
struct value_list_t;
|
||||
|
||||
template <typename Context, typename Operand, typename Container>
|
||||
Context& serialize(const in_t<Operand, value_list_t<Container>>& t, Context& context)
|
||||
Context& serialize(Context& context, const in_t<Operand, value_list_t<Container>>& t)
|
||||
{
|
||||
const auto& value_list = std::get<0>(t._args);
|
||||
if (value_list._container.empty())
|
||||
{
|
||||
serialize(boolean_operand{false}, context);
|
||||
serialize(context, boolean_operand{false});
|
||||
}
|
||||
else
|
||||
{
|
||||
serialize(t._operand, context);
|
||||
serialize(context, t._operand);
|
||||
context << " IN(";
|
||||
serialize(value_list, context);
|
||||
serialize(context, value_list);
|
||||
context << ')';
|
||||
}
|
||||
return context;
|
||||
|
@ -134,6 +134,35 @@ namespace sqlpp
|
||||
return to_sql_string(context, t._l) + Operator::symbol + to_sql_string(context, embrace(t._r));
|
||||
}
|
||||
*/
|
||||
template <typename Context, typename L, typename Operator, typename R>
|
||||
auto serialize_impl(Context& context, const logical_expression<L, Operator, R>& t) -> Context&
|
||||
{
|
||||
context << "(";
|
||||
serialize_operand(context, t._l);
|
||||
context << Operator::symbol;
|
||||
serialize_operand(context, t._r);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context, typename L, typename Operator, typename R>
|
||||
auto serialize(Context& context, const logical_expression<L, Operator, R>& t) -> Context&
|
||||
{
|
||||
serialize_impl(context, t);
|
||||
}
|
||||
|
||||
template <typename Context, typename L, typename Operator, typename R>
|
||||
auto serialize(Context& context, const logical_expression<L, Operator, dynamic_t<R>>& t) -> Context&
|
||||
{
|
||||
if (t._r._condition)
|
||||
{
|
||||
return serialize_impl(context, t);
|
||||
}
|
||||
|
||||
// If the dynamic part is inactive ignore it.
|
||||
serialize(context, t._l);
|
||||
return context;
|
||||
}
|
||||
|
||||
struct logical_and
|
||||
{
|
||||
|
@ -146,7 +146,7 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename... Expressions>
|
||||
Context& serialize(const order_by_data_t<Expressions...>& t, Context& context)
|
||||
Context& serialize(Context& context, const order_by_data_t<Expressions...>& t)
|
||||
{
|
||||
context << " ORDER BY ";
|
||||
interpret_tuple(t._expressions, ',', context);
|
||||
|
@ -54,9 +54,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename AggregateExpr>
|
||||
Context& serialize(const over_t<AggregateExpr>& t, Context& context)
|
||||
Context& serialize(Context& context, const over_t<AggregateExpr>& t)
|
||||
{
|
||||
serialize_operand(t._aggregate_expression, context);
|
||||
serialize_operand(context, t._aggregate_expression);
|
||||
context << " OVER()";
|
||||
return context;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename ValueType, typename NameType>
|
||||
Context& serialize(const parameter_t<ValueType, NameType>&, Context& context)
|
||||
Context& serialize(Context& context, const parameter_t<ValueType, NameType>&)
|
||||
{
|
||||
context << "?";
|
||||
return context;
|
||||
|
@ -57,10 +57,10 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename ValueType, typename Expr>
|
||||
Context& serialize(const parameterized_verbatim_t<ValueType, Expr>& t, Context& context)
|
||||
Context& serialize(Context& context, const parameterized_verbatim_t<ValueType, Expr>& t)
|
||||
{
|
||||
context << t._verbatim_lhs;
|
||||
serialize(t._expr, context);
|
||||
serialize(context, t._expr);
|
||||
context << t._verbatim_rhs;
|
||||
return context;
|
||||
}
|
||||
|
@ -224,13 +224,13 @@ namespace sqlpp
|
||||
template <typename T>
|
||||
static _context_t& _serialize_interpretable(const T& t, _context_t& context)
|
||||
{
|
||||
return ::sqlpp::serialize(t, context);
|
||||
return ::sqlpp::serialize(context, t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static _context_t& _interpret_interpretable(const T& t, _context_t& context)
|
||||
{
|
||||
return ::sqlpp::serialize(t, context);
|
||||
return ::sqlpp::serialize(context, t);
|
||||
}
|
||||
|
||||
// Select stmt (returns a result)
|
||||
|
@ -85,7 +85,7 @@ namespace sqlpp
|
||||
postgresql::context_t& serialize(const postgresql::on_conflict_do_nothing_data_t<ConflictTarget>& o,
|
||||
postgresql::context_t& context)
|
||||
{
|
||||
serialize(o._column, context);
|
||||
serialize(context, o._column);
|
||||
context << "DO NOTHING";
|
||||
return context;
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ namespace sqlpp
|
||||
const postgresql::on_conflict_do_update_data_t<ConflictTarget, Assignments...>& o,
|
||||
postgresql::context_t& context)
|
||||
{
|
||||
serialize(o._conflict_target, context);
|
||||
serialize(context, o._conflict_target);
|
||||
context << "DO UPDATE SET ";
|
||||
interpret_tuple(o._assignments, ",", context);
|
||||
return context;
|
||||
@ -154,9 +154,9 @@ namespace sqlpp
|
||||
const postgresql::on_conflict_do_update_where_data_t<ConflictTarget, Expression, Assignments...>& o,
|
||||
postgresql::context_t& context)
|
||||
{
|
||||
serialize(o._assignments, context);
|
||||
serialize(context, o._assignments);
|
||||
context << " WHERE ";
|
||||
serialize(o._expression, context);
|
||||
serialize(context, o._expression);
|
||||
return context;
|
||||
}
|
||||
} // namespace postgresql
|
||||
|
@ -133,12 +133,12 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename JoinType, typename Lhs, typename Rhs>
|
||||
Context& serialize(const pre_join_t<JoinType, Lhs, Rhs>& t, Context& context)
|
||||
Context& serialize(Context& context, const pre_join_t<JoinType, Lhs, Rhs>& t)
|
||||
{
|
||||
serialize(t._lhs, context);
|
||||
serialize(context, t._lhs);
|
||||
context << JoinType::_name;
|
||||
context << " JOIN ";
|
||||
serialize(t._rhs, context);
|
||||
serialize(context, t._rhs);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const remove_name_t&, Context& context)
|
||||
Context& serialize(Context& context, const remove_name_t&)
|
||||
{
|
||||
context << "DELETE";
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const schema_t& t, Context& context)
|
||||
Context& serialize(Context& context, const schema_t& t)
|
||||
{
|
||||
context << t._name;
|
||||
return context;
|
||||
|
@ -62,11 +62,11 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Table>
|
||||
Context& serialize(const schema_qualified_table_t<Table>& t, Context& context)
|
||||
Context& serialize(Context& context, const schema_qualified_table_t<Table>& t)
|
||||
{
|
||||
serialize(t._schema, context);
|
||||
serialize(context, t._schema);
|
||||
context << '.';
|
||||
serialize(t._table, context);
|
||||
serialize(context, t._table);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const select_name_t&, Context& context)
|
||||
Context& serialize(Context& context, const select_name_t&)
|
||||
{
|
||||
context << "SELECT ";
|
||||
|
||||
|
@ -268,7 +268,7 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename... Columns>
|
||||
Context& serialize(const std::tuple<Columns...>& t, Context& context)
|
||||
Context& serialize(Context& context, const std::tuple<Columns...>& t)
|
||||
{
|
||||
interpret_tuple(t, ',', context);
|
||||
return context;
|
||||
|
@ -135,7 +135,7 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename... Flags>
|
||||
Context& serialize(const select_flag_list_data_t<Flags...>& t, Context& context)
|
||||
Context& serialize(Context& context, const select_flag_list_data_t<Flags...>& t)
|
||||
{
|
||||
interpret_tuple(t._flags, ' ', context);
|
||||
if (sizeof...(Flags) != 0u)
|
||||
|
@ -42,7 +42,7 @@ namespace sqlpp
|
||||
static constexpr all_t all = {};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const all_t&, Context& context)
|
||||
Context& serialize(Context& context, const all_t&)
|
||||
{
|
||||
context << "ALL";
|
||||
return context;
|
||||
@ -56,7 +56,7 @@ namespace sqlpp
|
||||
static constexpr distinct_t distinct = {};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const distinct_t&, Context& context)
|
||||
Context& serialize(Context& context, const distinct_t&)
|
||||
{
|
||||
context << "DISTINCT";
|
||||
return context;
|
||||
@ -70,7 +70,7 @@ namespace sqlpp
|
||||
static constexpr straight_join_t straight_join = {};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const straight_join_t&, Context& context)
|
||||
Context& serialize(Context& context, const straight_join_t&)
|
||||
{
|
||||
context << "STRAIGHT_JOIN";
|
||||
return context;
|
||||
|
@ -91,9 +91,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Select, typename... NamedExpr>
|
||||
Context& serialize(const select_pseudo_table_t<Select, NamedExpr...>& t, Context& context)
|
||||
Context& serialize(Context& context, const select_pseudo_table_t<Select, NamedExpr...>& t)
|
||||
{
|
||||
serialize(t._select, context);
|
||||
serialize(context, t._select);
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -30,105 +30,85 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename T, typename Context>
|
||||
auto serialize_operand(const T& t, Context& context) -> Context&
|
||||
{
|
||||
if (requires_parens_t<T>::value)
|
||||
{
|
||||
context << '(';
|
||||
serialize(t, context);
|
||||
context << ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
serialize(t, context);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
#warning: We should switch context and arg to allow for this to have fewer error messages
|
||||
/*
|
||||
template <typename Context, typename X = void>
|
||||
auto serialize(Context& context, ...) -> Context&
|
||||
{
|
||||
static_assert(wrong_t<X>::value, "Missing specialization");
|
||||
return context;
|
||||
}
|
||||
*/
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const bool& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const bool& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const int8_t& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const int8_t& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const int16_t& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const int16_t& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const int32_t& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const int32_t& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const int64_t& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const int64_t& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const uint8_t& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const uint8_t& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const uint16_t& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const uint16_t& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const uint32_t& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const uint32_t& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const uint64_t& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const uint64_t& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const float& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const float& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const double& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const double& t) -> Context&
|
||||
{
|
||||
#warning: Analyze precision. There was a bug about this...
|
||||
context << t;
|
||||
@ -136,35 +116,35 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const char& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const char& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const char* t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const char* t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const std::string& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const std::string& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto serialize(const sqlpp::compat::string_view& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const sqlpp::compat::string_view& t) -> Context&
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const std::vector<uint8_t>& t, Context& context)
|
||||
Context& serialize(Context& context, const std::vector<uint8_t>& t)
|
||||
{
|
||||
constexpr char hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
context << "x'";
|
||||
@ -178,7 +158,7 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const ::sqlpp::chrono::day_point& t, Context& context)
|
||||
Context& serialize(Context& context, const ::sqlpp::chrono::day_point& t)
|
||||
{
|
||||
const auto ymd = ::date::year_month_day{t};
|
||||
context << "DATE '" << ymd << "'";
|
||||
@ -186,14 +166,14 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const std::chrono::microseconds& t, Context& context)
|
||||
Context& serialize(Context& context, const std::chrono::microseconds& t)
|
||||
{
|
||||
context << '\'' << ::date::make_time(t) << '\'';
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Period, typename Context>
|
||||
Context& serialize(const std::chrono::time_point<std::chrono::system_clock, Period>& t, Context& context)
|
||||
Context& serialize(Context& context, const std::chrono::time_point<std::chrono::system_clock, Period>& t)
|
||||
{
|
||||
const auto dp = ::sqlpp::chrono::floor<::date::days>(t);
|
||||
const auto time = ::date::make_time(t - dp);
|
||||
@ -203,7 +183,7 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename T, typename Context>
|
||||
auto serialize(const sqlpp::compat::optional<T>& t, Context& context) -> Context&
|
||||
auto serialize(Context& context, const sqlpp::compat::optional<T>& t) -> Context&
|
||||
{
|
||||
if (not t.has_value())
|
||||
{
|
||||
@ -211,9 +191,26 @@ namespace sqlpp
|
||||
}
|
||||
else
|
||||
{
|
||||
serialize(*t, context);
|
||||
serialize(context, *t);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename T, typename Context>
|
||||
auto serialize_operand(Context& context, const T& t) -> Context&
|
||||
{
|
||||
if (requires_parens_t<T>::value)
|
||||
{
|
||||
context << '(';
|
||||
serialize(context, t);
|
||||
context << ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
serialize(context, t);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
} // namespace sqlpp
|
||||
|
@ -47,7 +47,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Column>
|
||||
Context& serialize(const simple_column_t<Column>&, Context& context)
|
||||
Context& serialize(Context& context, const simple_column_t<Column>&)
|
||||
{
|
||||
context << name_of<typename simple_column_t<Column>::_column_t>::template char_ptr<Context>();
|
||||
return context;
|
||||
|
@ -138,9 +138,9 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Table>
|
||||
Context& serialize(const single_table_data_t<Table>& t, Context& context)
|
||||
Context& serialize(Context& context, const single_table_data_t<Table>& t)
|
||||
{
|
||||
serialize(t._table, context);
|
||||
serialize(context, t._table);
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -49,9 +49,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Expression>
|
||||
Context& serialize(const sort_order_t<Expression>& t, Context& context)
|
||||
Context& serialize(Context& context, const sort_order_t<Expression>& t)
|
||||
{
|
||||
serialize_operand(t._expression, context);
|
||||
serialize_operand(context, t._expression);
|
||||
switch (t._sort_type)
|
||||
{
|
||||
case sort_type::asc:
|
||||
|
@ -249,13 +249,13 @@ namespace sqlpp
|
||||
template <typename T>
|
||||
static _context_t& _serialize_interpretable(const T& t, _context_t& context)
|
||||
{
|
||||
return ::sqlpp::serialize(t, context);
|
||||
return ::sqlpp::serialize(context, t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static _context_t& _interpret_interpretable(const T& t, _context_t& context)
|
||||
{
|
||||
return ::sqlpp::serialize(t, context);
|
||||
return ::sqlpp::serialize(context, t);
|
||||
}
|
||||
|
||||
//! select returns a result (which can be iterated row by row)
|
||||
@ -263,7 +263,7 @@ namespace sqlpp
|
||||
bind_result_t select(const Select& s)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(s, context);
|
||||
serialize(context, s);
|
||||
return select_impl(context.str());
|
||||
}
|
||||
|
||||
@ -271,7 +271,7 @@ namespace sqlpp
|
||||
_prepared_statement_t prepare_select(Select& s)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(s, context);
|
||||
serialize(context, s);
|
||||
return prepare_impl(context.str());
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ namespace sqlpp
|
||||
size_t insert(const Insert& i)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(i, context);
|
||||
serialize(context, i);
|
||||
return insert_impl(context.str());
|
||||
}
|
||||
|
||||
@ -296,7 +296,7 @@ namespace sqlpp
|
||||
_prepared_statement_t prepare_insert(Insert& i)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(i, context);
|
||||
serialize(context, i);
|
||||
return prepare_impl(context.str());
|
||||
}
|
||||
|
||||
@ -313,7 +313,7 @@ namespace sqlpp
|
||||
size_t update(const Update& u)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(u, context);
|
||||
serialize(context, u);
|
||||
return update_impl(context.str());
|
||||
}
|
||||
|
||||
@ -321,7 +321,7 @@ namespace sqlpp
|
||||
_prepared_statement_t prepare_update(Update& u)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(u, context);
|
||||
serialize(context, u);
|
||||
return prepare_impl(context.str());
|
||||
}
|
||||
|
||||
@ -338,7 +338,7 @@ namespace sqlpp
|
||||
size_t remove(const Remove& r)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(r, context);
|
||||
serialize(context, r);
|
||||
return remove_impl(context.str());
|
||||
}
|
||||
|
||||
@ -346,7 +346,7 @@ namespace sqlpp
|
||||
_prepared_statement_t prepare_remove(Remove& r)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(r, context);
|
||||
serialize(context, r);
|
||||
return prepare_impl(context.str());
|
||||
}
|
||||
|
||||
@ -373,7 +373,7 @@ namespace sqlpp
|
||||
size_t execute(const Execute& x)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(x, context);
|
||||
serialize(context, x);
|
||||
return execute(context.str());
|
||||
}
|
||||
|
||||
@ -381,7 +381,7 @@ namespace sqlpp
|
||||
_prepared_statement_t prepare_execute(Execute& x)
|
||||
{
|
||||
_context_t context{*this};
|
||||
serialize(x, context);
|
||||
serialize(context, x);
|
||||
return prepare_impl(context.str());
|
||||
}
|
||||
|
||||
|
@ -268,12 +268,12 @@ namespace sqlpp
|
||||
struct value_type_of<statement_t<Policies...>> : value_type_of<typename detail::statement_policies_t<Policies...>> {};
|
||||
|
||||
template <typename Context, typename... Policies>
|
||||
Context& serialize(const statement_t<Policies...>& t, Context& context)
|
||||
Context& serialize(Context& context, const statement_t<Policies...>& t)
|
||||
{
|
||||
using P = detail::statement_policies_t<Policies...>;
|
||||
|
||||
using swallow = int[];
|
||||
(void)swallow{0, (serialize(static_cast<const typename Policies::template _base_t<P>&>(t)._data, context), 0)...};
|
||||
(void)swallow{0, (serialize(context, static_cast<const typename Policies::template _base_t<P>&>(t)._data), 0)...};
|
||||
|
||||
return context;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Table, typename... ColumnSpec>
|
||||
Context& serialize(const table_t<Table, ColumnSpec...>& /*unused*/, Context& context)
|
||||
Context& serialize(Context& context, const table_t<Table, ColumnSpec...>& /*unused*/)
|
||||
{
|
||||
context << name_of<Table>::template char_ptr<Context>();
|
||||
return context;
|
||||
|
@ -99,13 +99,13 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename AliasProvider, typename Table, typename... ColumnSpec>
|
||||
Context& serialize(const table_alias_t<AliasProvider, Table, ColumnSpec...>& t, Context& context)
|
||||
Context& serialize(Context& context, const table_alias_t<AliasProvider, Table, ColumnSpec...>& t)
|
||||
{
|
||||
if (requires_parens_t<Table>::value)
|
||||
{
|
||||
context << "(";
|
||||
}
|
||||
serialize(t._table, context);
|
||||
serialize(context, t._table);
|
||||
if (requires_parens_t<Table>::value)
|
||||
{
|
||||
context << ")";
|
||||
|
@ -53,10 +53,10 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Expr>
|
||||
Context& serialize(const trim_t<Expr>& t, Context& context)
|
||||
Context& serialize(Context& context, const trim_t<Expr>& t)
|
||||
{
|
||||
context << "TRIM(";
|
||||
serialize_operand(t._expr, context);
|
||||
serialize_operand(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
@ -47,13 +47,13 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Flag, typename Lhs, typename Rhs>
|
||||
Context& serialize(const union_data_t<Flag, Lhs, Rhs>& t, Context& context)
|
||||
Context& serialize(Context& context, const union_data_t<Flag, Lhs, Rhs>& t)
|
||||
{
|
||||
serialize(t._lhs, context);
|
||||
serialize(context, t._lhs);
|
||||
context << " UNION ";
|
||||
serialize(Flag{}, context);
|
||||
serialize(context, Flag{});
|
||||
context << " ";
|
||||
serialize(t._rhs, context);
|
||||
serialize(context, t._rhs);
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -41,7 +41,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const union_all_t&, Context& context)
|
||||
Context& serialize(Context& context, const union_all_t&)
|
||||
{
|
||||
context << "ALL";
|
||||
return context;
|
||||
@ -54,7 +54,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const union_distinct_t&, Context& context)
|
||||
Context& serialize(Context& context, const union_distinct_t&)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const update_name_t&, Context& context)
|
||||
Context& serialize(Context& context, const update_name_t&)
|
||||
{
|
||||
context << "UPDATE ";
|
||||
return context;
|
||||
|
@ -165,7 +165,7 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename... Assignments>
|
||||
Context& serialize(const update_list_data_t<Assignments...>& t, Context& context)
|
||||
Context& serialize(Context& context, const update_list_data_t<Assignments...>& t)
|
||||
{
|
||||
context << " SET ";
|
||||
interpret_tuple(t._assignments, ",", context);
|
||||
|
@ -52,10 +52,10 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Expr>
|
||||
Context& serialize(const upper_t<Expr>& t, Context& context)
|
||||
Context& serialize(Context& context, const upper_t<Expr>& t)
|
||||
{
|
||||
context << "UPPER(";
|
||||
serialize_operand(t._expr, context);
|
||||
serialize_operand(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename... Tables>
|
||||
Context& serialize(const using_data_t<Tables...>& t, Context& context)
|
||||
Context& serialize(Context& context, const using_data_t<Tables...>& t)
|
||||
{
|
||||
context << " USING ";
|
||||
interpret_tuple(t._tables, ',', context);
|
||||
|
@ -54,10 +54,10 @@ namespace sqlpp
|
||||
using check_value_arg = std::enable_if_t<not std::is_same<value_type_of_t<T>, no_value_t>::value and values_are_comparable<T, T>::value>;
|
||||
|
||||
template <typename Context, typename T>
|
||||
Context& serialize(const value_t<T>& t, Context& context)
|
||||
Context& serialize(Context& context, const value_t<T>& t)
|
||||
{
|
||||
#warning: Untested
|
||||
serialize(t._value, context);
|
||||
serialize(context, t._value);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename ValueType>
|
||||
Context& serialize(const verbatim_t<ValueType>& t, Context& context)
|
||||
Context& serialize(Context& context, const verbatim_t<ValueType>& t)
|
||||
{
|
||||
context << t._verbatim;
|
||||
return context;
|
||||
|
@ -75,7 +75,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const verbatim_table_t& t, Context& context)
|
||||
Context& serialize(Context& context, const verbatim_table_t& t)
|
||||
{
|
||||
context << t._representation;
|
||||
return context;
|
||||
|
@ -199,15 +199,15 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Expression>
|
||||
Context& serialize(const where_data_t<Expression>& t, Context& context)
|
||||
Context& serialize(Context& context, const where_data_t<Expression>& t)
|
||||
{
|
||||
context << " WHERE ";
|
||||
serialize(t._expression, context);
|
||||
serialize(context, t._expression);
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(const where_data_t<unconditional_t>&, Context& context)
|
||||
Context& serialize(Context& context, const where_data_t<unconditional_t>&)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename... Expressions>
|
||||
Context& serialize(const with_data_t<Expressions...>& t, Context& context)
|
||||
Context& serialize(Context& context, const with_data_t<Expressions...>& t)
|
||||
{
|
||||
using T = with_data_t<Expressions...>;
|
||||
// FIXME: If there is a recursive CTE, add a "RECURSIVE" here
|
||||
|
@ -43,9 +43,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Expression>
|
||||
Context& serialize(const without_table_check_t<Expression>& t, Context& context)
|
||||
Context& serialize(Context& context, const without_table_check_t<Expression>& t)
|
||||
{
|
||||
serialize(t.expr(), context);
|
||||
serialize(context, t.expr());
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -24,36 +24,36 @@
|
||||
|
||||
set(test_files
|
||||
logical_expression.cpp
|
||||
Any.cpp
|
||||
As.cpp
|
||||
Avg.cpp
|
||||
Blob.cpp
|
||||
Count.cpp
|
||||
CustomQuery.cpp
|
||||
DynamicWhere.cpp
|
||||
Exists.cpp
|
||||
Float.cpp
|
||||
ForUpdate.cpp
|
||||
From.cpp
|
||||
In.cpp
|
||||
Insert.cpp
|
||||
IsNotNull.cpp
|
||||
IsNull.cpp
|
||||
Lower.cpp
|
||||
Max.cpp
|
||||
Min.cpp
|
||||
Operator.cpp
|
||||
Over.cpp
|
||||
SelectAs.cpp
|
||||
SelectColumns.cpp
|
||||
SelectFlags.cpp
|
||||
Some.cpp
|
||||
Sum.cpp
|
||||
TableAlias.cpp
|
||||
Trim.cpp
|
||||
Upper.cpp
|
||||
Where.cpp
|
||||
ParameterizedVerbatim.cpp
|
||||
#Any.cpp
|
||||
#As.cpp
|
||||
#Avg.cpp
|
||||
#Blob.cpp
|
||||
#Count.cpp
|
||||
#CustomQuery.cpp
|
||||
#DynamicWhere.cpp
|
||||
#Exists.cpp
|
||||
#Float.cpp
|
||||
#ForUpdate.cpp
|
||||
#From.cpp
|
||||
#In.cpp
|
||||
#Insert.cpp
|
||||
#IsNotNull.cpp
|
||||
#IsNull.cpp
|
||||
#Lower.cpp
|
||||
#Max.cpp
|
||||
#Min.cpp
|
||||
#Operator.cpp
|
||||
#Over.cpp
|
||||
#SelectAs.cpp
|
||||
#SelectColumns.cpp
|
||||
#SelectFlags.cpp
|
||||
#Some.cpp
|
||||
#Sum.cpp
|
||||
#TableAlias.cpp
|
||||
#Trim.cpp
|
||||
#Upper.cpp
|
||||
#Where.cpp
|
||||
#ParameterizedVerbatim.cpp
|
||||
)
|
||||
|
||||
create_test_sourcelist(test_sources test_serializer_main.cpp ${test_files})
|
||||
|
@ -46,7 +46,7 @@ namespace
|
||||
{
|
||||
MockDb::_serializer_context_t printer = {};
|
||||
|
||||
const auto result = serialize(expr, printer).str();
|
||||
const auto result = serialize(printer, expr).str();
|
||||
|
||||
assert_equal(lineNo, result, expected);
|
||||
}
|
||||
|
64
tests/core/serialize/logical_expression.cpp
Normal file
64
tests/core/serialize/logical_expression.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021, Roland Bock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "Sample.h"
|
||||
#include "compare.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int logical_expression(int, char* [])
|
||||
{
|
||||
const auto foo = test::TabFoo{};
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
/*
|
||||
// Plus
|
||||
compare(__LINE__, bar.id + 3u, "(tab_bar.id+3)");
|
||||
compare(__LINE__, sqlpp::value(3) + foo.uIntN, "(3+tab_foo.u_int_n)");
|
||||
|
||||
// Shift left
|
||||
compare(__LINE__, sqlpp::value(3) << foo.uIntN, "(3<<tab_foo.u_int_n)");
|
||||
compare(__LINE__, bar.id << 3u, "(tab_bar.id<<3)");
|
||||
|
||||
// Shift right
|
||||
compare(__LINE__, sqlpp::value(3) >> foo.uIntN, "(3>>tab_foo.u_int_n)");
|
||||
compare(__LINE__, bar.id >> 3u, "(tab_bar.id>>3)");
|
||||
|
||||
// Comparison
|
||||
compare(__LINE__, bar.id < 3u, "(tab_bar.id<3)");
|
||||
compare(__LINE__, bar.id <= 3u, "(tab_bar.id<=3)");
|
||||
compare(__LINE__, bar.id == 3u, "(tab_bar.id=3)");
|
||||
compare(__LINE__, bar.id != 3u, "(tab_bar.id<>3)");
|
||||
compare(__LINE__, bar.id >= 3u, "(tab_bar.id>=3)");
|
||||
compare(__LINE__, bar.id > 3u, "(tab_bar.id>3)");
|
||||
*/
|
||||
|
||||
#warning: Consider reducing braces a bit as in sqlpp17
|
||||
compare(__LINE__, true and dynamic(true, bar.boolNn), "(1 AND tab_bar.bool_nn)");
|
||||
compare(__LINE__, true and dynamic(false, bar.boolNn), "1");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user