mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
interpret works for in()
This commit is contained in:
parent
602f33726f
commit
54fa55e6a5
@ -30,7 +30,7 @@
|
|||||||
#include <sqlpp11/expression_fwd.h>
|
#include <sqlpp11/expression_fwd.h>
|
||||||
#include <sqlpp11/alias.h>
|
#include <sqlpp11/alias.h>
|
||||||
#include <sqlpp11/sort_order.h>
|
#include <sqlpp11/sort_order.h>
|
||||||
#include <sqlpp11/in.h>
|
#include <sqlpp11/in_fwd.h>
|
||||||
#include <sqlpp11/is_null.h>
|
#include <sqlpp11/is_null.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
@ -136,14 +136,14 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Hint: use value_list wrapper for containers...
|
// Hint: use value_list wrapper for containers...
|
||||||
template<typename... T>
|
template<typename... T>
|
||||||
in_t<true, boolean, Base, typename Constraint<T>::type...> in(T&&... t) const
|
in_t<true, Base, typename Constraint<T>::type...> in(T&&... t) const
|
||||||
{
|
{
|
||||||
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used with in()");
|
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used with in()");
|
||||||
return { *static_cast<const Base*>(this), {std::forward<T>(t)}... };
|
return { *static_cast<const Base*>(this), {std::forward<T>(t)}... };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... T>
|
template<typename... T>
|
||||||
in_t<false, boolean, Base, typename Constraint<T>::type...> not_in(T&&... t) const
|
in_t<false, Base, typename Constraint<T>::type...> not_in(T&&... t) const
|
||||||
{
|
{
|
||||||
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot with be used with not_in()");
|
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot with be used with not_in()");
|
||||||
return { *static_cast<const Base*>(this), {std::forward<T>(t)}... };
|
return { *static_cast<const Base*>(this), {std::forward<T>(t)}... };
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <sqlpp11/parameter_list.h>
|
#include <sqlpp11/parameter_list.h>
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <sqlpp11/column_types.h>
|
#include <sqlpp11/column_types.h>
|
||||||
|
#include <sqlpp11/in.h>
|
||||||
#include <sqlpp11/exists.h>
|
#include <sqlpp11/exists.h>
|
||||||
#include <sqlpp11/any.h>
|
#include <sqlpp11/any.h>
|
||||||
#include <sqlpp11/some.h>
|
#include <sqlpp11/some.h>
|
||||||
|
@ -24,25 +24,26 @@
|
|||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SQLPP_IN_H
|
#ifndef SQLPP_IN_FWD_H
|
||||||
#define SQLPP_IN_H
|
#define SQLPP_IN_FWD_H
|
||||||
|
|
||||||
#include <sstream>
|
#include <sqlpp11/in_fwd.h>
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
|
#include <sqlpp11/boolean.h>
|
||||||
#include <sqlpp11/detail/set.h>
|
#include <sqlpp11/detail/set.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
// FIXME: Move to vendor namespace
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
// The ValueType should be boolean, this is a hack because boolean is not fully defined when the compiler first gets here...
|
template<bool NotInverted, typename Operand, typename... Args>
|
||||||
template<bool NotInverted, typename ValueType, typename Operand, typename... Args>
|
struct in_t: public boolean::template operators<in_t<NotInverted, Operand, Args...>>
|
||||||
struct in_t: public ValueType::_base_value_type::template operators<in_t<NotInverted, ValueType, Args...>>
|
|
||||||
{
|
{
|
||||||
static constexpr bool _inverted = not NotInverted;
|
static constexpr bool _inverted = not NotInverted;
|
||||||
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
|
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
|
||||||
|
|
||||||
struct _value_type: public ValueType::_base_value_type // we requite fully defined boolean here
|
struct _value_type: public boolean
|
||||||
{
|
{
|
||||||
using _is_named_expression = std::true_type;
|
using _is_named_expression = std::true_type;
|
||||||
};
|
};
|
||||||
@ -84,11 +85,26 @@ namespace sqlpp
|
|||||||
os << ")";
|
os << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
Operand _operand;
|
Operand _operand;
|
||||||
std::tuple<Args...> _args;
|
std::tuple<Args...> _args;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Context, bool NotInverted, typename Operand, typename... Args>
|
||||||
|
struct interpreter_t<Context, detail::in_t<NotInverted, Operand, Args...>>
|
||||||
|
{
|
||||||
|
using T = detail::in_t<NotInverted, Operand, Args...>;
|
||||||
|
|
||||||
|
static Context& _(const T& t, Context& context)
|
||||||
|
{
|
||||||
|
interpret(t._operand, context);
|
||||||
|
context << (t._inverted ? " NOT IN(" : " IN(");
|
||||||
|
interpret_tuple(t._args, ',', context);
|
||||||
|
context << ')';
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -61,6 +61,7 @@ namespace sqlpp
|
|||||||
using set_assignments_t = update_t<Database, Table, AssignmentsT, Where>;
|
using set_assignments_t = update_t<Database, Table, AssignmentsT, Where>;
|
||||||
template<typename WhereT>
|
template<typename WhereT>
|
||||||
using set_where_t = update_t<Database, Table, Assignments, WhereT>;
|
using set_where_t = update_t<Database, Table, Assignments, WhereT>;
|
||||||
|
//FIXME: add method to explicitly indicate that EVERYTHING should be updated?
|
||||||
|
|
||||||
using _parameter_tuple_t = std::tuple<Table, Assignments, Where>;
|
using _parameter_tuple_t = std::tuple<Table, Assignments, Where>;
|
||||||
using _parameter_list_t = typename make_parameter_list_t<update_t>::type;
|
using _parameter_list_t = typename make_parameter_list_t<update_t>::type;
|
||||||
|
@ -68,6 +68,7 @@ int main()
|
|||||||
|
|
||||||
interpret(update(t), printer).flush();
|
interpret(update(t), printer).flush();
|
||||||
interpret(update(t).set(t.gamma = true), printer).flush();
|
interpret(update(t).set(t.gamma = true), printer).flush();
|
||||||
|
interpret(update(t).set(t.gamma = true).where(t.beta.in("kaesekuchen", "cheesecake")), printer).flush();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user