mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Next step in replacing serializer_t
This commit is contained in:
parent
61116f89c5
commit
2cab1fa681
@ -57,19 +57,13 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Expression, typename AliasProvider>
|
||||
struct serializer_t<Context, expression_alias_t<Expression, AliasProvider>>
|
||||
Context& serialize(const expression_alias_t<Expression, AliasProvider>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Expression>;
|
||||
using T = expression_alias_t<Expression, AliasProvider>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
serialize_operand(t._expression, context);
|
||||
context << " AS ";
|
||||
context << name_of<T>::template char_ptr<Context>();
|
||||
return context;
|
||||
}
|
||||
};
|
||||
serialize_operand(t._expression, context);
|
||||
context << " AS ";
|
||||
context << name_of<expression_alias_t<Expression, AliasProvider>>::template char_ptr<Context>();
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
@ -109,32 +109,15 @@ namespace sqlpp
|
||||
}
|
||||
};
|
||||
|
||||
// workaround for msvs bug https://connect.microsoft.com/VisualStudio/feedback/details/2173053
|
||||
// template <typename Context, typename... Args>
|
||||
// struct serializer_t<Context, column_t<Args...>>
|
||||
// {
|
||||
// using _serialize_check = consistent_t;
|
||||
// using T = column_t<Args...>;
|
||||
//
|
||||
// static Context& _(const T&, Context& context)
|
||||
// {
|
||||
// context << name_of<typename T::_table>::char_ptr() << '.' << name_of<T>::char_ptr();
|
||||
// return context;
|
||||
// }
|
||||
// };
|
||||
template <typename Context, typename Args1, typename Args2>
|
||||
struct serializer_t<Context, column_t<Args1, Args2>>
|
||||
template <typename Context, typename Table, typename ColumnSpec>
|
||||
Context& serialize(const column_t<Table, ColumnSpec>&, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = column_t<Args1, Args2>;
|
||||
using T = column_t<Table, ColumnSpec>;
|
||||
|
||||
static Context& _(const T& /*unused*/, Context& context)
|
||||
{
|
||||
context << name_of<typename T::_table>::template char_ptr<Context>() << '.'
|
||||
<< name_of<T>::template char_ptr<Context>();
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << name_of<typename T::_table>::template char_ptr<Context>() << '.'
|
||||
<< name_of<T>::template char_ptr<Context>();
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
@ -67,23 +67,17 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, blob_operand>
|
||||
Context& serialize(const blob_operand& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = blob_operand;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
constexpr char hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
context << "x'";
|
||||
for (const auto c : t._t)
|
||||
{
|
||||
constexpr char hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
context << "x'";
|
||||
for (const auto c : t._t)
|
||||
{
|
||||
context << hexChars[c >> 4] << hexChars[c & 0x0F];
|
||||
}
|
||||
context << '\'';
|
||||
|
||||
return context;
|
||||
context << hexChars[c >> 4] << hexChars[c & 0x0F];
|
||||
}
|
||||
};
|
||||
context << '\'';
|
||||
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
#endif
|
||||
|
@ -63,17 +63,11 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, boolean_operand>
|
||||
Context& serialize(const boolean_operand& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = boolean_operand;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
{
|
||||
context << t._t;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << t._t;
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
@ -61,17 +61,11 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, day_point_operand>
|
||||
Context& serialize(const day_point_operand& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = day_point_operand;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
{
|
||||
const auto ymd = ::date::year_month_day{t._t};
|
||||
context << "DATE '" << ymd << "'";
|
||||
return context;
|
||||
}
|
||||
};
|
||||
const auto ymd = ::date::year_month_day{t._t};
|
||||
context << "DATE '" << ymd << "'";
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
#endif
|
||||
|
@ -59,16 +59,10 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, floating_point_operand>
|
||||
Context& serialize(const floating_point_operand& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = floating_point_operand;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
{
|
||||
context << t._t;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << t._t;
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
#endif
|
||||
|
@ -61,17 +61,11 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, integral_operand>
|
||||
Context& serialize(const integral_operand& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = integral_operand;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
{
|
||||
context << t._t;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << t._t;
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
@ -75,19 +75,13 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename... Args>
|
||||
struct serializer_t<Context, concat_t<Args...>>
|
||||
Context& serialize(const concat_t<Args...>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Args...>;
|
||||
using T = concat_t<Args...>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
context << "(";
|
||||
interpret_tuple(t._args, "||", context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << "(";
|
||||
interpret_tuple(t._args, "||", context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
auto concat(Args... args) -> concat_t<Args...>
|
||||
|
@ -79,20 +79,14 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Operand, typename Pattern>
|
||||
struct serializer_t<Context, like_t<Operand, Pattern>>
|
||||
Context& serialize(const like_t<Operand, Pattern>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Operand, Pattern>;
|
||||
using T = like_t<Operand, Pattern>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
serialize_operand(t._operand, context);
|
||||
context << " LIKE(";
|
||||
serialize(t._pattern, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
};
|
||||
serialize_operand(t._operand, context);
|
||||
context << " LIKE(";
|
||||
serialize(t._pattern, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
@ -74,16 +74,10 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, text_operand>
|
||||
Context& serialize(const text_operand& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = text_operand;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
{
|
||||
context << '\'' << context.escape(t._t) << '\'';
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << '\'' << context.escape(t._t) << '\'';
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
#endif
|
||||
|
@ -63,16 +63,10 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Period>
|
||||
struct serializer_t<Context, time_of_day_operand<Period>>
|
||||
Context& serialize(const time_of_day_operand<Period>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = time_of_day_operand<Period>;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
{
|
||||
context << '\'' << ::date::make_time(t._t) << '\'';
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << '\'' << ::date::make_time(t._t) << '\'';
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
#endif
|
||||
|
@ -63,19 +63,13 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Period>
|
||||
struct serializer_t<Context, time_point_operand<Period>>
|
||||
Context& serialize(const time_point_operand<Period>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = time_point_operand<Period>;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
{
|
||||
const auto dp = ::sqlpp::chrono::floor<::date::days>(t._t);
|
||||
const auto time = ::date::make_time(t._t - dp);
|
||||
const auto ymd = ::date::year_month_day{dp};
|
||||
context << "TIMESTAMP '" << ymd << ' ' << time << "'";
|
||||
return context;
|
||||
}
|
||||
};
|
||||
const auto dp = ::sqlpp::chrono::floor<::date::days>(t._t);
|
||||
const auto time = ::date::make_time(t._t - dp);
|
||||
const auto ymd = ::date::year_month_day{dp};
|
||||
context << "TIMESTAMP '" << ymd << ' ' << time << "'";
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
#endif
|
||||
|
@ -61,17 +61,11 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, unsigned_integral_operand>
|
||||
Context& serialize(const unsigned_integral_operand& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = unsigned_integral_operand;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
{
|
||||
context << t._t;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << t._t;
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
@ -77,39 +77,29 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Db>
|
||||
struct serializer_t<Context, dynamic_select_column_list<Db>>
|
||||
Context& serialize(const dynamic_select_column_list<Db>& t, Context& context)
|
||||
{
|
||||
using T = dynamic_select_column_list<Db>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
bool first = true;
|
||||
for (const auto column : t._dynamic_columns)
|
||||
{
|
||||
bool first = true;
|
||||
for (const auto column : t._dynamic_columns)
|
||||
if (first)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
context << ',';
|
||||
}
|
||||
serialize(column, context);
|
||||
first = false;
|
||||
}
|
||||
return context;
|
||||
else
|
||||
{
|
||||
context << ',';
|
||||
}
|
||||
serialize(column, context);
|
||||
}
|
||||
};
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, dynamic_select_column_list<void>>
|
||||
Context& serialize(const dynamic_select_column_list<void>&, Context& context)
|
||||
{
|
||||
using T = dynamic_select_column_list<void>;
|
||||
|
||||
static Context& _(const T& /*unused*/, Context& context)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
};
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
@ -78,19 +78,13 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Select>
|
||||
struct serializer_t<Context, exists_t<Select>>
|
||||
Context& serialize(const exists_t<Select>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Select>;
|
||||
using T = exists_t<Select>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
context << "EXISTS(";
|
||||
serialize(t._select, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << "EXISTS(";
|
||||
serialize(t._select, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto exists(T t) -> exists_t<wrap_operand_t<T>>
|
||||
|
@ -61,21 +61,15 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Lhs, typename Rhs>
|
||||
struct serializer_t<Context, binary_expression_t<Lhs, op::equal_to, Rhs>>
|
||||
Context& serialize(const binary_expression_t<Lhs, op::equal_to, Rhs>& t, Context& context)
|
||||
{
|
||||
using T = binary_expression_t<Lhs, op::equal_to, Rhs>;
|
||||
using _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
context << "(";
|
||||
serialize_operand(t._lhs, context);
|
||||
context << "=";
|
||||
serialize_operand(t._rhs, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << "(";
|
||||
serialize_operand(t._lhs, context);
|
||||
context << "=";
|
||||
serialize_operand(t._rhs, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Lhs, typename Rhs>
|
||||
struct binary_expression_t<Lhs, op::not_equal_to, Rhs>
|
||||
@ -102,21 +96,15 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Lhs, typename Rhs>
|
||||
struct serializer_t<Context, binary_expression_t<Lhs, op::not_equal_to, Rhs>>
|
||||
Context& serialize(const binary_expression_t<Lhs, op::not_equal_to, Rhs>& t, Context& context)
|
||||
{
|
||||
using T = binary_expression_t<Lhs, op::not_equal_to, Rhs>;
|
||||
using _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
context << "(";
|
||||
serialize_operand(t._lhs, context);
|
||||
context << "<>";
|
||||
serialize_operand(t._rhs, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << "(";
|
||||
serialize_operand(t._lhs, context);
|
||||
context << "<>";
|
||||
serialize_operand(t._rhs, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Rhs>
|
||||
struct unary_expression_t<op::logical_not, Rhs>
|
||||
@ -140,21 +128,15 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Rhs>
|
||||
struct serializer_t<Context, unary_expression_t<op::logical_not, Rhs>>
|
||||
Context& serialize(const unary_expression_t<op::logical_not, Rhs>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Rhs>;
|
||||
using T = unary_expression_t<op::logical_not, Rhs>;
|
||||
context << "(";
|
||||
context << "NOT ";
|
||||
serialize_operand(t._rhs, context);
|
||||
context << ")";
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
context << "(";
|
||||
context << "NOT ";
|
||||
serialize_operand(t._rhs, context);
|
||||
context << ")";
|
||||
|
||||
return context;
|
||||
}
|
||||
};
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Lhs, typename O, typename Rhs>
|
||||
struct binary_expression_t : public expression_operators<binary_expression_t<Lhs, O, Rhs>, value_type_of<O>>,
|
||||
@ -178,21 +160,15 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Lhs, typename O, typename Rhs>
|
||||
struct serializer_t<Context, binary_expression_t<Lhs, O, Rhs>>
|
||||
Context& serialize(const binary_expression_t<Lhs, O, Rhs>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
|
||||
using T = binary_expression_t<Lhs, O, Rhs>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
context << "(";
|
||||
serialize_operand(t._lhs, context);
|
||||
context << O::_name;
|
||||
serialize_operand(t._rhs, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << "(";
|
||||
serialize_operand(t._lhs, context);
|
||||
context << O::_name;
|
||||
serialize_operand(t._rhs, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename O, typename Rhs>
|
||||
struct unary_expression_t : public expression_operators<unary_expression_t<O, Rhs>, value_type_of<O>>,
|
||||
@ -215,20 +191,14 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename O, typename Rhs>
|
||||
struct serializer_t<Context, unary_expression_t<O, Rhs>>
|
||||
Context& serialize(const unary_expression_t<O, Rhs>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Rhs>;
|
||||
using T = unary_expression_t<O, Rhs>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
context << "(";
|
||||
context << O::_name;
|
||||
serialize_operand(t._rhs, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << "(";
|
||||
context << O::_name;
|
||||
serialize_operand(t._rhs, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
@ -252,27 +252,21 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Database, typename... Expressions>
|
||||
struct serializer_t<Context, group_by_data_t<Database, Expressions...>>
|
||||
Context& serialize(const group_by_data_t<Database, Expressions...>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Expressions...>;
|
||||
using T = group_by_data_t<Database, Expressions...>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
|
||||
{
|
||||
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
|
||||
{
|
||||
return context;
|
||||
}
|
||||
context << " GROUP BY ";
|
||||
interpret_tuple(t._expressions, ',', context);
|
||||
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
|
||||
{
|
||||
context << ',';
|
||||
}
|
||||
interpret_list(t._dynamic_expressions, ',', context);
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << " GROUP 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>
|
||||
auto group_by(T&&... t) -> decltype(statement_t<void, no_group_by_t>().group_by(std::forward<T>(t)...))
|
||||
|
@ -49,9 +49,9 @@ namespace sqlpp
|
||||
named_interpretable_t& operator=(named_interpretable_t&&) = default;
|
||||
~named_interpretable_t() = default;
|
||||
|
||||
_serializer_context_t& serialize(_serializer_context_t& context) const
|
||||
_serializer_context_t& interpret(_serializer_context_t& context) const
|
||||
{
|
||||
return _impl->serialize(context);
|
||||
return _impl->interpret(context);
|
||||
}
|
||||
|
||||
std::string _get_name() const
|
||||
@ -65,7 +65,7 @@ namespace sqlpp
|
||||
struct _impl_base
|
||||
{
|
||||
virtual ~_impl_base() = default;
|
||||
virtual _serializer_context_t& serialize(_serializer_context_t& context) const = 0;
|
||||
virtual _serializer_context_t& interpret(_serializer_context_t& context) const = 0;
|
||||
virtual std::string _get_name() const = 0;
|
||||
};
|
||||
|
||||
@ -77,9 +77,9 @@ namespace sqlpp
|
||||
{
|
||||
}
|
||||
|
||||
_serializer_context_t& serialize(_serializer_context_t& context) const
|
||||
_serializer_context_t& interpret(_serializer_context_t& context) const
|
||||
{
|
||||
::sqlpp::serialize(_t, context);
|
||||
interpret(_t, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -95,27 +95,21 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Database>
|
||||
struct serializer_t<Context, named_interpretable_t<Database>>
|
||||
Context& serialize(const named_interpretable_t<Database>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = named_interpretable_t<Database>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
if (t._requires_braces)
|
||||
{
|
||||
if (t._requires_braces)
|
||||
{
|
||||
context << '(';
|
||||
t.serialize(context);
|
||||
context << ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
t.serialize(context);
|
||||
}
|
||||
|
||||
return context;
|
||||
context << '(';
|
||||
t.interpret(context);
|
||||
context << ')';
|
||||
}
|
||||
};
|
||||
else
|
||||
{
|
||||
t.interpret(context);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
@ -37,15 +37,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, no_data_t>
|
||||
Context& serialize(const no_data_t&, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = no_data_t;
|
||||
|
||||
static Context& _(const T& /*unused*/, Context& context)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
};
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
#endif
|
||||
|
@ -82,16 +82,10 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, noop>
|
||||
Context& serialize(const noop&, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = noop;
|
||||
|
||||
static Context& _(const T& /*unused*/, Context& context)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
};
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct is_noop : std::is_same<T, noop>
|
||||
|
@ -73,67 +73,49 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Operand, typename... Args>
|
||||
struct serializer_t<Context, not_in_t<Operand, Args...>>
|
||||
Context& serialize(const not_in_t<Operand, Args...>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Args...>;
|
||||
using T = not_in_t<Operand, Args...>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
serialize_operand(t._operand, context);
|
||||
context << " NOT IN(";
|
||||
if (sizeof...(Args) == 1)
|
||||
{
|
||||
serialize_operand(t._operand, context);
|
||||
context << " NOT IN(";
|
||||
if (sizeof...(Args) == 1)
|
||||
{
|
||||
serialize(std::get<0>(t._args), context);
|
||||
}
|
||||
else
|
||||
{
|
||||
interpret_tuple(t._args, ',', context);
|
||||
}
|
||||
context << ')';
|
||||
return context;
|
||||
serialize(std::get<0>(t._args), context);
|
||||
}
|
||||
};
|
||||
else
|
||||
{
|
||||
interpret_tuple(t._args, ',', context);
|
||||
}
|
||||
context << ')';
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context, typename Operand>
|
||||
struct serializer_t<Context, not_in_t<Operand>>
|
||||
Context& serialize(const not_in_t<Operand>&, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = not_in_t<Operand>;
|
||||
|
||||
static Context& _(const T& /*unused*/, Context& context)
|
||||
{
|
||||
serialize(boolean_operand{true}, context);
|
||||
return context;
|
||||
}
|
||||
};
|
||||
serialize(boolean_operand{true}, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
struct value_list_t;
|
||||
|
||||
template <typename Context, typename Operand, typename Container>
|
||||
struct serializer_t<Context, not_in_t<Operand, value_list_t<Container>>>
|
||||
Context& serialize(const not_in_t<Operand, value_list_t<Container>>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, value_list_t<Container>>;
|
||||
using T = not_in_t<Operand, value_list_t<Container>>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
const auto& value_list = std::get<0>(t._args);
|
||||
if (value_list._container.empty())
|
||||
{
|
||||
const auto& value_list = std::get<0>(t._args);
|
||||
if (value_list._container.empty())
|
||||
{
|
||||
serialize(boolean_operand{true}, context);
|
||||
}
|
||||
else
|
||||
{
|
||||
serialize(t._operand, context);
|
||||
context << " NOT IN(";
|
||||
serialize(value_list, context);
|
||||
context << ')';
|
||||
}
|
||||
return context;
|
||||
serialize(boolean_operand{true}, context);
|
||||
}
|
||||
};
|
||||
else
|
||||
{
|
||||
serialize(t._operand, context);
|
||||
context << " NOT IN(";
|
||||
serialize(value_list, context);
|
||||
context << ')';
|
||||
}
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
@ -57,18 +57,12 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, select_name_t>
|
||||
Context& serialize(const select_name_t&, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = select_name_t;
|
||||
context << "SELECT ";
|
||||
|
||||
static Context& _(const T& /*unused*/, Context& context)
|
||||
{
|
||||
context << "SELECT ";
|
||||
|
||||
return context;
|
||||
}
|
||||
};
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Database>
|
||||
using blank_select_t = statement_t<Database,
|
||||
|
@ -134,11 +134,8 @@ namespace sqlpp
|
||||
using column_names = detail::make_type_set_t<typename Columns::_alias_t...>;
|
||||
static_assert(not column_names::template count<typename named_expression::_alias_t>(),
|
||||
"a column of this name is present in the select already");
|
||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, named_expression>;
|
||||
_serialize_check{};
|
||||
|
||||
using ok =
|
||||
logic::all_t<_is_dynamic::value, is_selectable_t<named_expression>::value, _serialize_check::type::value>;
|
||||
logic::all_t<_is_dynamic::value, is_selectable_t<named_expression>::value>;
|
||||
|
||||
_add_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert
|
||||
}
|
||||
|
@ -32,12 +32,6 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename T, typename Context>
|
||||
auto serialize(const T& t, Context& context) -> Context&
|
||||
{
|
||||
return serializer_t<Context, T>::_(t, context);
|
||||
}
|
||||
|
||||
template <typename T, typename Context>
|
||||
auto serialize_operand(const T& t, Context& context) -> Context&
|
||||
{
|
||||
|
@ -443,7 +443,7 @@ namespace sqlpp
|
||||
typename std::enable_if<is_statement_t<T>::value or is_prepared_statement_t<T>::value>::type>
|
||||
{
|
||||
using type =
|
||||
detail::get_first_if<is_inconsistent_t, consistent_t, typename T::_run_check, serialize_check_t<Context, T>>;
|
||||
detail::get_first_if<is_inconsistent_t, consistent_t, typename T::_run_check>;
|
||||
};
|
||||
|
||||
template <typename Context, typename T>
|
||||
|
@ -53,25 +53,19 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename ValueType>
|
||||
struct serializer_t<Context, value_or_null_t<ValueType>>
|
||||
Context& serialize(const value_or_null_t<ValueType>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using Operand = value_or_null_t<ValueType>;
|
||||
|
||||
static Context& _(const Operand& t, Context& context)
|
||||
if (t._is_null)
|
||||
{
|
||||
if (t._is_null)
|
||||
{
|
||||
context << "NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
serialize(wrap_operand_t<typename ValueType::_cpp_value_type>{t._value}, context);
|
||||
}
|
||||
|
||||
return context;
|
||||
context << "NULL";
|
||||
}
|
||||
};
|
||||
else
|
||||
{
|
||||
serialize(wrap_operand_t<typename ValueType::_cpp_value_type>{t._value}, context);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto value_or_null(T t) -> value_or_null_t<value_type_of<wrap_operand_t<T>>>
|
||||
|
@ -365,53 +365,35 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Database, typename Expression>
|
||||
struct serializer_t<Context, where_data_t<Database, Expression>>
|
||||
Context& serialize(const where_data_t<Database, Expression>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Expression>;
|
||||
using T = where_data_t<Database, Expression>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
context << " WHERE ";
|
||||
serialize(t._expression, context);
|
||||
if (not t._dynamic_expressions.empty())
|
||||
{
|
||||
context << " WHERE ";
|
||||
serialize(t._expression, context);
|
||||
if (not t._dynamic_expressions.empty())
|
||||
{
|
||||
context << " AND ";
|
||||
}
|
||||
interpret_list(t._dynamic_expressions, " AND ", context);
|
||||
return context;
|
||||
context << " AND ";
|
||||
}
|
||||
};
|
||||
interpret_list(t._dynamic_expressions, " AND ", context);
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context, typename Database>
|
||||
struct serializer_t<Context, where_data_t<Database, unconditional_t>>
|
||||
Context& serialize(const where_data_t<Database, unconditional_t>& t, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = where_data_t<Database, unconditional_t>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
if (t._dynamic_expressions.empty())
|
||||
{
|
||||
if (t._dynamic_expressions.empty())
|
||||
{
|
||||
return context;
|
||||
}
|
||||
context << " WHERE ";
|
||||
interpret_list(t._dynamic_expressions, " AND ", context);
|
||||
return context;
|
||||
}
|
||||
};
|
||||
context << " WHERE ";
|
||||
interpret_list(t._dynamic_expressions, " AND ", context);
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
struct serializer_t<Context, where_data_t<void, unconditional_t>>
|
||||
Context& serialize(const where_data_t<void, unconditional_t>&, Context& context)
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = where_data_t<void, unconditional_t>;
|
||||
|
||||
static Context& _(const T& /*unused*/, Context& context)
|
||||
{
|
||||
return context;
|
||||
}
|
||||
};
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto where(T&& t) -> decltype(statement_t<void, no_where_t<false>>().where(std::forward<T>(t)))
|
||||
|
@ -89,14 +89,14 @@ struct MockDb : public sqlpp::connection
|
||||
template <typename T>
|
||||
static _serializer_context_t& _serialize_interpretable(const T& t, _serializer_context_t& context)
|
||||
{
|
||||
sqlpp::serialize(t, context);
|
||||
serialize(t, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static _serializer_context_t& _interpret_interpretable(const T& t, _interpreter_context_t& context)
|
||||
{
|
||||
sqlpp::serialize(t, context);
|
||||
serialize(t, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ struct MockDb : public sqlpp::connection
|
||||
size_t execute(const Statement& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running execute call with\n" << context.str() << std::endl;
|
||||
return execute(context.str());
|
||||
}
|
||||
@ -151,7 +151,7 @@ struct MockDb : public sqlpp::connection
|
||||
size_t insert(const Insert& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running insert call with\n" << context.str() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@ -160,7 +160,7 @@ struct MockDb : public sqlpp::connection
|
||||
size_t update(const Update& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running update call with\n" << context.str() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@ -169,7 +169,7 @@ struct MockDb : public sqlpp::connection
|
||||
size_t remove(const Remove& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running remove call with\n" << context.str() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@ -178,7 +178,7 @@ struct MockDb : public sqlpp::connection
|
||||
result_t select(const Select& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running select call with\n" << context.str() << std::endl;
|
||||
return {};
|
||||
}
|
||||
@ -205,7 +205,7 @@ struct MockDb : public sqlpp::connection
|
||||
_prepared_statement_t prepare_execute(Statement& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running prepare execute call with\n" << context.str() << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
@ -214,7 +214,7 @@ struct MockDb : public sqlpp::connection
|
||||
_prepared_statement_t prepare_insert(Insert& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running prepare insert call with\n" << context.str() << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
@ -235,7 +235,7 @@ struct MockDb : public sqlpp::connection
|
||||
_prepared_statement_t prepare_select(Select& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running prepare select call with\n" << context.str() << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
@ -303,14 +303,14 @@ struct MockSizeDb : public sqlpp::connection
|
||||
template <typename T>
|
||||
static _serializer_context_t& _serialize_interpretable(const T& t, _serializer_context_t& context)
|
||||
{
|
||||
sqlpp::serialize(t, context);
|
||||
serialize(t, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static _serializer_context_t& _interpret_interpretable(const T& t, _interpreter_context_t& context)
|
||||
{
|
||||
sqlpp::serialize(t, context);
|
||||
serialize(t, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -350,7 +350,7 @@ struct MockSizeDb : public sqlpp::connection
|
||||
size_t execute(const Statement& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running execute call with\n" << context.str() << std::endl;
|
||||
return execute(context.str());
|
||||
}
|
||||
@ -359,7 +359,7 @@ struct MockSizeDb : public sqlpp::connection
|
||||
size_t insert(const Insert& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running insert call with\n" << context.str() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@ -368,7 +368,7 @@ struct MockSizeDb : public sqlpp::connection
|
||||
size_t update(const Update& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running update call with\n" << context.str() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@ -377,7 +377,7 @@ struct MockSizeDb : public sqlpp::connection
|
||||
size_t remove(const Remove& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running remove call with\n" << context.str() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@ -386,7 +386,7 @@ struct MockSizeDb : public sqlpp::connection
|
||||
result_t select(const Select& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running select call with\n" << context.str() << std::endl;
|
||||
return {};
|
||||
}
|
||||
@ -413,7 +413,7 @@ struct MockSizeDb : public sqlpp::connection
|
||||
_prepared_statement_t prepare_execute(Statement& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running prepare execute call with\n" << context.str() << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
@ -422,7 +422,7 @@ struct MockSizeDb : public sqlpp::connection
|
||||
_prepared_statement_t prepare_insert(Insert& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running prepare insert call with\n" << context.str() << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
@ -443,7 +443,7 @@ struct MockSizeDb : public sqlpp::connection
|
||||
_prepared_statement_t prepare_select(Select& x)
|
||||
{
|
||||
_serializer_context_t context;
|
||||
::sqlpp::serialize(x, context);
|
||||
serialize(x, context);
|
||||
std::cout << "Running prepare select call with\n" << context.str() << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -73,6 +73,8 @@ int Select(int, char*[])
|
||||
getColumn(db, t.alpha);
|
||||
select(count(t.alpha));
|
||||
|
||||
std::cerr << serialize(select(sqlpp::value(false).as(sqlpp::alias::a)), printer).str() << std::endl;
|
||||
/*
|
||||
for (const auto& row : db(select(sqlpp::value(false).as(sqlpp::alias::a))))
|
||||
{
|
||||
std::cout << row.a << std::endl;
|
||||
@ -208,6 +210,7 @@ int Select(int, char*[])
|
||||
std::cout << "Error: transaction isolation level does not match default level" << std::endl;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user