mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Repaired insert to work with expression values again
This commit is contained in:
parent
d79c2ca92c
commit
3484903525
@ -30,9 +30,7 @@
|
||||
#include <sqlpp11/default_value.h>
|
||||
#include <sqlpp11/null.h>
|
||||
#include <sqlpp11/tvin.h>
|
||||
#include <sqlpp11/rhs_is_null.h>
|
||||
#include <sqlpp11/rhs_is_default.h>
|
||||
#include <sqlpp11/rhs_is_trivial.h>
|
||||
#include <sqlpp11/rhs_wrap.h>
|
||||
#include <sqlpp11/serialize.h>
|
||||
#include <sqlpp11/serializer.h>
|
||||
#include <sqlpp11/simple_column.h>
|
||||
@ -46,7 +44,7 @@ namespace sqlpp
|
||||
using _recursive_traits = make_recursive_traits<Lhs, Rhs>;
|
||||
|
||||
using _lhs_t = Lhs;
|
||||
using _rhs_t = allow_tvin_t<Rhs>;
|
||||
using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>;
|
||||
|
||||
static_assert(can_be_null_t<_lhs_t>::value ? true : not (std::is_same<_rhs_t, null_t>::value or is_tvin_t<_rhs_t>::value), "column must not be null");
|
||||
|
||||
@ -73,20 +71,8 @@ namespace sqlpp
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
serialize(simple_column(t._lhs), context);
|
||||
if ((trivial_value_is_null_t<typename T::_lhs_t>::value and rhs_is_trivial(t))
|
||||
or rhs_is_null(t))
|
||||
{
|
||||
context << "=NULL";
|
||||
}
|
||||
else if (rhs_is_default(t))
|
||||
{
|
||||
context << "=DEFAULT";
|
||||
}
|
||||
else
|
||||
{
|
||||
context << "=";
|
||||
serialize(t._rhs, context);
|
||||
}
|
||||
context << "=";
|
||||
serialize(t._rhs, context);
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
@ -57,7 +57,7 @@ namespace sqlpp
|
||||
using rhs = wrap_operand_t<T>;
|
||||
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
||||
|
||||
return { *static_cast<const Base*>(this), rhs{t} };
|
||||
return { *static_cast<const Base*>(this), {rhs{t}} };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@ -66,7 +66,7 @@ namespace sqlpp
|
||||
using rhs = wrap_operand_t<T>;
|
||||
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
||||
|
||||
return { *static_cast<const Base*>(this), rhs{t} };
|
||||
return { *static_cast<const Base*>(this), {rhs{t}} };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -92,20 +92,20 @@ namespace sqlpp
|
||||
using rhs = wrap_operand_t<T>;
|
||||
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand assignment operand");
|
||||
|
||||
return { *this, rhs{t} };
|
||||
return { *this, {rhs{t}} };
|
||||
}
|
||||
|
||||
auto operator =(sqlpp::null_t) const
|
||||
->assignment_t<column_t, sqlpp::null_t>
|
||||
{
|
||||
static_assert(can_be_null_t<column_t>::value, "column cannot be null");
|
||||
return { *this, {} };
|
||||
return { *this, sqlpp::null_t{} };
|
||||
}
|
||||
|
||||
auto operator =(sqlpp::default_value_t) const
|
||||
->assignment_t<column_t, sqlpp::default_value_t>
|
||||
{
|
||||
return { *this, {} };
|
||||
return { *this, sqlpp::default_value_t{} };
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -30,8 +30,7 @@
|
||||
#include <sqlpp11/alias.h>
|
||||
#include <sqlpp11/boolean.h>
|
||||
#include <sqlpp11/tvin.h>
|
||||
#include <sqlpp11/rhs_is_null.h>
|
||||
#include <sqlpp11/rhs_is_trivial.h>
|
||||
#include <sqlpp11/rhs_wrap.h>
|
||||
#include <sqlpp11/noop.h>
|
||||
#include <sqlpp11/expression_fwd.h>
|
||||
#include <sqlpp11/serializer.h>
|
||||
@ -46,7 +45,7 @@ namespace sqlpp
|
||||
using _traits = make_traits<boolean, sqlpp::tag::is_expression>;
|
||||
using _recursive_traits = make_recursive_traits<Lhs, Rhs>;
|
||||
using _lhs_t = Lhs;
|
||||
using _rhs_t = allow_tvin_t<Rhs>;
|
||||
using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>;
|
||||
|
||||
binary_expression_t(_lhs_t lhs, _rhs_t rhs):
|
||||
_lhs(lhs),
|
||||
@ -72,8 +71,7 @@ namespace sqlpp
|
||||
{
|
||||
context << "(";
|
||||
serialize(t._lhs, context);
|
||||
if ((trivial_value_is_null_t<typename T::_lhs_t>::value and rhs_is_trivial(t))
|
||||
or rhs_is_null(t))
|
||||
if (t._rhs._is_null())
|
||||
{
|
||||
context << " IS NULL";
|
||||
}
|
||||
@ -94,7 +92,7 @@ namespace sqlpp
|
||||
using _traits = make_traits<boolean, sqlpp::tag::is_expression>;
|
||||
using _recursive_traits = make_recursive_traits<Lhs, Rhs>;
|
||||
using _lhs_t = Lhs;
|
||||
using _rhs_t = allow_tvin_t<Rhs>;
|
||||
using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>;
|
||||
|
||||
binary_expression_t(Lhs lhs, _rhs_t rhs):
|
||||
_lhs(lhs),
|
||||
@ -120,8 +118,7 @@ namespace sqlpp
|
||||
{
|
||||
context << "(";
|
||||
serialize(t._lhs, context);
|
||||
if ((trivial_value_is_null_t<typename T::_lhs_t>::value and rhs_is_trivial(t))
|
||||
or rhs_is_null(t))
|
||||
if (t._rhs._is_null())
|
||||
{
|
||||
context << " IS NOT NULL";
|
||||
}
|
||||
|
@ -60,41 +60,35 @@ namespace sqlpp
|
||||
{
|
||||
using _is_insert_value = std::true_type;
|
||||
using _column_t = Column;
|
||||
static constexpr bool _trivial_value_is_null = trivial_value_is_null_t<Column>::value;
|
||||
using _pure_value_t = typename value_type_of<Column>::_cpp_value_type;
|
||||
using _wrapped_value_t = typename wrap_operand<_pure_value_t>::type;
|
||||
using _tvin_t = tvin_t<_wrapped_value_t>;
|
||||
|
||||
insert_value_t(_wrapped_value_t rhs):
|
||||
_is_null(false),
|
||||
_is_default(false),
|
||||
_value(rhs)
|
||||
insert_value_t(rhs_wrap_t<_wrapped_value_t, _trivial_value_is_null> rhs):
|
||||
_is_null(rhs._is_null()),
|
||||
_is_default(rhs._is_default()),
|
||||
_value(rhs._expr._t)
|
||||
{}
|
||||
|
||||
insert_value_t(_tvin_t rhs):
|
||||
_is_null(rhs._is_trivial()),
|
||||
_is_default(false),
|
||||
_value(rhs._value)
|
||||
insert_value_t(rhs_wrap_t<_tvin_t, _trivial_value_is_null> rhs):
|
||||
_is_null(rhs._is_null()),
|
||||
_is_default(rhs._is_default()),
|
||||
_value(rhs._expr._value)
|
||||
{}
|
||||
|
||||
insert_value_t(const null_t&):
|
||||
insert_value_t(const rhs_wrap_t<null_t, _trivial_value_is_null>&):
|
||||
_is_null(true),
|
||||
_is_default(false),
|
||||
_value{}
|
||||
{}
|
||||
|
||||
insert_value_t(const default_value_t&):
|
||||
insert_value_t(const rhs_wrap_t<default_value_t, _trivial_value_is_null>&):
|
||||
_is_null(false),
|
||||
_is_default(true),
|
||||
_value{}
|
||||
{}
|
||||
|
||||
template<typename Db, typename FieldSpec>
|
||||
insert_value_t(const result_field_t<value_type_of<Column>, Db, FieldSpec>& rhs):
|
||||
_is_null(rhs.is_null()),
|
||||
_is_default(false),
|
||||
_value(rhs.is_null() ? _wrapped_value_t{} : rhs.value())
|
||||
{}
|
||||
|
||||
insert_value_t(const insert_value_t&) = default;
|
||||
insert_value_t(insert_value_t&&) = default;
|
||||
insert_value_t& operator=(const insert_value_t&) = default;
|
||||
|
@ -87,7 +87,7 @@ namespace sqlpp
|
||||
insert_list_data_t(Assignments... assignments):
|
||||
_assignments(assignments...),
|
||||
_columns({assignments._lhs}...),
|
||||
_values(insert_value_t<typename Assignments::_lhs_t>{assignments._rhs}...)
|
||||
_values({assignments._rhs}...)
|
||||
{}
|
||||
|
||||
insert_list_data_t(const insert_list_data_t&) = default;
|
||||
@ -98,7 +98,7 @@ namespace sqlpp
|
||||
|
||||
std::tuple<Assignments...> _assignments; // FIXME: Need to replace _columns and _values by _assignments (connector-container requires assignments)
|
||||
std::tuple<simple_column_t<typename Assignments::_lhs_t>...> _columns;
|
||||
std::tuple<insert_value_t<typename Assignments::_lhs_t>...> _values;
|
||||
std::tuple<typename Assignments::_rhs_t...> _values;
|
||||
interpretable_list_t<Database> _dynamic_columns;
|
||||
interpretable_list_t<Database> _dynamic_values;
|
||||
};
|
||||
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2014, 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 SQLPP_RHS_IS_DEFAULT_H
|
||||
#define SQLPP_RHS_IS_DEFAULT_H
|
||||
|
||||
#include <sqlpp11/default_value.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename T, typename Enable = void>
|
||||
struct rhs_is_default_t
|
||||
{
|
||||
static constexpr bool _(const T&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct rhs_is_default_t<T, typename std::enable_if<std::is_same<T, default_value_t>::value, void>::type>
|
||||
{
|
||||
static constexpr bool _(const T& t)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Expression>
|
||||
constexpr bool rhs_is_default(const Expression& e)
|
||||
{
|
||||
return rhs_is_default_t<typename std::decay<Expression>::type::_rhs_t>::_(e._rhs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2014, 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 SQLPP_RHS_IS_NULL_H
|
||||
#define SQLPP_RHS_IS_NULL_H
|
||||
|
||||
#include <sqlpp11/tvin.h>
|
||||
#include <sqlpp11/null.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename T, typename Enable = void>
|
||||
struct rhs_is_null_t
|
||||
{
|
||||
static constexpr bool _(const T&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct rhs_is_null_t<T, typename std::enable_if<std::is_same<T, null_t>::value, void>::type>
|
||||
{
|
||||
static constexpr bool _(const T& t)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct rhs_is_null_t<T, typename std::enable_if<is_tvin_t<T>::value, void>::type>
|
||||
{
|
||||
static bool _(const T& t)
|
||||
{
|
||||
return t._is_null();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct rhs_is_null_t<T, typename std::enable_if<is_result_field_t<T>::value, void>::type>
|
||||
{
|
||||
static bool _(const T& t)
|
||||
{
|
||||
return t.is_null();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Expression>
|
||||
constexpr bool rhs_is_null(const Expression& e)
|
||||
{
|
||||
return rhs_is_null_t<typename std::decay<Expression>::type::_rhs_t>::_(e._rhs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2014, 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 SQLPP_RHS_IS_TRIVIAL_H
|
||||
#define SQLPP_RHS_IS_TRIVIAL_H
|
||||
|
||||
#include <sqlpp11/tvin.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename T, typename Enable = void>
|
||||
struct rhs_is_trivial_t
|
||||
{
|
||||
static constexpr bool _(const T&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct rhs_is_trivial_t<T, typename std::enable_if<is_wrapped_value_t<T>::value, void>::type>
|
||||
{
|
||||
static bool _(const T& t)
|
||||
{
|
||||
return t._is_trivial();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct rhs_is_trivial_t<T, typename std::enable_if<is_tvin_t<T>::value, void>::type>
|
||||
{
|
||||
static bool _(const T& t)
|
||||
{
|
||||
return t._is_trivial();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct rhs_is_trivial_t<T, typename std::enable_if<is_result_field_t<T>::value, void>::type>
|
||||
{
|
||||
static bool _(const T& t)
|
||||
{
|
||||
if (null_is_trivial_value_t<T>::value)
|
||||
{
|
||||
return t._is_trivial();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (t.is_null())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return t._is_trivial();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Expression>
|
||||
constexpr bool rhs_is_trivial(const Expression& e)
|
||||
{
|
||||
return rhs_is_trivial_t<typename std::decay<Expression>::type::_rhs_t>::_(e._rhs);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
172
include/sqlpp11/rhs_wrap.h
Normal file
172
include/sqlpp11/rhs_wrap.h
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2014, 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 SQLPP_RHS_WRAP_H
|
||||
#define SQLPP_RHS_WRAP_H
|
||||
|
||||
#include <sqlpp11/tvin.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&)
|
||||
{
|
||||
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_tvin_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 (null_is_trivial_value_t<Expr>::value)
|
||||
{
|
||||
return t.is_null();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (t.is_null())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return t._is_trivial();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Expr, typename Enable = void>
|
||||
struct rhs_is_null_t
|
||||
{
|
||||
static constexpr bool _(const Expr&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Expr>
|
||||
struct rhs_is_null_t<Expr, typename std::enable_if<is_tvin_t<Expr>::value, void>::type>
|
||||
{
|
||||
static bool _(const Expr& t)
|
||||
{
|
||||
return t._is_null();
|
||||
}
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<typename Expr, bool TrivialValueIsNull>
|
||||
struct rhs_wrap_t
|
||||
{
|
||||
using _traits = typename Expr::_traits;
|
||||
using _recursive_traits = typename Expr::_recursive_traits;
|
||||
|
||||
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 (TrivialValueIsNull and detail::rhs_is_trivial_t<Expr>::_(_expr))
|
||||
or 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, bool TrivialValueIsNull>
|
||||
struct serializer_t<Context, rhs_wrap_t<Expr, TrivialValueIsNull>>
|
||||
{
|
||||
using T = rhs_wrap_t<Expr, TrivialValueIsNull>;
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -27,6 +27,7 @@
|
||||
#include "MockDb.h"
|
||||
#include "is_regular.h"
|
||||
#include <sqlpp11/insert.h>
|
||||
#include <sqlpp11/functions.h>
|
||||
#include <iostream>
|
||||
|
||||
MockDb db;
|
||||
@ -68,7 +69,12 @@ int main()
|
||||
printer.reset();
|
||||
std::cerr << serialize(i, printer).str() << std::endl;
|
||||
|
||||
|
||||
db(multi_insert);
|
||||
|
||||
db(insert_into(t).set(t.delta = sqlpp::verbatim<sqlpp::integer>("17+4")));
|
||||
db(insert_into(t).set(t.delta = sqlpp::null));
|
||||
db(insert_into(t).set(t.delta = sqlpp::default_value));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ int main()
|
||||
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");
|
||||
|
||||
bool x = sqlpp::rhs_is_null(t.alpha == row.alpha);
|
||||
bool y = sqlpp::rhs_is_trivial(t.alpha == row.alpha);
|
||||
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;
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sqlpp11/update.h>
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
#include "Sample.h"
|
||||
#include "MockDb.h"
|
||||
#include "is_regular.h"
|
||||
@ -64,5 +64,10 @@ int main()
|
||||
|
||||
db(u);
|
||||
|
||||
db(update(t).set(t.delta = sqlpp::verbatim<sqlpp::integer>("17+4")).where(true));
|
||||
db(update(t).set(t.delta = sqlpp::null).where(true));
|
||||
db(update(t).set(t.delta = sqlpp::default_value).where(true));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user