2023-07-25 13:00:05 +08:00
|
|
|
#pragma once
|
|
|
|
|
2013-10-02 16:55:36 +08:00
|
|
|
/*
|
2015-02-16 02:00:21 +08:00
|
|
|
* Copyright (c) 2013-2015, Roland Bock
|
2013-10-02 16:55:36 +08:00
|
|
|
* All rights reserved.
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
2013-10-02 16:55:36 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
2013-10-02 16:55:36 +08:00
|
|
|
* Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
2013-10-02 16:55:36 +08:00
|
|
|
* 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.
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
2013-10-02 16:55:36 +08:00
|
|
|
* 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 <sqlpp11/type_traits.h>
|
2014-12-01 02:40:34 +08:00
|
|
|
#include <sqlpp11/char_sequence.h>
|
2015-10-30 05:21:46 +08:00
|
|
|
#include <sqlpp11/data_types/boolean.h>
|
2014-06-14 00:51:51 +08:00
|
|
|
#include <sqlpp11/in_fwd.h>
|
2014-02-02 21:58:08 +08:00
|
|
|
#include <sqlpp11/detail/type_set.h>
|
2013-10-02 16:55:36 +08:00
|
|
|
|
|
|
|
namespace sqlpp
|
|
|
|
{
|
2015-09-14 03:33:19 +08:00
|
|
|
struct in_alias_t
|
|
|
|
{
|
|
|
|
struct _alias_t
|
|
|
|
{
|
|
|
|
static constexpr const char _literal[] = "in_";
|
|
|
|
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
|
|
|
template <typename T>
|
|
|
|
struct _member_t
|
|
|
|
{
|
|
|
|
T in;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Operand, typename... Args>
|
|
|
|
struct in_t : public expression_operators<in_t<Operand, Args...>, boolean>,
|
|
|
|
public alias_operators<in_t<Operand, Args...>>
|
|
|
|
{
|
|
|
|
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
|
|
|
using _nodes = detail::type_vector<Operand, Args...>;
|
|
|
|
|
|
|
|
using _auto_alias_t = in_alias_t;
|
|
|
|
|
|
|
|
in_t(Operand operand, Args... args) : _operand(operand), _args(args...)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
in_t(const in_t&) = default;
|
|
|
|
in_t(in_t&&) = default;
|
|
|
|
in_t& operator=(const in_t&) = default;
|
|
|
|
in_t& operator=(in_t&&) = default;
|
|
|
|
~in_t() = default;
|
|
|
|
|
|
|
|
Operand _operand;
|
|
|
|
std::tuple<Args...> _args;
|
|
|
|
};
|
|
|
|
|
2021-08-02 00:39:11 +08:00
|
|
|
template <typename Context, typename Operand, typename Arg, typename... Args>
|
|
|
|
Context& serialize(const in_t<Operand, Arg, Args...>& t, Context& context)
|
2015-09-14 03:33:19 +08:00
|
|
|
{
|
2021-08-01 18:54:46 +08:00
|
|
|
serialize(t._operand, context);
|
|
|
|
context << " IN(";
|
2021-08-02 00:39:11 +08:00
|
|
|
if (sizeof...(Args) == 0)
|
2015-09-14 03:33:19 +08:00
|
|
|
{
|
2021-08-01 18:54:46 +08:00
|
|
|
serialize(std::get<0>(t._args), context);
|
2015-09-14 03:33:19 +08:00
|
|
|
}
|
2021-08-01 18:54:46 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
interpret_tuple(t._args, ',', context);
|
|
|
|
}
|
|
|
|
context << ')';
|
|
|
|
return context;
|
|
|
|
}
|
2015-09-14 03:33:19 +08:00
|
|
|
|
2015-12-19 22:15:04 +08:00
|
|
|
template <typename Context, typename Operand>
|
2021-08-01 18:54:46 +08:00
|
|
|
Context& serialize(const in_t<Operand>&, Context& context)
|
2015-12-19 22:15:04 +08:00
|
|
|
{
|
2021-08-01 18:54:46 +08:00
|
|
|
serialize(boolean_operand{false}, context);
|
|
|
|
return context;
|
|
|
|
}
|
2015-12-19 22:15:04 +08:00
|
|
|
|
2015-09-14 03:33:19 +08:00
|
|
|
template <typename Container>
|
|
|
|
struct value_list_t;
|
|
|
|
|
|
|
|
template <typename Context, typename Operand, typename Container>
|
2021-08-01 18:54:46 +08:00
|
|
|
Context& serialize(const in_t<Operand, value_list_t<Container>>& t, Context& context)
|
2015-09-14 03:33:19 +08:00
|
|
|
{
|
2021-08-01 18:54:46 +08:00
|
|
|
const auto& value_list = std::get<0>(t._args);
|
|
|
|
if (value_list._container.empty())
|
2015-09-14 03:33:19 +08:00
|
|
|
{
|
2021-08-01 18:54:46 +08:00
|
|
|
serialize(boolean_operand{false}, context);
|
2015-09-14 03:33:19 +08:00
|
|
|
}
|
2021-08-01 18:54:46 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
serialize(t._operand, context);
|
|
|
|
context << " IN(";
|
|
|
|
serialize(value_list, context);
|
|
|
|
context << ')';
|
|
|
|
}
|
|
|
|
return context;
|
|
|
|
}
|
2017-09-10 20:56:51 +08:00
|
|
|
} // namespace sqlpp
|