mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Remove tvin
This was a special feature for a project I was working on long ago. It provided implicit behavior for trivial value (0 or "") which were supposed to be interpreted as NULL. They led to `operator==` potentially being serialized as 'IS NULL'. It makes more sense to introduce explicit helpers, e.g. - equal_or_is_null(col, optional) - not_equal_or_is_not_null(col, optional)
This commit is contained in:
parent
35c2b9ec04
commit
db0295a9d0
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <sqlpp11/default_value.h>
|
#include <sqlpp11/default_value.h>
|
||||||
#include <sqlpp11/null.h>
|
#include <sqlpp11/null.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
#include <sqlpp11/rhs_wrap.h>
|
#include <sqlpp11/rhs_wrap.h>
|
||||||
#include <sqlpp11/serialize.h>
|
#include <sqlpp11/serialize.h>
|
||||||
#include <sqlpp11/serializer.h>
|
#include <sqlpp11/serializer.h>
|
||||||
@ -42,11 +41,11 @@ 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<allow_tvin_t<Rhs>>;
|
using _rhs_t = rhs_wrap_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
|
||||||
: not(std::is_same<_rhs_t, null_t>::value or is_tvin_t<_rhs_t>::value),
|
: not std::is_same<_rhs_t, null_t>::value,
|
||||||
"column must not be null");
|
"column must not be null");
|
||||||
|
|
||||||
assignment_t(_lhs_t lhs, _rhs_t rhs) : _lhs(lhs), _rhs(rhs)
|
assignment_t(_lhs_t lhs, _rhs_t rhs) : _lhs(lhs), _rhs(rhs)
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <sqlpp11/data_types/blob/data_type.h>
|
#include <sqlpp11/data_types/blob/data_type.h>
|
||||||
#include <sqlpp11/data_types/blob/wrap_operand.h>
|
#include <sqlpp11/data_types/blob/wrap_operand.h>
|
||||||
#include <sqlpp11/data_types/blob/operand.h>
|
#include <sqlpp11/data_types/blob/operand.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <sqlpp11/data_types/parameter_value.h>
|
#include <sqlpp11/data_types/parameter_value.h>
|
||||||
#include <sqlpp11/data_types/parameter_value_base.h>
|
#include <sqlpp11/data_types/parameter_value_base.h>
|
||||||
#include <sqlpp11/data_types/boolean/data_type.h>
|
#include <sqlpp11/data_types/boolean/data_type.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <sqlpp11/data_types/day_point/data_type.h>
|
#include <sqlpp11/data_types/day_point/data_type.h>
|
||||||
#include <sqlpp11/data_types/day_point/wrap_operand.h>
|
#include <sqlpp11/data_types/day_point/wrap_operand.h>
|
||||||
#include <sqlpp11/data_types/day_point/operand.h>
|
#include <sqlpp11/data_types/day_point/operand.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <sqlpp11/data_types/floating_point/data_type.h>
|
#include <sqlpp11/data_types/floating_point/data_type.h>
|
||||||
#include <sqlpp11/data_types/floating_point/wrap_operand.h>
|
#include <sqlpp11/data_types/floating_point/wrap_operand.h>
|
||||||
#include <sqlpp11/data_types/floating_point/operand.h>
|
#include <sqlpp11/data_types/floating_point/operand.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <sqlpp11/data_types/parameter_value.h>
|
#include <sqlpp11/data_types/parameter_value.h>
|
||||||
#include <sqlpp11/data_types/parameter_value_base.h>
|
#include <sqlpp11/data_types/parameter_value_base.h>
|
||||||
#include <sqlpp11/data_types/integral/data_type.h>
|
#include <sqlpp11/data_types/integral/data_type.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#define SQLPP11_DATA_TYPES_PARAMETER_VALUE_BASE_H
|
#define SQLPP11_DATA_TYPES_PARAMETER_VALUE_BASE_H
|
||||||
|
|
||||||
#include <sqlpp11/data_types/parameter_value.h>
|
#include <sqlpp11/data_types/parameter_value.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -54,21 +53,6 @@ namespace sqlpp
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
parameter_value_base& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
|
|
||||||
{
|
|
||||||
if (t._is_trivial())
|
|
||||||
{
|
|
||||||
_value = {};
|
|
||||||
_is_null = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_value = t._value._t;
|
|
||||||
_is_null = false;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_null()
|
void set_null()
|
||||||
{
|
{
|
||||||
_value = {};
|
_value = {};
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <sqlpp11/data_types/text/data_type.h>
|
#include <sqlpp11/data_types/text/data_type.h>
|
||||||
#include <sqlpp11/data_types/text/wrap_operand.h>
|
#include <sqlpp11/data_types/text/wrap_operand.h>
|
||||||
#include <sqlpp11/data_types/text/operand.h>
|
#include <sqlpp11/data_types/text/operand.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <sqlpp11/data_types/time_of_day/data_type.h>
|
#include <sqlpp11/data_types/time_of_day/data_type.h>
|
||||||
#include <sqlpp11/data_types/time_point/wrap_operand.h>
|
#include <sqlpp11/data_types/time_point/wrap_operand.h>
|
||||||
#include <sqlpp11/data_types/time_point/operand.h>
|
#include <sqlpp11/data_types/time_point/operand.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include <sqlpp11/data_types/time_point/data_type.h>
|
#include <sqlpp11/data_types/time_point/data_type.h>
|
||||||
#include <sqlpp11/data_types/time_point/wrap_operand.h>
|
#include <sqlpp11/data_types/time_point/wrap_operand.h>
|
||||||
#include <sqlpp11/data_types/time_point/operand.h>
|
#include <sqlpp11/data_types/time_point/operand.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <sqlpp11/data_types/parameter_value.h>
|
#include <sqlpp11/data_types/parameter_value.h>
|
||||||
#include <sqlpp11/data_types/parameter_value_base.h>
|
#include <sqlpp11/data_types/parameter_value_base.h>
|
||||||
#include <sqlpp11/data_types/unsigned_integral/data_type.h>
|
#include <sqlpp11/data_types/unsigned_integral/data_type.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#include <sqlpp11/noop.h>
|
#include <sqlpp11/noop.h>
|
||||||
#include <sqlpp11/rhs_wrap.h>
|
#include <sqlpp11/rhs_wrap.h>
|
||||||
#include <sqlpp11/serializer.h>
|
#include <sqlpp11/serializer.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
#include <sqlpp11/wrap_operand.h>
|
#include <sqlpp11/wrap_operand.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
@ -45,7 +44,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<allow_tvin_t<Rhs>>;
|
using _rhs_t = rhs_wrap_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)
|
||||||
@ -72,15 +71,8 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
context << "(";
|
context << "(";
|
||||||
serialize_operand(t._lhs, context);
|
serialize_operand(t._lhs, context);
|
||||||
if (t._rhs._is_null())
|
|
||||||
{
|
|
||||||
context << " IS NULL";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context << "=";
|
context << "=";
|
||||||
serialize_operand(t._rhs, context);
|
serialize_operand(t._rhs, context);
|
||||||
}
|
|
||||||
context << ")";
|
context << ")";
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
@ -93,7 +85,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<allow_tvin_t<Rhs>>;
|
using _rhs_t = rhs_wrap_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)
|
||||||
@ -120,15 +112,8 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
context << "(";
|
context << "(";
|
||||||
serialize_operand(t._lhs, context);
|
serialize_operand(t._lhs, context);
|
||||||
if (t._rhs._is_null())
|
|
||||||
{
|
|
||||||
context << " IS NOT NULL";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context << "<>";
|
context << "<>";
|
||||||
serialize_operand(t._rhs, context);
|
serialize_operand(t._rhs, context);
|
||||||
}
|
|
||||||
context << ")";
|
context << ")";
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <sqlpp11/default_value.h>
|
#include <sqlpp11/default_value.h>
|
||||||
#include <sqlpp11/null.h>
|
#include <sqlpp11/null.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
#include <sqlpp11/value_or_null.h>
|
#include <sqlpp11/value_or_null.h>
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <sqlpp11/serializer.h>
|
#include <sqlpp11/serializer.h>
|
||||||
@ -63,7 +62,7 @@ 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 = tvin_t<_wrapped_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(rhs_wrap_t<_wrapped_value_t> rhs)
|
||||||
@ -71,11 +70,6 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_value_t(rhs_wrap_t<_tvin_t> rhs)
|
|
||||||
: _is_null(rhs._is_null()), _is_default(rhs._is_default()), _value(rhs._expr._value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
insert_value_t(const rhs_wrap_t<null_t>& /*unused*/)
|
insert_value_t(const rhs_wrap_t<null_t>& /*unused*/)
|
||||||
: _is_null(true), _is_default(false), _value{}
|
: _is_null(true), _is_default(false), _value{}
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <sqlpp11/default_value.h>
|
#include <sqlpp11/default_value.h>
|
||||||
#include <sqlpp11/null.h>
|
#include <sqlpp11/null.h>
|
||||||
#include <sqlpp11/tvin.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -53,15 +52,6 @@ namespace sqlpp
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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>
|
template <typename Expr>
|
||||||
struct rhs_is_trivial_t<Expr, typename std::enable_if<is_result_field_t<Expr>::value, void>::type>
|
struct rhs_is_trivial_t<Expr, typename std::enable_if<is_result_field_t<Expr>::value, void>::type>
|
||||||
{
|
{
|
||||||
@ -85,15 +75,6 @@ namespace sqlpp
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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>
|
template <typename Expr>
|
||||||
struct rhs_is_null_t<Expr, typename std::enable_if<is_result_field_t<Expr>::value, void>::type>
|
struct rhs_is_null_t<Expr, typename std::enable_if<is_result_field_t<Expr>::value, void>::type>
|
||||||
{
|
{
|
||||||
|
@ -1,169 +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_TVIN_H
|
|
||||||
#define SQLPP11_TVIN_H
|
|
||||||
|
|
||||||
// TVIN: Trivial value is NULL
|
|
||||||
|
|
||||||
#include <sqlpp11/serialize.h>
|
|
||||||
#include <sqlpp11/serializer.h>
|
|
||||||
#include <sqlpp11/type_traits.h>
|
|
||||||
#include <sqlpp11/wrap_operand.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
template <typename Operand>
|
|
||||||
struct tvin_arg_t
|
|
||||||
{
|
|
||||||
using _traits = make_traits<value_type_of<Operand>, tag::is_expression>;
|
|
||||||
using _nodes = detail::type_vector<Operand>;
|
|
||||||
|
|
||||||
using _operand_t = Operand;
|
|
||||||
|
|
||||||
tvin_arg_t(_operand_t operand) : _value(operand)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
tvin_arg_t(const tvin_arg_t&) = default;
|
|
||||||
tvin_arg_t(tvin_arg_t&&) = default;
|
|
||||||
tvin_arg_t& operator=(const tvin_arg_t&) = default;
|
|
||||||
tvin_arg_t& operator=(tvin_arg_t&&) = default;
|
|
||||||
~tvin_arg_t() = default;
|
|
||||||
|
|
||||||
_operand_t _value;
|
|
||||||
};
|
|
||||||
|
|
||||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_tvin_with_correct_operator_t,
|
|
||||||
"tvin may only be used with operators =, == and !=");
|
|
||||||
|
|
||||||
template <typename Context, typename Operand>
|
|
||||||
struct serializer_t<Context, tvin_arg_t<Operand>>
|
|
||||||
{
|
|
||||||
using _serialize_check = assert_tvin_with_correct_operator_t;
|
|
||||||
using T = tvin_arg_t<Operand>;
|
|
||||||
|
|
||||||
static Context& _(const T& /*unused*/, Context& /*unused*/)
|
|
||||||
{
|
|
||||||
_serialize_check{};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct tvin_t;
|
|
||||||
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template <typename T>
|
|
||||||
struct allow_tvin_impl
|
|
||||||
{
|
|
||||||
using type = T;
|
|
||||||
};
|
|
||||||
template <typename T>
|
|
||||||
struct allow_tvin_impl<tvin_arg_t<T>>
|
|
||||||
{
|
|
||||||
using type = tvin_t<T>;
|
|
||||||
};
|
|
||||||
} // namespace detail
|
|
||||||
template <typename T>
|
|
||||||
using allow_tvin_t = typename detail::allow_tvin_impl<T>::type;
|
|
||||||
|
|
||||||
template <typename Operand>
|
|
||||||
struct tvin_t
|
|
||||||
{
|
|
||||||
using _traits = make_traits<value_type_of<Operand>, tag::is_expression>;
|
|
||||||
using _nodes = detail::type_vector<Operand>;
|
|
||||||
|
|
||||||
using _operand_t = Operand;
|
|
||||||
|
|
||||||
tvin_t(tvin_arg_t<Operand> arg) : _value(arg._value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
tvin_t(const tvin_t&) = default;
|
|
||||||
tvin_t(tvin_t&&) = default;
|
|
||||||
tvin_t& operator=(const tvin_t&) = default;
|
|
||||||
tvin_t& operator=(tvin_t&&) = default;
|
|
||||||
~tvin_t() = default;
|
|
||||||
|
|
||||||
bool _is_trivial() const
|
|
||||||
{
|
|
||||||
return _value._is_trivial();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _is_null() const
|
|
||||||
{
|
|
||||||
return _value._is_trivial();
|
|
||||||
}
|
|
||||||
|
|
||||||
_operand_t _value;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template <typename T>
|
|
||||||
struct is_tvin_impl
|
|
||||||
{
|
|
||||||
using type = std::false_type;
|
|
||||||
};
|
|
||||||
template <typename T>
|
|
||||||
struct is_tvin_impl<tvin_t<T>>
|
|
||||||
{
|
|
||||||
using type = std::true_type;
|
|
||||||
};
|
|
||||||
} // namespace detail
|
|
||||||
template <typename T>
|
|
||||||
using is_tvin_t = typename detail::is_tvin_impl<T>::type;
|
|
||||||
|
|
||||||
template <typename Context, typename Operand>
|
|
||||||
struct serializer_t<Context, tvin_t<Operand>>
|
|
||||||
{
|
|
||||||
using _serialize_check = serialize_check_of<Context, Operand>;
|
|
||||||
using T = tvin_t<Operand>;
|
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
|
||||||
{
|
|
||||||
if (t._is_trivial())
|
|
||||||
{
|
|
||||||
context << "NULL";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
serialize(t._value, context);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Operand>
|
|
||||||
auto tvin(Operand operand) -> tvin_arg_t<wrap_operand_t<Operand>>
|
|
||||||
{
|
|
||||||
using _operand_t = wrap_operand_t<Operand>;
|
|
||||||
static_assert(not std::is_same<_operand_t, Operand>::value or is_result_field_t<Operand>::value,
|
|
||||||
"tvin() used with invalid type (only string and primitive types allowed)");
|
|
||||||
return {{operand}};
|
|
||||||
}
|
|
||||||
} // namespace sqlpp
|
|
||||||
|
|
||||||
#endif
|
|
@ -45,7 +45,7 @@ int Insert(int, char* [])
|
|||||||
compare(__LINE__, insert_into(bar).default_values(), "INSERT INTO tab_bar DEFAULT VALUES");
|
compare(__LINE__, insert_into(bar).default_values(), "INSERT INTO tab_bar DEFAULT VALUES");
|
||||||
compare(__LINE__, insert_into(bar).set(bar.beta = "cheesecake", bar.gamma = true),
|
compare(__LINE__, insert_into(bar).set(bar.beta = "cheesecake", bar.gamma = true),
|
||||||
"INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")");
|
"INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")");
|
||||||
compare(__LINE__, insert_into(bar).set(bar.beta = ::sqlpp::tvin(""), bar.gamma = true),
|
compare(__LINE__, insert_into(bar).set(bar.beta = ::sqlpp::null, bar.gamma = true),
|
||||||
"INSERT INTO tab_bar (beta,gamma) VALUES(NULL," + getTrue() + ")");
|
"INSERT INTO tab_bar (beta,gamma) VALUES(NULL," + getTrue() + ")");
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
// string_view argument
|
// string_view argument
|
||||||
|
@ -63,7 +63,7 @@ int Where(int, char*[])
|
|||||||
// Sometimes
|
// Sometimes
|
||||||
compare(__LINE__, where(bar.gamma), " WHERE tab_bar.gamma");
|
compare(__LINE__, where(bar.gamma), " WHERE tab_bar.gamma");
|
||||||
compare(__LINE__, where(bar.gamma == false), " WHERE (tab_bar.gamma=" + getFalse() + ")");
|
compare(__LINE__, where(bar.gamma == false), " WHERE (tab_bar.gamma=" + getFalse() + ")");
|
||||||
compare(__LINE__, where(bar.gamma == ::sqlpp::tvin(false)), " WHERE (tab_bar.gamma IS NULL)");
|
compare(__LINE__, where(bar.beta.is_null()), " WHERE tab_bar.beta IS NULL");
|
||||||
compare(__LINE__, where(bar.beta == "SQL"), " WHERE (tab_bar.beta='SQL')");
|
compare(__LINE__, where(bar.beta == "SQL"), " WHERE (tab_bar.beta='SQL')");
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
// string_view argument
|
// string_view argument
|
||||||
|
@ -436,30 +436,5 @@ int Function(int, char* [])
|
|||||||
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
|
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
|
||||||
}
|
}
|
||||||
|
|
||||||
// test tvin
|
|
||||||
{
|
|
||||||
static_assert(std::is_same<decltype(sqlpp::tvin(1)), sqlpp::tvin_arg_t<sqlpp::integral_operand>>::value,
|
|
||||||
"integral values are accepted and wrapped");
|
|
||||||
static_assert(std::is_same<decltype(sqlpp::tvin(false)), sqlpp::tvin_arg_t<sqlpp::boolean_operand>>::value,
|
|
||||||
"bool values are accepted and wrapped");
|
|
||||||
static_assert(std::is_same<decltype(sqlpp::tvin(0.17)), sqlpp::tvin_arg_t<sqlpp::floating_point_operand>>::value,
|
|
||||||
"float values are accepted and wrapped");
|
|
||||||
static_assert(std::is_same<decltype(sqlpp::tvin("test")), sqlpp::tvin_arg_t<sqlpp::text_operand>>::value,
|
|
||||||
"text values are accepted and wrapped");
|
|
||||||
|
|
||||||
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
|
|
||||||
{
|
|
||||||
static_assert(std::is_same<decltype(sqlpp::tvin(row.alpha)),
|
|
||||||
sqlpp::tvin_arg_t<typename std::remove_const<decltype(row.alpha)>::type>>::value,
|
|
||||||
"result fields are accepted and not wrapped");
|
|
||||||
static_assert(std::is_same<decltype(sqlpp::tvin(row.beta)),
|
|
||||||
sqlpp::tvin_arg_t<typename std::remove_const<decltype(row.beta)>::type>>::value,
|
|
||||||
"result fields are accepted and not wrapped");
|
|
||||||
static_assert(std::is_same<decltype(sqlpp::tvin(row.gamma)),
|
|
||||||
sqlpp::tvin_arg_t<typename std::remove_const<decltype(row.gamma)>::type>>::value,
|
|
||||||
"result fields are accepted and not wrapped");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -87,12 +87,12 @@ int Insert(int, char*[])
|
|||||||
|
|
||||||
db(multi_insert);
|
db(multi_insert);
|
||||||
|
|
||||||
auto values = [&t]() { return std::make_tuple(t.gamma = true, t.delta = sqlpp::tvin(0)); };
|
auto values = [&t]() { return std::make_tuple(t.gamma = true, t.beta = sqlpp::null); };
|
||||||
|
|
||||||
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::verbatim<sqlpp::integer>("17+4")));
|
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::verbatim<sqlpp::integer>("17+4")));
|
||||||
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::null));
|
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::null));
|
||||||
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::default_value));
|
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::default_value));
|
||||||
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::tvin(0)));
|
db(insert_into(t).set(t.gamma = true, t.delta = 0));
|
||||||
db(insert_into(t).set(values()));
|
db(insert_into(t).set(values()));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -43,9 +43,6 @@ int Interpret(int, char* [])
|
|||||||
auto i = insert_into(t).columns(t.gamma, t.beta);
|
auto i = insert_into(t).columns(t.gamma, t.beta);
|
||||||
i.values.add(t.gamma = true, t.beta = "cheesecake");
|
i.values.add(t.gamma = true, t.beta = "cheesecake");
|
||||||
serialize(i, printer).str();
|
serialize(i, printer).str();
|
||||||
i.values.add(t.gamma = false, t.beta = sqlpp::tvin("coffee"));
|
|
||||||
i.values.add(t.gamma = false, t.beta = sqlpp::tvin(std::string()));
|
|
||||||
serialize(i, printer).str();
|
|
||||||
i.values.add(t.gamma = sqlpp::default_value, t.beta = sqlpp::null);
|
i.values.add(t.gamma = sqlpp::default_value, t.beta = sqlpp::null);
|
||||||
serialize(i, printer).str();
|
serialize(i, printer).str();
|
||||||
}
|
}
|
||||||
@ -57,13 +54,9 @@ int Interpret(int, char* [])
|
|||||||
serialize(+t.alpha, printer).str();
|
serialize(+t.alpha, printer).str();
|
||||||
serialize(-(t.alpha + 7), printer).str();
|
serialize(-(t.alpha + 7), printer).str();
|
||||||
serialize(t.alpha = 0, printer).str();
|
serialize(t.alpha = 0, printer).str();
|
||||||
serialize(t.alpha = sqlpp::tvin(0), printer).str();
|
|
||||||
serialize(t.alpha == 0, printer).str();
|
serialize(t.alpha == 0, printer).str();
|
||||||
serialize(t.alpha == sqlpp::tvin(0), printer).str();
|
|
||||||
serialize(t.alpha != 0, printer).str();
|
serialize(t.alpha != 0, printer).str();
|
||||||
serialize(t.gamma != sqlpp::tvin(false), printer).str();
|
|
||||||
serialize(t.alpha == 7, printer).str();
|
serialize(t.alpha == 7, printer).str();
|
||||||
serialize(t.delta = sqlpp::tvin(0), printer).str();
|
|
||||||
serialize(t.beta + "kaesekuchen", printer).str();
|
serialize(t.beta + "kaesekuchen", printer).str();
|
||||||
|
|
||||||
serialize(sqlpp::select(), printer).str();
|
serialize(sqlpp::select(), printer).str();
|
||||||
@ -103,8 +96,6 @@ int Interpret(int, char* [])
|
|||||||
serialize(insert_into(t), printer).str();
|
serialize(insert_into(t), printer).str();
|
||||||
serialize(insert_into(f).default_values(), printer).str();
|
serialize(insert_into(f).default_values(), printer).str();
|
||||||
serialize(insert_into(t).set(t.gamma = true), printer).str();
|
serialize(insert_into(t).set(t.gamma = true), printer).str();
|
||||||
// serialize(insert_into(t).set(t.gamma = sqlpp::tvin(false)), printer).str(); cannot test this since gamma cannot be
|
|
||||||
// null and a static assert is thrown
|
|
||||||
|
|
||||||
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();
|
||||||
@ -113,8 +104,6 @@ int Interpret(int, char* [])
|
|||||||
|
|
||||||
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();
|
||||||
serialize(remove_from(t).where(t.alpha == sqlpp::tvin(0)), printer).str();
|
|
||||||
serialize(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).str();
|
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
serialize(sqlpp::value(7), printer).str();
|
serialize(sqlpp::value(7), printer).str();
|
||||||
|
@ -108,7 +108,6 @@ int Prepared(int, char* [])
|
|||||||
t.gamma != parameter(t.gamma));
|
t.gamma != parameter(t.gamma));
|
||||||
auto p = db.prepare(s);
|
auto p = db.prepare(s);
|
||||||
p.params.alpha = 7;
|
p.params.alpha = 7;
|
||||||
p.params.alpha = sqlpp::tvin(0);
|
|
||||||
using S = decltype(s);
|
using S = decltype(s);
|
||||||
using P = sqlpp::make_parameter_list_t<S>;
|
using P = sqlpp::make_parameter_list_t<S>;
|
||||||
P npl;
|
P npl;
|
||||||
|
@ -134,7 +134,7 @@ int Select(int, char*[])
|
|||||||
std::cout << row.count << std::endl;
|
std::cout << row.count << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& row : db(select(count(t.alpha), avg(t.alpha)).from(t).where(t.alpha == sqlpp::tvin(0))))
|
for (const auto& row : db(select(count(t.alpha), avg(t.alpha)).from(t).where(t.alpha == 0)))
|
||||||
{
|
{
|
||||||
std::cout << row.count << std::endl;
|
std::cout << row.count << std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user