mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Moved shared result field code into separate file
This commit is contained in:
parent
a62c660ad5
commit
828106acbd
@ -32,6 +32,7 @@
|
|||||||
#include <sqlpp11/basic_expression_operators.h>
|
#include <sqlpp11/basic_expression_operators.h>
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <sqlpp11/exception.h>
|
#include <sqlpp11/exception.h>
|
||||||
|
#include <sqlpp11/result_field_methods.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -97,46 +98,8 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
template<typename Db, typename FieldSpec>
|
||||||
struct _result_field_t;
|
struct _result_field_t: public result_field_methods_t<_result_field_t<Db, FieldSpec>>
|
||||||
|
|
||||||
// I am SO waiting for concepts lite!
|
|
||||||
template<typename Field, typename Enable = void>
|
|
||||||
struct field_methods_t
|
|
||||||
{
|
{
|
||||||
static constexpr bool _null_is_trivial = true;
|
|
||||||
operator _cpp_value_type() const { return static_cast<const Field&>(*this).value(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
|
||||||
struct field_methods_t<
|
|
||||||
_result_field_t<Db, FieldSpec>,
|
|
||||||
typename std::enable_if<enforce_null_result_treatment_t<Db>::value
|
|
||||||
and column_spec_can_be_null_t<FieldSpec>::value
|
|
||||||
and not null_is_trivial_value_t<FieldSpec>::value>::type>
|
|
||||||
{
|
|
||||||
static constexpr bool _null_is_trivial = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
|
||||||
struct _result_field_t: public field_methods_t<_result_field_t<Db, FieldSpec>>
|
|
||||||
{
|
|
||||||
using _field_methods_t = field_methods_t<_result_field_t<Db, FieldSpec>>;
|
|
||||||
|
|
||||||
using _traits = make_traits<integral,
|
|
||||||
tag::is_result_field,
|
|
||||||
tag::is_expression,
|
|
||||||
tag_if<tag::null_is_trivial_value, _field_methods_t::_null_is_trivial>>;
|
|
||||||
|
|
||||||
struct _recursive_traits
|
|
||||||
{
|
|
||||||
using _parameters = std::tuple<>;
|
|
||||||
using _provided_tables = detail::type_set<>;
|
|
||||||
using _provided_outer_tables = detail::type_set<>;
|
|
||||||
using _required_tables = detail::type_set<>;
|
|
||||||
using _extra_tables = detail::type_set<>;
|
|
||||||
using _can_be_null = column_spec_can_be_null_t<FieldSpec>;
|
|
||||||
};
|
|
||||||
|
|
||||||
_result_field_t():
|
_result_field_t():
|
||||||
_is_valid(false),
|
_is_valid(false),
|
||||||
_is_null(true),
|
_is_null(true),
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <sqlpp11/basic_expression_operators.h>
|
#include <sqlpp11/basic_expression_operators.h>
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <sqlpp11/exception.h>
|
#include <sqlpp11/exception.h>
|
||||||
|
#include <sqlpp11/result_field_methods.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -96,46 +97,8 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
template<typename Db, typename FieldSpec>
|
||||||
struct _result_field_t;
|
struct _result_field_t: public result_field_methods_t<_result_field_t<Db, FieldSpec>>
|
||||||
|
|
||||||
// I am SO waiting for concepts lite!
|
|
||||||
template<typename Field, typename Enable = void>
|
|
||||||
struct field_methods_t
|
|
||||||
{
|
{
|
||||||
static constexpr bool _null_is_trivial = true;
|
|
||||||
operator _cpp_value_type() const { return static_cast<const Field&>(*this).value(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
|
||||||
struct field_methods_t<
|
|
||||||
_result_field_t<Db, FieldSpec>,
|
|
||||||
typename std::enable_if<enforce_null_result_treatment_t<Db>::value
|
|
||||||
and column_spec_can_be_null_t<FieldSpec>::value
|
|
||||||
and not null_is_trivial_value_t<FieldSpec>::value>::type>
|
|
||||||
{
|
|
||||||
static constexpr bool _null_is_trivial = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
|
||||||
struct _result_field_t: public field_methods_t<_result_field_t<Db, FieldSpec>>
|
|
||||||
{
|
|
||||||
using _field_methods_t = field_methods_t<_result_field_t<Db, FieldSpec>>;
|
|
||||||
|
|
||||||
using _traits = make_traits<integral,
|
|
||||||
tag::is_result_field,
|
|
||||||
tag::is_expression,
|
|
||||||
tag_if<tag::null_is_trivial_value, _field_methods_t::_null_is_trivial>>;
|
|
||||||
|
|
||||||
struct _recursive_traits
|
|
||||||
{
|
|
||||||
using _parameters = std::tuple<>;
|
|
||||||
using _provided_tables = detail::type_set<>;
|
|
||||||
using _provided_outer_tables = detail::type_set<>;
|
|
||||||
using _required_tables = detail::type_set<>;
|
|
||||||
using _extra_tables = detail::type_set<>;
|
|
||||||
using _can_be_null = column_spec_can_be_null_t<FieldSpec>;
|
|
||||||
};
|
|
||||||
|
|
||||||
_result_field_t():
|
_result_field_t():
|
||||||
_is_valid(false),
|
_is_valid(false),
|
||||||
_is_null(true),
|
_is_null(true),
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <sqlpp11/exception.h>
|
#include <sqlpp11/exception.h>
|
||||||
#include <sqlpp11/value_type.h>
|
#include <sqlpp11/value_type.h>
|
||||||
#include <sqlpp11/assignment.h>
|
#include <sqlpp11/assignment.h>
|
||||||
|
#include <sqlpp11/result_field_methods.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -97,46 +98,8 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
template<typename Db, typename FieldSpec>
|
||||||
struct _result_field_t;
|
struct _result_field_t: public result_field_methods_t<_result_field_t<Db, FieldSpec>>
|
||||||
|
|
||||||
// I am SO waiting for concepts lite!
|
|
||||||
template<typename Field, typename Enable = void>
|
|
||||||
struct field_methods_t
|
|
||||||
{
|
{
|
||||||
static constexpr bool _null_is_trivial = true;
|
|
||||||
operator _cpp_value_type() const { return static_cast<const Field&>(*this).value(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
|
||||||
struct field_methods_t<
|
|
||||||
_result_field_t<Db, FieldSpec>,
|
|
||||||
typename std::enable_if<enforce_null_result_treatment_t<Db>::value
|
|
||||||
and column_spec_can_be_null_t<FieldSpec>::value
|
|
||||||
and not null_is_trivial_value_t<FieldSpec>::value>::type>
|
|
||||||
{
|
|
||||||
static constexpr bool _null_is_trivial = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
|
||||||
struct _result_field_t: public field_methods_t<_result_field_t<Db, FieldSpec>>
|
|
||||||
{
|
|
||||||
using _field_methods_t = field_methods_t<_result_field_t<Db, FieldSpec>>;
|
|
||||||
|
|
||||||
using _traits = make_traits<integral,
|
|
||||||
tag::is_result_field,
|
|
||||||
tag::is_expression,
|
|
||||||
tag_if<tag::null_is_trivial_value, _field_methods_t::_null_is_trivial>>;
|
|
||||||
|
|
||||||
struct _recursive_traits
|
|
||||||
{
|
|
||||||
using _parameters = std::tuple<>;
|
|
||||||
using _provided_tables = detail::type_set<>;
|
|
||||||
using _provided_outer_tables = detail::type_set<>;
|
|
||||||
using _required_tables = detail::type_set<>;
|
|
||||||
using _extra_tables = detail::type_set<>;
|
|
||||||
using _can_be_null = column_spec_can_be_null_t<FieldSpec>;
|
|
||||||
};
|
|
||||||
|
|
||||||
_result_field_t():
|
_result_field_t():
|
||||||
_is_valid(false),
|
_is_valid(false),
|
||||||
_is_null(true),
|
_is_null(true),
|
||||||
|
97
include/sqlpp11/result_field_methods.h
Normal file
97
include/sqlpp11/result_field_methods.h
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* 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_RESULT_FIELD_METHODS_H
|
||||||
|
#define SQLPP_RESULT_FIELD_METHODS_H
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<typename Field>
|
||||||
|
struct get_field_spec_impl
|
||||||
|
{
|
||||||
|
static_assert(wrong_t<Field>::value, "Invalid argument for get_field_spec");
|
||||||
|
};
|
||||||
|
|
||||||
|
template<template<typename, typename> class Field, typename Db, typename FieldSpec>
|
||||||
|
struct get_field_spec_impl<Field<Db, FieldSpec>>
|
||||||
|
{
|
||||||
|
using type = FieldSpec;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Field>
|
||||||
|
using get_field_spec_t = typename get_field_spec_impl<Field>::type;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Field, typename Enable = void>
|
||||||
|
struct result_field_methods_base_t
|
||||||
|
{
|
||||||
|
using _field_spec_t = detail::get_field_spec_t<Field>;
|
||||||
|
static constexpr bool _null_is_trivial = true;
|
||||||
|
operator cpp_value_type_of<_field_spec_t>() const { return static_cast<const Field&>(*this).value(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<template<typename, typename> class Field, typename Db, typename FieldSpec>
|
||||||
|
struct result_field_methods_base_t<
|
||||||
|
Field<Db, FieldSpec>,
|
||||||
|
typename std::enable_if<enforce_null_result_treatment_t<Db>::value
|
||||||
|
and column_spec_can_be_null_t<FieldSpec>::value
|
||||||
|
and not null_is_trivial_value_t<FieldSpec>::value>::type>
|
||||||
|
{
|
||||||
|
using _field_spec_t = FieldSpec;
|
||||||
|
static constexpr bool _null_is_trivial = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Field>
|
||||||
|
struct result_field_methods_t: public result_field_methods_base_t<Field>
|
||||||
|
{
|
||||||
|
using _base_t = result_field_methods_base_t<Field>;
|
||||||
|
using _field_spec_t = typename _base_t::_field_spec_t;
|
||||||
|
|
||||||
|
using _traits = make_traits<value_type_of<_field_spec_t>,
|
||||||
|
tag::is_result_field,
|
||||||
|
tag::is_expression,
|
||||||
|
tag_if<tag::null_is_trivial_value, _base_t::_null_is_trivial>>;
|
||||||
|
|
||||||
|
struct _recursive_traits
|
||||||
|
{
|
||||||
|
using _parameters = std::tuple<>;
|
||||||
|
using _provided_tables = detail::type_set<>;
|
||||||
|
using _provided_outer_tables = detail::type_set<>;
|
||||||
|
using _required_tables = detail::type_set<>;
|
||||||
|
using _extra_tables = detail::type_set<>;
|
||||||
|
using _can_be_null = column_spec_can_be_null_t<_field_spec_t>;
|
||||||
|
};
|
||||||
|
|
||||||
|
using _name_t = typename _field_spec_t::_name_t;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
@ -32,6 +32,7 @@
|
|||||||
#include <sqlpp11/exception.h>
|
#include <sqlpp11/exception.h>
|
||||||
#include <sqlpp11/concat.h>
|
#include <sqlpp11/concat.h>
|
||||||
#include <sqlpp11/like.h>
|
#include <sqlpp11/like.h>
|
||||||
|
#include <sqlpp11/result_field_methods.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -96,46 +97,8 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
template<typename Db, typename FieldSpec>
|
||||||
struct _result_field_t;
|
struct _result_field_t: public result_field_methods_t<_result_field_t<Db, FieldSpec>>
|
||||||
|
|
||||||
// I am SO waiting for concepts lite!
|
|
||||||
template<typename Field, typename Enable = void>
|
|
||||||
struct field_methods_t
|
|
||||||
{
|
{
|
||||||
static constexpr bool _null_is_trivial = true;
|
|
||||||
operator _cpp_value_type() const { return static_cast<const Field&>(*this).value(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
|
||||||
struct field_methods_t<
|
|
||||||
_result_field_t<Db, FieldSpec>,
|
|
||||||
typename std::enable_if<enforce_null_result_treatment_t<Db>::value
|
|
||||||
and column_spec_can_be_null_t<FieldSpec>::value
|
|
||||||
and not null_is_trivial_value_t<FieldSpec>::value>::type>
|
|
||||||
{
|
|
||||||
static constexpr bool _null_is_trivial = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Db, typename FieldSpec>
|
|
||||||
struct _result_field_t: public field_methods_t<_result_field_t<Db, FieldSpec>>
|
|
||||||
{
|
|
||||||
using _field_methods_t = field_methods_t<_result_field_t<Db, FieldSpec>>;
|
|
||||||
|
|
||||||
using _traits = make_traits<integral,
|
|
||||||
tag::is_result_field,
|
|
||||||
tag::is_expression,
|
|
||||||
tag_if<tag::null_is_trivial_value, _field_methods_t::_null_is_trivial>>;
|
|
||||||
|
|
||||||
struct _recursive_traits
|
|
||||||
{
|
|
||||||
using _parameters = std::tuple<>;
|
|
||||||
using _provided_tables = detail::type_set<>;
|
|
||||||
using _provided_outer_tables = detail::type_set<>;
|
|
||||||
using _required_tables = detail::type_set<>;
|
|
||||||
using _extra_tables = detail::type_set<>;
|
|
||||||
using _can_be_null = column_spec_can_be_null_t<FieldSpec>;
|
|
||||||
};
|
|
||||||
|
|
||||||
_result_field_t():
|
_result_field_t():
|
||||||
_is_valid(false),
|
_is_valid(false),
|
||||||
_value_ptr(nullptr),
|
_value_ptr(nullptr),
|
||||||
|
@ -192,6 +192,9 @@ namespace sqlpp
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
using value_type_of = typename detail::value_type_of_impl<T>::type;
|
using value_type_of = typename detail::value_type_of_impl<T>::type;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using cpp_value_type_of = typename value_type_of<T>::_cpp_value_type;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using required_tables_of = typename detail::required_table_of_impl<T>::type;
|
using required_tables_of = typename detail::required_table_of_impl<T>::type;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user