0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Started to use parameter_value_base to simplify parameter_value code

This commit is contained in:
rbock 2015-10-30 23:24:42 +01:00
parent 37b7966ab2
commit f48e807ce5
11 changed files with 121 additions and 135 deletions

View File

@ -29,7 +29,7 @@
#include <sqlpp11/char_sequence.h> #include <sqlpp11/char_sequence.h>
#include <sqlpp11/select_flags.h> #include <sqlpp11/select_flags.h>
#include <sqlpp11/data_types/integral.h> #include <sqlpp11/data_types/integral/data_type.h>
namespace sqlpp namespace sqlpp
{ {

View File

@ -28,12 +28,12 @@
#define SQLPP_BOOLEAN_H #define SQLPP_BOOLEAN_H
#include <sqlpp11/data_types/boolean/data_type.h> #include <sqlpp11/data_types/boolean/data_type.h>
#include <sqlpp11/data_types/boolean/operand.h>
#include <sqlpp11/data_types/boolean/wrap_operand.h>
#include <sqlpp11/data_types/boolean/expression_operators.h> #include <sqlpp11/data_types/boolean/expression_operators.h>
#include <sqlpp11/data_types/boolean/column_operators.h> #include <sqlpp11/data_types/boolean/column_operators.h>
#include <sqlpp11/data_types/boolean/parameter_type.h> #include <sqlpp11/data_types/boolean/parameter_type.h>
#include <sqlpp11/data_types/boolean/result_field.h> #include <sqlpp11/data_types/boolean/result_field.h>
#include <sqlpp11/data_types/boolean/operand.h>
#include <sqlpp11/data_types/boolean/wrap_operand.h>
#include <sqlpp11/data_types/boolean/serialize.h> #include <sqlpp11/data_types/boolean/serialize.h>
#endif #endif

View File

@ -28,80 +28,24 @@
#define SQLPP_BOOLEAN_PARAMETER_TYPE_H #define SQLPP_BOOLEAN_PARAMETER_TYPE_H
#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/boolean/data_type.h> #include <sqlpp11/data_types/boolean/data_type.h>
#include <sqlpp11/data_types/boolean/wrap_operand.h>
#include <sqlpp11/data_types/boolean/operand.h>
#include <sqlpp11/tvin.h> #include <sqlpp11/tvin.h>
namespace sqlpp namespace sqlpp
{ {
template <> template <>
struct parameter_value_t<boolean> struct parameter_value_t<boolean> : public base_parameter_value<boolean>
{ {
using _value_type = boolean; // FIXME using base = base_parameter_value<boolean>;
using _cpp_value_type = typename _value_type::_cpp_value_type; using base::base;
using base::operator=;
parameter_value_t() : _value(false), _is_null(true)
{
}
parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false)
{
}
parameter_value_t& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
parameter_value_t& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = false;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
parameter_value_t& operator=(const std::nullptr_t&)
{
_value = false;
_is_null = true;
return *this;
}
bool is_null() const
{
return _is_null;
}
_cpp_value_type value() const
{
return _value;
}
operator _cpp_value_type() const
{
return value();
}
template <typename Target> template <typename Target>
void _bind(Target& target, size_t index) const void _bind(Target& target, size_t index) const
{ {
target._bind_boolean_parameter(index, &_value, _is_null); target._bind_boolean_parameter(index, &_value, _is_null);
} }
private:
signed char _value;
bool _is_null;
}; };
} }

View File

@ -28,12 +28,12 @@
#define SQLPP_DAY_POINT_H #define SQLPP_DAY_POINT_H
#include <sqlpp11/data_types/day_point/data_type.h> #include <sqlpp11/data_types/day_point/data_type.h>
#include <sqlpp11/data_types/day_point/operand.h>
#include <sqlpp11/data_types/day_point/wrap_operand.h>
#include <sqlpp11/data_types/day_point/expression_operators.h> #include <sqlpp11/data_types/day_point/expression_operators.h>
#include <sqlpp11/data_types/day_point/column_operators.h> #include <sqlpp11/data_types/day_point/column_operators.h>
#include <sqlpp11/data_types/day_point/parameter_type.h> #include <sqlpp11/data_types/day_point/parameter_type.h>
#include <sqlpp11/data_types/day_point/result_field.h> #include <sqlpp11/data_types/day_point/result_field.h>
#include <sqlpp11/data_types/day_point/operand.h>
#include <sqlpp11/data_types/day_point/wrap_operand.h>
#include <sqlpp11/data_types/day_point/serialize.h> #include <sqlpp11/data_types/day_point/serialize.h>
#endif #endif

View File

@ -28,12 +28,12 @@
#define SQLPP_FLOATING_POINT_H #define SQLPP_FLOATING_POINT_H
#include <sqlpp11/data_types/floating_point/data_type.h> #include <sqlpp11/data_types/floating_point/data_type.h>
#include <sqlpp11/data_types/floating_point/operand.h>
#include <sqlpp11/data_types/floating_point/wrap_operand.h>
#include <sqlpp11/data_types/floating_point/expression_operators.h> #include <sqlpp11/data_types/floating_point/expression_operators.h>
#include <sqlpp11/data_types/floating_point/column_operators.h> #include <sqlpp11/data_types/floating_point/column_operators.h>
#include <sqlpp11/data_types/floating_point/parameter_type.h> #include <sqlpp11/data_types/floating_point/parameter_type.h>
#include <sqlpp11/data_types/floating_point/result_field.h> #include <sqlpp11/data_types/floating_point/result_field.h>
#include <sqlpp11/data_types/floating_point/operand.h>
#include <sqlpp11/data_types/floating_point/wrap_operand.h>
#include <sqlpp11/data_types/floating_point/serialize.h> #include <sqlpp11/data_types/floating_point/serialize.h>
#endif #endif

View File

@ -28,12 +28,12 @@
#define SQLPP_INTEGRAL_H #define SQLPP_INTEGRAL_H
#include <sqlpp11/data_types/integral/data_type.h> #include <sqlpp11/data_types/integral/data_type.h>
#include <sqlpp11/data_types/integral/operand.h>
#include <sqlpp11/data_types/integral/wrap_operand.h>
#include <sqlpp11/data_types/integral/expression_operators.h> #include <sqlpp11/data_types/integral/expression_operators.h>
#include <sqlpp11/data_types/integral/column_operators.h> #include <sqlpp11/data_types/integral/column_operators.h>
#include <sqlpp11/data_types/integral/parameter_type.h> #include <sqlpp11/data_types/integral/parameter_type.h>
#include <sqlpp11/data_types/integral/result_field.h> #include <sqlpp11/data_types/integral/result_field.h>
#include <sqlpp11/data_types/integral/operand.h>
#include <sqlpp11/data_types/integral/wrap_operand.h>
#include <sqlpp11/data_types/integral/serialize.h> #include <sqlpp11/data_types/integral/serialize.h>
#endif #endif

View File

@ -28,79 +28,24 @@
#define SQLPP_INTEGRAL_PARAMETER_TYPE_H #define SQLPP_INTEGRAL_PARAMETER_TYPE_H
#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/integral/data_type.h> #include <sqlpp11/data_types/integral/data_type.h>
#include <sqlpp11/data_types/integral/wrap_operand.h>
#include <sqlpp11/data_types/integral/operand.h>
#include <sqlpp11/tvin.h> #include <sqlpp11/tvin.h>
namespace sqlpp namespace sqlpp
{ {
template <> template <>
struct parameter_value_t<integral> struct parameter_value_t<integral> : public base_parameter_value<integral>
{ {
using _value_type = integral; using base = base_parameter_value<integral>;
using _cpp_value_type = typename _value_type::_cpp_value_type; using base::base;
using base::operator=;
parameter_value_t() : _value(0), _is_null(true)
{
}
explicit parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false)
{
}
parameter_value_t& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
parameter_value_t& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = 0;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
void set_null()
{
_value = 0;
_is_null = true;
}
bool is_null() const
{
return _is_null;
}
const _cpp_value_type& value() const
{
return _value;
}
operator _cpp_value_type() const
{
return _value;
}
template <typename Target> template <typename Target>
void _bind(Target& target, size_t index) const void _bind(Target& target, size_t index) const
{ {
target._bind_integral_parameter(index, &_value, _is_null); target._bind_integral_parameter(index, &_value, _is_null);
} }
private:
_cpp_value_type _value;
bool _is_null;
}; };
} }
#endif #endif

View File

@ -35,7 +35,7 @@ namespace sqlpp
struct integral_operand; struct integral_operand;
template <typename T> template <typename T>
struct wrap_operand<T, typename std::enable_if<std::is_integral<T>::value>::type> struct wrap_operand<T, typename std::enable_if<std::is_integral<T>::value and not std::is_same<bool, T>::value>::type>
{ {
using type = integral_operand; using type = integral_operand;
}; };

View File

@ -0,0 +1,97 @@
/*
* 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 SQLPP_PARAMETER_VALUE_BASE_H
#define SQLPP_PARAMETER_VALUE_BASE_H
#include <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/tvin.h>
namespace sqlpp
{
template <typename DataType>
struct base_parameter_value
{
using _value_type = DataType;
using _cpp_value_type = typename _value_type::_cpp_value_type;
base_parameter_value() : _value(0), _is_null(true)
{
}
explicit base_parameter_value(const _cpp_value_type& val) : _value(val), _is_null(false)
{
}
base_parameter_value& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
base_parameter_value& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = 0;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
void set_null()
{
_value = 0;
_is_null = true;
}
bool is_null() const
{
return _is_null;
}
const _cpp_value_type& value() const
{
return _value;
}
operator _cpp_value_type() const
{
return _value;
}
protected:
_cpp_value_type _value;
bool _is_null;
};
}
#endif

View File

@ -28,12 +28,12 @@
#define SQLPP_TEXT_H #define SQLPP_TEXT_H
#include <sqlpp11/data_types/text/data_type.h> #include <sqlpp11/data_types/text/data_type.h>
#include <sqlpp11/data_types/text/operand.h>
#include <sqlpp11/data_types/text/wrap_operand.h>
#include <sqlpp11/data_types/text/expression_operators.h> #include <sqlpp11/data_types/text/expression_operators.h>
#include <sqlpp11/data_types/text/column_operators.h> #include <sqlpp11/data_types/text/column_operators.h>
#include <sqlpp11/data_types/text/parameter_type.h> #include <sqlpp11/data_types/text/parameter_type.h>
#include <sqlpp11/data_types/text/result_field.h> #include <sqlpp11/data_types/text/result_field.h>
#include <sqlpp11/data_types/text/operand.h>
#include <sqlpp11/data_types/text/wrap_operand.h>
#include <sqlpp11/data_types/text/serialize.h> #include <sqlpp11/data_types/text/serialize.h>
// text specific functions // text specific functions

View File

@ -28,12 +28,12 @@
#define SQLPP_TIME_POINT_H #define SQLPP_TIME_POINT_H
#include <sqlpp11/data_types/time_point/data_type.h> #include <sqlpp11/data_types/time_point/data_type.h>
#include <sqlpp11/data_types/time_point/operand.h>
#include <sqlpp11/data_types/time_point/wrap_operand.h>
#include <sqlpp11/data_types/time_point/expression_operators.h> #include <sqlpp11/data_types/time_point/expression_operators.h>
#include <sqlpp11/data_types/time_point/column_operators.h> #include <sqlpp11/data_types/time_point/column_operators.h>
#include <sqlpp11/data_types/time_point/parameter_type.h> #include <sqlpp11/data_types/time_point/parameter_type.h>
#include <sqlpp11/data_types/time_point/result_field.h> #include <sqlpp11/data_types/time_point/result_field.h>
#include <sqlpp11/data_types/time_point/operand.h>
#include <sqlpp11/data_types/time_point/wrap_operand.h>
#include <sqlpp11/data_types/time_point/serialize.h> #include <sqlpp11/data_types/time_point/serialize.h>
#endif #endif