From 2b8a36aa97c9f2a2146a5e6fb7b681e1e51dd5b0 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 5 Jul 2015 13:53:38 +0200 Subject: [PATCH] Added support for empty in() and not_in() I wonder why SQL does not have that anyway. --- include/sqlpp11/in.h | 27 +++++++++++++++++++++++++++ include/sqlpp11/not_in.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/include/sqlpp11/in.h b/include/sqlpp11/in.h index 9628ee84..28d9901f 100644 --- a/include/sqlpp11/in.h +++ b/include/sqlpp11/in.h @@ -95,6 +95,33 @@ namespace sqlpp } }; + template + struct value_list_t; + + template + struct serializer_t>> + { + using _serialize_check = serialize_check_of>; + using T = in_t>; + + static Context& _(const T& t, Context& context) + { + const auto& value_list = std::get<0>(t._args); + if (value_list._container.empty()) + { + context << " 'operand in empty list' = 'false' "; + } + else + { + serialize(t._operand, context); + context << " IN("; + serialize(value_list, context); + context << ')'; + } + return context; + } + }; + } #endif diff --git a/include/sqlpp11/not_in.h b/include/sqlpp11/not_in.h index c42edc70..d230d815 100644 --- a/include/sqlpp11/not_in.h +++ b/include/sqlpp11/not_in.h @@ -95,6 +95,34 @@ namespace sqlpp } }; + template + struct value_list_t; + + template + struct serializer_t>> + { + using _serialize_check = serialize_check_of>; + using T = not_in_t>; + + static Context& _(const T& t, Context& context) + { + const auto& value_list = std::get<0>(t._args); + if (value_list._container.empty()) + { + context << " 'operand not in empty list' != 'false' "; + } + else + { + serialize(t._operand, context); + context << " NOT IN("; + serialize(value_list, context); + context << ')'; + } + return context; + } + }; + + } #endif