mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Merge branch 'feature/case' into develop
This commit is contained in:
commit
e25ae64909
189
include/sqlpp11/case.h
Normal file
189
include/sqlpp11/case.h
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015-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_CASE_H
|
||||||
|
#define SQLPP_CASE_H
|
||||||
|
|
||||||
|
#include <sqlpp11/type_traits.h>
|
||||||
|
#include <sqlpp11/char_sequence.h>
|
||||||
|
#include <sqlpp11/data_types/boolean.h>
|
||||||
|
#include <sqlpp11/detail/type_set.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template <typename When>
|
||||||
|
using valid_when_t =
|
||||||
|
logic::all_t<is_boolean_t<wrap_operand_t<When>>::value, is_expression_t<wrap_operand_t<When>>::value>;
|
||||||
|
|
||||||
|
template <typename Then>
|
||||||
|
using valid_then_t = is_expression_t<wrap_operand_t<Then>>;
|
||||||
|
|
||||||
|
template <typename Then, typename Else>
|
||||||
|
using valid_else_t = logic::all_t<
|
||||||
|
is_expression_t<wrap_operand_t<Else>>::value,
|
||||||
|
logic::any_t<is_sql_null_t<Then>::value,
|
||||||
|
is_sql_null_t<wrap_operand_t<Else>>::value,
|
||||||
|
std::is_same<value_type_of<Then>, value_type_of<wrap_operand_t<Else>>>::value>::value>;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename When, typename Then, typename Else>
|
||||||
|
struct case_t
|
||||||
|
: public expression_operators<
|
||||||
|
case_t<When, Then, Else>,
|
||||||
|
typename std::conditional<is_sql_null_t<Then>::value, value_type_of<Else>, value_type_of<Then>>::type>,
|
||||||
|
public alias_operators<case_t<When, Then, Else>>
|
||||||
|
{
|
||||||
|
using _traits = make_traits<value_type_of<Then>, tag::is_expression>;
|
||||||
|
using _nodes = detail::type_vector<When, Then, Else>;
|
||||||
|
|
||||||
|
case_t(When when, Then then, Else else_) : _when(when), _then(then), _else(else_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
case_t(const case_t&) = default;
|
||||||
|
case_t(case_t&&) = default;
|
||||||
|
case_t& operator=(const case_t&) = default;
|
||||||
|
case_t& operator=(case_t&&) = default;
|
||||||
|
~case_t() = default;
|
||||||
|
|
||||||
|
When _when;
|
||||||
|
Then _then;
|
||||||
|
Else _else;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename When, typename Then>
|
||||||
|
class case_then_t
|
||||||
|
{
|
||||||
|
template <typename Else>
|
||||||
|
auto _else_impl(const std::true_type&, Else else_) -> case_t<When, Then, Else>
|
||||||
|
{
|
||||||
|
return {_when, _then, else_};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Else>
|
||||||
|
auto _else_impl(const std::false_type&, Else else_) -> void;
|
||||||
|
|
||||||
|
public:
|
||||||
|
case_then_t(When when, Then then) : _when(when), _then(then)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
case_then_t(const case_then_t&) = default;
|
||||||
|
case_then_t(case_then_t&&) = default;
|
||||||
|
case_then_t& operator=(const case_then_t&) = default;
|
||||||
|
case_then_t& operator=(case_then_t&&) = default;
|
||||||
|
~case_then_t() = default;
|
||||||
|
|
||||||
|
template <typename Else>
|
||||||
|
auto else_(Else else_) -> decltype(this->_else_impl(detail::valid_else_t<Then, Else>{}, else_))
|
||||||
|
{
|
||||||
|
static_assert(detail::valid_else_t<Then, Else>::value,
|
||||||
|
"arguments of then and else must be expressions of the same type (or null)");
|
||||||
|
return _else_impl(detail::valid_else_t<Then, Else>{}, else_);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
When _when;
|
||||||
|
Then _then;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename When>
|
||||||
|
class case_when_t
|
||||||
|
{
|
||||||
|
template <typename Then>
|
||||||
|
auto _then_impl(const std::true_type&, Then t) -> case_then_t<When, wrap_operand_t<Then>>
|
||||||
|
{
|
||||||
|
return {_when, t};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Then>
|
||||||
|
auto _then_impl(const std::false_type&, Then t) -> void;
|
||||||
|
|
||||||
|
public:
|
||||||
|
case_when_t(When when) : _when(when)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
case_when_t(const case_when_t&) = default;
|
||||||
|
case_when_t(case_when_t&&) = default;
|
||||||
|
case_when_t& operator=(const case_when_t&) = default;
|
||||||
|
case_when_t& operator=(case_when_t&&) = default;
|
||||||
|
~case_when_t() = default;
|
||||||
|
|
||||||
|
template <typename Then>
|
||||||
|
auto then(Then t) -> decltype(this->_then_impl(detail::valid_then_t<Then>{}, t))
|
||||||
|
{
|
||||||
|
static_assert(detail::valid_then_t<Then>::value, "then argument must be a value expression");
|
||||||
|
return _then_impl(detail::valid_then_t<Then>{}, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
When _when;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Context, typename When, typename Then, typename Else>
|
||||||
|
struct serializer_t<Context, case_t<When, Then, Else>>
|
||||||
|
{
|
||||||
|
using _serialize_check = serialize_check_of<When, Then, Else>;
|
||||||
|
using T = case_t<When, Then, Else>;
|
||||||
|
|
||||||
|
static Context& _(const T& t, Context& context)
|
||||||
|
{
|
||||||
|
context << "(CASE WHEN ";
|
||||||
|
serialize(t._when, context);
|
||||||
|
context << " THEN ";
|
||||||
|
serialize(t._then, context);
|
||||||
|
context << " ELSE ";
|
||||||
|
serialize(t._else, context);
|
||||||
|
context << " END)";
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template <typename When>
|
||||||
|
auto case_when_impl(const std::true_type&, When when) -> case_when_t<wrap_operand_t<When>>
|
||||||
|
{
|
||||||
|
return {when};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename When>
|
||||||
|
auto case_when_impl(const std::false_type&, When when) -> void;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename When>
|
||||||
|
auto case_when(When when) -> decltype(detail::case_when_impl(detail::valid_when_t<When>{}, when))
|
||||||
|
{
|
||||||
|
static_assert(detail::valid_when_t<When>::value, "case_when condition must be a boolean expression");
|
||||||
|
|
||||||
|
return detail::case_when_impl(detail::valid_when_t<When>{}, when);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -33,5 +33,6 @@
|
|||||||
#include <sqlpp11/data_types/text.h>
|
#include <sqlpp11/data_types/text.h>
|
||||||
#include <sqlpp11/data_types/day_point.h>
|
#include <sqlpp11/data_types/day_point.h>
|
||||||
#include <sqlpp11/data_types/time_point.h>
|
#include <sqlpp11/data_types/time_point.h>
|
||||||
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,25 +27,12 @@
|
|||||||
#ifndef SQLPP_NO_VALUE_H
|
#ifndef SQLPP_NO_VALUE_H
|
||||||
#define SQLPP_NO_VALUE_H
|
#define SQLPP_NO_VALUE_H
|
||||||
|
|
||||||
#include <type_traits>
|
#include <sqlpp11/data_types/no_value/data_type.h>
|
||||||
#include <sqlpp11/expression_operators.h>
|
#include <sqlpp11/data_types/no_value/operand.h>
|
||||||
#include <sqlpp11/data_types/column_operators.h>
|
#include <sqlpp11/data_types/no_value/wrap_operand.h>
|
||||||
|
#include <sqlpp11/data_types/no_value/expression_operators.h>
|
||||||
|
#include <sqlpp11/data_types/no_value/column_operators.h>
|
||||||
|
#include <sqlpp11/data_types/no_value/parameter_value.h>
|
||||||
|
#include <sqlpp11/data_types/no_value/result_field.h>
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
struct no_value_t
|
|
||||||
{
|
|
||||||
using _traits = make_traits<void>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Base>
|
|
||||||
struct expression_operators<Base, no_value_t>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Base>
|
|
||||||
struct column_operators<Base, no_value_t>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
41
include/sqlpp11/data_types/no_value/column_operators.h
Normal file
41
include/sqlpp11/data_types/no_value/column_operators.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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_NO_VALUE_COLUMN_OPERATORS_H
|
||||||
|
#define SQLPP_NO_VALUE_COLUMN_OPERATORS_H
|
||||||
|
|
||||||
|
#include <sqlpp11/data_types/column_operators.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
struct no_value_t;
|
||||||
|
|
||||||
|
template <typename Base>
|
||||||
|
struct column_operators<Base, no_value_t>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
44
include/sqlpp11/data_types/no_value/data_type.h
Normal file
44
include/sqlpp11/data_types/no_value/data_type.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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_NO_VALUE_DATA_TYPE_H
|
||||||
|
#define SQLPP_NO_VALUE_DATA_TYPE_H
|
||||||
|
|
||||||
|
#include <sqlpp11/type_traits.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
struct no_value_t
|
||||||
|
{
|
||||||
|
using _traits = make_traits<no_value_t>;
|
||||||
|
using _cpp_value_type = void;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using _is_valid_operand = wrong_t<T>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
42
include/sqlpp11/data_types/no_value/expression_operators.h
Normal file
42
include/sqlpp11/data_types/no_value/expression_operators.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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_NO_VALUE_EXPRESSION_OPERATORS_H
|
||||||
|
#define SQLPP_NO_VALUE_EXPRESSION_OPERATORS_H
|
||||||
|
|
||||||
|
#include <sqlpp11/expression_return_types.h>
|
||||||
|
#include <sqlpp11/expression_operators.h>
|
||||||
|
#include <sqlpp11/basic_expression_operators.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
template <typename Expression>
|
||||||
|
struct expression_operators<Expression, no_value_t> : public basic_expression_operators<Expression, no_value_t>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
35
include/sqlpp11/data_types/no_value/operand.h
Normal file
35
include/sqlpp11/data_types/no_value/operand.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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_NO_VALUE_OPERAND_H
|
||||||
|
#define SQLPP_NO_VALUE_OPERAND_H
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
// There is no no_value operand
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
35
include/sqlpp11/data_types/no_value/parameter_value.h
Normal file
35
include/sqlpp11/data_types/no_value/parameter_value.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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_NO_VALUE_PARAMETER_VALUE_H
|
||||||
|
#define SQLPP_NO_VALUE_PARAMETER_VALUE_H
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
// There is no no_value parameter
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
72
include/sqlpp11/data_types/no_value/result_field.h
Normal file
72
include/sqlpp11/data_types/no_value/result_field.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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_NO_VALUE_RESULT_FIELD_H
|
||||||
|
#define SQLPP_NO_VALUE_RESULT_FIELD_H
|
||||||
|
|
||||||
|
#include <sqlpp11/result_field.h>
|
||||||
|
#include <sqlpp11/data_types/no_value/data_type.h>
|
||||||
|
#include <sqlpp11/field_spec.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
|
||||||
|
struct result_field_t<Db, field_spec_t<NameType, no_value_t, CanBeNull, NullIsTrivialValue>>
|
||||||
|
{
|
||||||
|
template <typename Target>
|
||||||
|
void _bind(Target&, size_t)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Target>
|
||||||
|
void _post_bind(Target&, size_t)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void _validate() const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void _invalidate() const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool is_null() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
|
||||||
|
inline std::ostream& operator<<(
|
||||||
|
std::ostream& os, const result_field_t<Db, field_spec_t<NameType, no_value_t, CanBeNull, NullIsTrivialValue>>&)
|
||||||
|
{
|
||||||
|
os << "NULL";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
35
include/sqlpp11/data_types/no_value/wrap_operand.h
Normal file
35
include/sqlpp11/data_types/no_value/wrap_operand.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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_NO_VALUE_WRAP_OPERAND_H
|
||||||
|
#define SQLPP_NO_VALUE_WRAP_OPERAND_H
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
// There is no no_value operand
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -27,7 +27,7 @@
|
|||||||
#ifndef SQLPP_DEFAULT_VALUE_H
|
#ifndef SQLPP_DEFAULT_VALUE_H
|
||||||
#define SQLPP_DEFAULT_VALUE_H
|
#define SQLPP_DEFAULT_VALUE_H
|
||||||
|
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <sqlpp11/parameter_list.h>
|
#include <sqlpp11/parameter_list.h>
|
||||||
#include <sqlpp11/data_types.h>
|
#include <sqlpp11/data_types.h>
|
||||||
#include <sqlpp11/aggregate_functions.h>
|
#include <sqlpp11/aggregate_functions.h>
|
||||||
|
#include <sqlpp11/case.h>
|
||||||
#include <sqlpp11/in.h>
|
#include <sqlpp11/in.h>
|
||||||
#include <sqlpp11/not_in.h>
|
#include <sqlpp11/not_in.h>
|
||||||
#include <sqlpp11/is_null.h>
|
#include <sqlpp11/is_null.h>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include <sqlpp11/statement_fwd.h>
|
#include <sqlpp11/statement_fwd.h>
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
#include <sqlpp11/no_data.h>
|
#include <sqlpp11/no_data.h>
|
||||||
#include <sqlpp11/prepared_insert.h>
|
#include <sqlpp11/prepared_insert.h>
|
||||||
#include <sqlpp11/serializer.h>
|
#include <sqlpp11/serializer.h>
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#ifndef SQLPP_MULTI_COLUMN_H
|
#ifndef SQLPP_MULTI_COLUMN_H
|
||||||
#define SQLPP_MULTI_COLUMN_H
|
#define SQLPP_MULTI_COLUMN_H
|
||||||
|
|
||||||
#include <sqlpp11/no_value.h>
|
|
||||||
#include <sqlpp11/logic.h>
|
#include <sqlpp11/logic.h>
|
||||||
#include <sqlpp11/detail/type_set.h>
|
#include <sqlpp11/detail/type_set.h>
|
||||||
|
|
||||||
@ -35,6 +34,8 @@
|
|||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
struct no_value_t;
|
||||||
|
|
||||||
template <typename AliasProvider, typename... Columns>
|
template <typename AliasProvider, typename... Columns>
|
||||||
struct multi_column_alias_t;
|
struct multi_column_alias_t;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#define SQLPP_NOOP_H
|
#define SQLPP_NOOP_H
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
#include <sqlpp11/serializer.h>
|
#include <sqlpp11/serializer.h>
|
||||||
#include <sqlpp11/prepared_execute.h>
|
#include <sqlpp11/prepared_execute.h>
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#ifndef SQLPP_NULL_H
|
#ifndef SQLPP_NULL_H
|
||||||
#define SQLPP_NULL_H
|
#define SQLPP_NULL_H
|
||||||
|
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include <sqlpp11/parameter_list.h>
|
#include <sqlpp11/parameter_list.h>
|
||||||
#include <sqlpp11/result.h>
|
#include <sqlpp11/result.h>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include <sqlpp11/parameter_list.h>
|
#include <sqlpp11/parameter_list.h>
|
||||||
#include <sqlpp11/result.h>
|
#include <sqlpp11/result.h>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include <sqlpp11/parameter_list.h>
|
#include <sqlpp11/parameter_list.h>
|
||||||
#include <sqlpp11/result.h>
|
#include <sqlpp11/result.h>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include <sqlpp11/parameter_list.h>
|
#include <sqlpp11/parameter_list.h>
|
||||||
#include <sqlpp11/result.h>
|
#include <sqlpp11/result.h>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include <sqlpp11/parameter_list.h>
|
#include <sqlpp11/parameter_list.h>
|
||||||
#include <sqlpp11/result.h>
|
#include <sqlpp11/result.h>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <sqlpp11/result_row.h>
|
#include <sqlpp11/result_row.h>
|
||||||
#include <sqlpp11/table.h>
|
#include <sqlpp11/table.h>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
#include <sqlpp11/field_spec.h>
|
#include <sqlpp11/field_spec.h>
|
||||||
#include <sqlpp11/expression_fwd.h>
|
#include <sqlpp11/expression_fwd.h>
|
||||||
#include <sqlpp11/select_pseudo_table.h>
|
#include <sqlpp11/select_pseudo_table.h>
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#ifndef SQLPP_SELECT_PSEUDO_TABLE_H
|
#ifndef SQLPP_SELECT_PSEUDO_TABLE_H
|
||||||
#define SQLPP_SELECT_PSEUDO_TABLE_H
|
#define SQLPP_SELECT_PSEUDO_TABLE_H
|
||||||
|
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#define SQLPP_SINGLE_TABLE_H
|
#define SQLPP_SINGLE_TABLE_H
|
||||||
|
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
#include <sqlpp11/no_data.h>
|
#include <sqlpp11/no_data.h>
|
||||||
#include <sqlpp11/serializer.h>
|
#include <sqlpp11/serializer.h>
|
||||||
#include <sqlpp11/prepared_insert.h>
|
#include <sqlpp11/prepared_insert.h>
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#include <sqlpp11/column.h>
|
#include <sqlpp11/column.h>
|
||||||
#include <sqlpp11/detail/type_set.h>
|
#include <sqlpp11/detail/type_set.h>
|
||||||
#include <sqlpp11/join.h>
|
#include <sqlpp11/join.h>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -38,12 +38,13 @@
|
|||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
struct no_value_t;
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template <typename T, typename Enable = void>
|
template <typename T, typename Enable = void>
|
||||||
struct value_type_of_impl
|
struct value_type_of_impl
|
||||||
{
|
{
|
||||||
static_assert(wrong_t<value_type_of_impl>::value, "Attempting to obtain value type from type without value_type");
|
using type = no_value_t;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#ifndef SQLPP_VERBATIM_H
|
#ifndef SQLPP_VERBATIM_H
|
||||||
#define SQLPP_VERBATIM_H
|
#define SQLPP_VERBATIM_H
|
||||||
|
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <sqlpp11/serialize.h>
|
#include <sqlpp11/serialize.h>
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#ifndef SQLPP_VERBATIM_TABLE_H
|
#ifndef SQLPP_VERBATIM_TABLE_H
|
||||||
#define SQLPP_VERBATIM_TABLE_H
|
#define SQLPP_VERBATIM_TABLE_H
|
||||||
|
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
|
@ -216,5 +216,9 @@ int Interpret(int, char**)
|
|||||||
printer.reset();
|
printer.reset();
|
||||||
std::cerr << serialize(select(all_of(s)).from(s).where(true), printer).str() << std::endl;
|
std::cerr << serialize(select(all_of(s)).from(s).where(true), printer).str() << std::endl;
|
||||||
|
|
||||||
|
printer.reset();
|
||||||
|
std::cerr << serialize(sqlpp::case_when(true).then(t.alpha).else_(t.alpha + 1).as(t.beta), printer).str()
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sqlpp11/schema.h>
|
#include <sqlpp11/schema.h>
|
||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/data_types/no_value.h>
|
||||||
#include <sqlpp11/serialize.h>
|
#include <sqlpp11/serialize.h>
|
||||||
#include <sqlpp11/serializer_context.h>
|
#include <sqlpp11/serializer_context.h>
|
||||||
#include <sqlpp11/connection.h>
|
#include <sqlpp11/connection.h>
|
||||||
|
@ -164,5 +164,11 @@ int Select(int, char**)
|
|||||||
|
|
||||||
select(sqlpp::value(7).as(t.alpha));
|
select(sqlpp::value(7).as(t.alpha));
|
||||||
|
|
||||||
|
for (const auto& row :
|
||||||
|
db(select(sqlpp::case_when(true).then(sqlpp::null).else_(sqlpp::null).as(t.beta)).from(t).where(true)))
|
||||||
|
{
|
||||||
|
std::cerr << row.beta << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user