mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-04-28 15:09:26 -05:00
Allow in() and not_in() to have zero arguments
This is then equivalent to in(value_list(some_empty_vector)) and not_in(value_list(some_empty_vector): tab.a.in() evaluates to false tab.a.not_in() evaluates to true
This commit is contained in:
+14
-3
@@ -56,8 +56,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Operand, Args...>;
|
||||
|
||||
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
|
||||
|
||||
using _auto_alias_t = in_alias_t;
|
||||
|
||||
in_t(Operand operand, Args... args) : _operand(operand), _args(args...)
|
||||
@@ -93,6 +91,19 @@ namespace sqlpp
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Context, typename Operand>
|
||||
struct serializer_t<Context, in_t<Operand>>
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = in_t<Operand>;
|
||||
|
||||
static Context& _(const T&, Context& context)
|
||||
{
|
||||
serialize(boolean_operand{false}, context);
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Container>
|
||||
struct value_list_t;
|
||||
|
||||
@@ -107,7 +118,7 @@ namespace sqlpp
|
||||
const auto& value_list = std::get<0>(t._args);
|
||||
if (value_list._container.empty())
|
||||
{
|
||||
context << " 'operand in empty list' = 'false' ";
|
||||
serialize(boolean_operand{false}, context);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -56,8 +56,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Operand, Args...>;
|
||||
|
||||
static_assert(sizeof...(Args) > 0, "not_in() requires at least one argument");
|
||||
|
||||
using _auto_alias_t = not_in_alias_t;
|
||||
|
||||
not_in_t(Operand operand, Args... args) : _operand(operand), _args(args...)
|
||||
@@ -93,6 +91,19 @@ namespace sqlpp
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Context, typename Operand>
|
||||
struct serializer_t<Context, not_in_t<Operand>>
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = not_in_t<Operand>;
|
||||
|
||||
static Context& _(const T&, Context& context)
|
||||
{
|
||||
serialize(boolean_operand{true}, context);
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Container>
|
||||
struct value_list_t;
|
||||
|
||||
@@ -107,7 +118,7 @@ namespace sqlpp
|
||||
const auto& value_list = std::get<0>(t._args);
|
||||
if (value_list._container.empty())
|
||||
{
|
||||
context << " 'operand not in empty list' != 'false' ";
|
||||
serialize(boolean_operand{true}, context);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -63,6 +63,12 @@ namespace sqlpp
|
||||
{
|
||||
_field::operator()()._bind(target, index);
|
||||
}
|
||||
|
||||
template <typename Target>
|
||||
void _post_bind(Target& target)
|
||||
{
|
||||
_field::operator()()._post_bind(target, index);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t index, typename AliasProvider, typename Db, typename... FieldSpecs>
|
||||
@@ -91,6 +97,12 @@ namespace sqlpp
|
||||
{
|
||||
_multi_field::operator()()._bind(target);
|
||||
}
|
||||
|
||||
template <typename Target>
|
||||
void _post_bind(Target& target)
|
||||
{
|
||||
_multi_field::operator()()._post_bind(target);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Db, std::size_t NextIndex, std::size_t... Is, typename... FieldSpecs>
|
||||
@@ -117,6 +129,13 @@ namespace sqlpp
|
||||
using swallow = int[];
|
||||
(void)swallow{(result_field<Db, Is, FieldSpecs>::_bind(target), 0)...};
|
||||
}
|
||||
|
||||
template <typename Target>
|
||||
void _post_bind(Target& target)
|
||||
{
|
||||
using swallow = int[];
|
||||
(void)swallow{(result_field<Db, Is, FieldSpecs>::_post_bind(target), 0)...};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -175,6 +194,12 @@ namespace sqlpp
|
||||
{
|
||||
_impl::_bind(target);
|
||||
}
|
||||
|
||||
template <typename Target>
|
||||
void _post_bind(Target& target)
|
||||
{
|
||||
_impl::_post_bind(target);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Db, typename... FieldSpecs>
|
||||
@@ -254,6 +279,19 @@ namespace sqlpp
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Target>
|
||||
void _post_bind(Target& target)
|
||||
{
|
||||
_impl::_post_bind(target);
|
||||
|
||||
std::size_t index = _field_index_sequence::_next_index;
|
||||
for (const auto& field_name : _dynamic_field_names)
|
||||
{
|
||||
_dynamic_fields.at(field_name)._post_bind(target, index);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
||||
Reference in New Issue
Block a user