mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08: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:
parent
833eeccd61
commit
f029e5993b
@ -56,8 +56,6 @@ namespace sqlpp
|
|||||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||||
using _nodes = detail::type_vector<Operand, Args...>;
|
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;
|
using _auto_alias_t = in_alias_t;
|
||||||
|
|
||||||
in_t(Operand operand, Args... args) : _operand(operand), _args(args...)
|
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>
|
template <typename Container>
|
||||||
struct value_list_t;
|
struct value_list_t;
|
||||||
|
|
||||||
@ -107,7 +118,7 @@ namespace sqlpp
|
|||||||
const auto& value_list = std::get<0>(t._args);
|
const auto& value_list = std::get<0>(t._args);
|
||||||
if (value_list._container.empty())
|
if (value_list._container.empty())
|
||||||
{
|
{
|
||||||
context << " 'operand in empty list' = 'false' ";
|
serialize(boolean_operand{false}, context);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -56,8 +56,6 @@ namespace sqlpp
|
|||||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||||
using _nodes = detail::type_vector<Operand, Args...>;
|
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;
|
using _auto_alias_t = not_in_alias_t;
|
||||||
|
|
||||||
not_in_t(Operand operand, Args... args) : _operand(operand), _args(args...)
|
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>
|
template <typename Container>
|
||||||
struct value_list_t;
|
struct value_list_t;
|
||||||
|
|
||||||
@ -107,7 +118,7 @@ namespace sqlpp
|
|||||||
const auto& value_list = std::get<0>(t._args);
|
const auto& value_list = std::get<0>(t._args);
|
||||||
if (value_list._container.empty())
|
if (value_list._container.empty())
|
||||||
{
|
{
|
||||||
context << " 'operand not in empty list' != 'false' ";
|
serialize(boolean_operand{true}, context);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -63,6 +63,12 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
_field::operator()()._bind(target, index);
|
_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>
|
template <std::size_t index, typename AliasProvider, typename Db, typename... FieldSpecs>
|
||||||
@ -91,6 +97,12 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
_multi_field::operator()()._bind(target);
|
_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>
|
template <typename Db, std::size_t NextIndex, std::size_t... Is, typename... FieldSpecs>
|
||||||
@ -117,6 +129,13 @@ namespace sqlpp
|
|||||||
using swallow = int[];
|
using swallow = int[];
|
||||||
(void)swallow{(result_field<Db, Is, FieldSpecs>::_bind(target), 0)...};
|
(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);
|
_impl::_bind(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Target>
|
||||||
|
void _post_bind(Target& target)
|
||||||
|
{
|
||||||
|
_impl::_post_bind(target);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Db, typename... FieldSpecs>
|
template <typename Db, typename... FieldSpecs>
|
||||||
@ -254,6 +279,19 @@ namespace sqlpp
|
|||||||
++index;
|
++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>
|
template <typename T>
|
||||||
|
@ -106,6 +106,7 @@ int Interpret(int, char**)
|
|||||||
serialize(update(t), printer).str();
|
serialize(update(t), printer).str();
|
||||||
serialize(update(t).set(t.gamma = true), printer).str();
|
serialize(update(t).set(t.gamma = true), printer).str();
|
||||||
serialize(update(t).set(t.gamma = true).where(t.beta.in("kaesekuchen", "cheesecake")), printer).str();
|
serialize(update(t).set(t.gamma = true).where(t.beta.in("kaesekuchen", "cheesecake")), printer).str();
|
||||||
|
serialize(update(t).set(t.gamma = true).where(t.beta.in()), printer).str();
|
||||||
|
|
||||||
serialize(remove_from(t), printer).str();
|
serialize(remove_from(t), printer).str();
|
||||||
serialize(remove_from(t).using_(t), printer).str();
|
serialize(remove_from(t).using_(t), printer).str();
|
||||||
@ -203,6 +204,12 @@ int Interpret(int, char**)
|
|||||||
std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in(select(f.epsilon).from(f).where(true))), printer)
|
std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in(select(f.epsilon).from(f).where(true))), printer)
|
||||||
.str() << std::endl;
|
.str() << std::endl;
|
||||||
|
|
||||||
|
printer.reset();
|
||||||
|
std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in()), printer).str() << std::endl;
|
||||||
|
|
||||||
|
printer.reset();
|
||||||
|
std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.not_in()), printer).str() << std::endl;
|
||||||
|
|
||||||
auto schema = db.attach("lorem");
|
auto schema = db.attach("lorem");
|
||||||
auto s = schema_qualified_table(schema, t).as(sqlpp::alias::x);
|
auto s = schema_qualified_table(schema, t).as(sqlpp::alias::x);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user