mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Remove rhs_wrap (was required for tvin only)
This commit is contained in:
parent
db0295a9d0
commit
93b0093fb5
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <sqlpp11/default_value.h>
|
#include <sqlpp11/default_value.h>
|
||||||
#include <sqlpp11/null.h>
|
#include <sqlpp11/null.h>
|
||||||
#include <sqlpp11/rhs_wrap.h>
|
|
||||||
#include <sqlpp11/serialize.h>
|
#include <sqlpp11/serialize.h>
|
||||||
#include <sqlpp11/serializer.h>
|
#include <sqlpp11/serializer.h>
|
||||||
#include <sqlpp11/simple_column.h>
|
#include <sqlpp11/simple_column.h>
|
||||||
@ -41,7 +40,7 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
using _traits = make_traits<no_value_t, tag::is_assignment>;
|
using _traits = make_traits<no_value_t, tag::is_assignment>;
|
||||||
using _lhs_t = Lhs;
|
using _lhs_t = Lhs;
|
||||||
using _rhs_t = rhs_wrap_t<Rhs>;
|
using _rhs_t = Rhs;
|
||||||
using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
|
using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
|
||||||
|
|
||||||
static_assert(can_be_null_t<_lhs_t>::value ? true
|
static_assert(can_be_null_t<_lhs_t>::value ? true
|
||||||
|
@ -47,7 +47,7 @@ namespace sqlpp
|
|||||||
using rhs = wrap_operand_t<T>;
|
using rhs = wrap_operand_t<T>;
|
||||||
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
|
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
|
||||||
|
|
||||||
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
|
return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -56,7 +56,7 @@ namespace sqlpp
|
|||||||
using rhs = wrap_operand_t<T>;
|
using rhs = wrap_operand_t<T>;
|
||||||
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
|
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
|
||||||
|
|
||||||
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
|
return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -65,7 +65,7 @@ namespace sqlpp
|
|||||||
using rhs = wrap_operand_t<T>;
|
using rhs = wrap_operand_t<T>;
|
||||||
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
|
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
|
||||||
|
|
||||||
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
|
return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -74,7 +74,7 @@ namespace sqlpp
|
|||||||
using rhs = wrap_operand_t<T>;
|
using rhs = wrap_operand_t<T>;
|
||||||
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
|
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
|
||||||
|
|
||||||
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
|
return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
#include <sqlpp11/data_types/boolean.h>
|
#include <sqlpp11/data_types/boolean.h>
|
||||||
#include <sqlpp11/expression_fwd.h>
|
#include <sqlpp11/expression_fwd.h>
|
||||||
#include <sqlpp11/noop.h>
|
#include <sqlpp11/noop.h>
|
||||||
#include <sqlpp11/rhs_wrap.h>
|
|
||||||
#include <sqlpp11/serializer.h>
|
#include <sqlpp11/serializer.h>
|
||||||
#include <sqlpp11/wrap_operand.h>
|
#include <sqlpp11/wrap_operand.h>
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
using _traits = make_traits<boolean, tag::is_expression>;
|
using _traits = make_traits<boolean, tag::is_expression>;
|
||||||
using _lhs_t = Lhs;
|
using _lhs_t = Lhs;
|
||||||
using _rhs_t = rhs_wrap_t<Rhs>;
|
using _rhs_t = Rhs;
|
||||||
using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
|
using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
|
||||||
|
|
||||||
binary_expression_t(Lhs lhs, Rhs rhs) : _lhs(lhs), _rhs(rhs)
|
binary_expression_t(Lhs lhs, Rhs rhs) : _lhs(lhs), _rhs(rhs)
|
||||||
@ -85,7 +84,7 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
using _traits = make_traits<boolean, tag::is_expression>;
|
using _traits = make_traits<boolean, tag::is_expression>;
|
||||||
using _lhs_t = Lhs;
|
using _lhs_t = Lhs;
|
||||||
using _rhs_t = rhs_wrap_t<Rhs>;
|
using _rhs_t = Rhs;
|
||||||
using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
|
using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
|
||||||
|
|
||||||
binary_expression_t(Lhs lhs, Rhs rhs) : _lhs(lhs), _rhs(rhs)
|
binary_expression_t(Lhs lhs, Rhs rhs) : _lhs(lhs), _rhs(rhs)
|
||||||
|
@ -62,26 +62,25 @@ namespace sqlpp
|
|||||||
using _column_t = Column;
|
using _column_t = Column;
|
||||||
using _pure_value_t = typename value_type_of<Column>::_cpp_value_type;
|
using _pure_value_t = typename value_type_of<Column>::_cpp_value_type;
|
||||||
using _wrapped_value_t = wrap_operand_t<_pure_value_t>;
|
using _wrapped_value_t = wrap_operand_t<_pure_value_t>;
|
||||||
using _tvin_t = _wrapped_value_t;
|
|
||||||
using _value_or_null_t = value_or_null_t<typename Column::_traits::_value_type>;
|
using _value_or_null_t = value_or_null_t<typename Column::_traits::_value_type>;
|
||||||
|
|
||||||
insert_value_t(rhs_wrap_t<_wrapped_value_t> rhs)
|
insert_value_t(_wrapped_value_t rhs)
|
||||||
: _is_null(rhs._is_null()), _is_default(rhs._is_default()), _value(rhs._expr._t)
|
: _is_null(false), _is_default(false), _value(rhs._t)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_value_t(const rhs_wrap_t<null_t>& /*unused*/)
|
insert_value_t(const null_t& /*unused*/)
|
||||||
: _is_null(true), _is_default(false), _value{}
|
: _is_null(true), _is_default(false), _value{}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_value_t(const rhs_wrap_t<default_value_t>& /*unused*/)
|
insert_value_t(const default_value_t& /*unused*/)
|
||||||
: _is_null(false), _is_default(true), _value{}
|
: _is_null(false), _is_default(true), _value{}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_value_t(const rhs_wrap_t<_value_or_null_t>& rhs)
|
insert_value_t(const _value_or_null_t& rhs)
|
||||||
: _is_null(rhs._expr._is_null), _is_default(false), _value{rhs._expr._value}
|
: _is_null(rhs._is_null), _is_default(false), _value{rhs._value}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2013-2015, Roland Bock
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
* are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SQLPP11_RHS_WRAP_H
|
|
||||||
#define SQLPP11_RHS_WRAP_H
|
|
||||||
|
|
||||||
#include <sqlpp11/default_value.h>
|
|
||||||
#include <sqlpp11/null.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template <typename Expr, typename Enable = void>
|
|
||||||
struct rhs_is_trivial_t
|
|
||||||
{
|
|
||||||
static constexpr bool _(const Expr& /*unused*/)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Expr>
|
|
||||||
struct rhs_is_trivial_t<Expr, typename std::enable_if<is_wrapped_value_t<Expr>::value, void>::type>
|
|
||||||
{
|
|
||||||
static bool _(const Expr& t)
|
|
||||||
{
|
|
||||||
return t._is_trivial();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Expr>
|
|
||||||
struct rhs_is_trivial_t<Expr, typename std::enable_if<is_result_field_t<Expr>::value, void>::type>
|
|
||||||
{
|
|
||||||
static bool _(const Expr& t)
|
|
||||||
{
|
|
||||||
if (t.is_null())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return t._is_trivial();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Expr, typename Enable = void>
|
|
||||||
struct rhs_is_null_t
|
|
||||||
{
|
|
||||||
static constexpr bool _(const Expr& /*unused*/)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Expr>
|
|
||||||
struct rhs_is_null_t<Expr, typename std::enable_if<is_result_field_t<Expr>::value, void>::type>
|
|
||||||
{
|
|
||||||
static bool _(const Expr& t)
|
|
||||||
{
|
|
||||||
return t.is_null();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template <typename Expr>
|
|
||||||
struct rhs_wrap_t
|
|
||||||
{
|
|
||||||
using _traits = typename Expr::_traits;
|
|
||||||
using _nodes = detail::type_vector<Expr>;
|
|
||||||
|
|
||||||
rhs_wrap_t(Expr expr) : _expr(expr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
rhs_wrap_t(const rhs_wrap_t&) = default;
|
|
||||||
rhs_wrap_t(rhs_wrap_t&&) = default;
|
|
||||||
rhs_wrap_t& operator=(const rhs_wrap_t&) = default;
|
|
||||||
rhs_wrap_t& operator=(rhs_wrap_t&&) = default;
|
|
||||||
~rhs_wrap_t() = default;
|
|
||||||
|
|
||||||
bool _is_null() const
|
|
||||||
{
|
|
||||||
return detail::rhs_is_null_t<Expr>::_(_expr);
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr bool _is_default()
|
|
||||||
{
|
|
||||||
return std::is_same<Expr, default_value_t>::value;
|
|
||||||
}
|
|
||||||
|
|
||||||
Expr _expr;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Context, typename Expr>
|
|
||||||
struct serializer_t<Context, rhs_wrap_t<Expr>>
|
|
||||||
{
|
|
||||||
using _serialize_check = serialize_check_of<Context, Expr>;
|
|
||||||
using T = rhs_wrap_t<Expr>;
|
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
|
||||||
if (t._is_null())
|
|
||||||
{
|
|
||||||
context << "NULL";
|
|
||||||
}
|
|
||||||
else if (t._is_default())
|
|
||||||
{
|
|
||||||
context << "DEFAULT";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
serialize(t._expr, context);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
|
||||||
|
|
||||||
#endif
|
|
@ -45,11 +45,6 @@ int Result(int, char* [])
|
|||||||
static_assert(sqlpp::can_be_null_t<T>::value, "row.alpha can be null");
|
static_assert(sqlpp::can_be_null_t<T>::value, "row.alpha can be null");
|
||||||
static_assert(sqlpp::is_result_field_t<T>::value, "result_fields are not wrapped");
|
static_assert(sqlpp::is_result_field_t<T>::value, "result_fields are not wrapped");
|
||||||
|
|
||||||
bool x = (t.alpha == row.alpha)._rhs._is_null();
|
|
||||||
bool y = (t.alpha == row.alpha)._rhs._is_default();
|
|
||||||
std::cerr << x << std::endl;
|
|
||||||
std::cerr << y << std::endl;
|
|
||||||
|
|
||||||
for (const auto& sub : db(select(all_of(t)).from(t).where(t.alpha == row.alpha)))
|
for (const auto& sub : db(select(all_of(t)).from(t).where(t.alpha == row.alpha)))
|
||||||
{
|
{
|
||||||
std::cerr << sub.alpha << std::endl;
|
std::cerr << sub.alpha << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user