0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Rewrote macro generated function code to handwritten code

This increases the number of Bytes, but it also increases readability,
and reduces complexity.
It also allows to specialize functions for database engines.
This commit is contained in:
Roland Bock 2013-09-19 17:07:14 +02:00
parent 0db405c28c
commit 950859af5f
11 changed files with 757 additions and 51 deletions

93
include/sqlpp11/any.h Normal file
View File

@ -0,0 +1,93 @@
/*
* Copyright (c) 2013, 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_ANY_H
#define SQLPP_ANY_H
#include <sstream>
#include <sqlpp11/boolean.h>
namespace sqlpp
{
namespace detail
{
template<typename Select>
struct any_t: public boolean::template operators<any_t<Select>>
{
static_assert(is_select_t<Select>::value, "any() requires a single column select expression as argument");
static_assert(is_value_t<Select>::value, "any() requires a single column select expression as argument");
struct _value_type: public Select::_value_type::_base_value_type
{
using _is_named_expression = tag_yes;
};
struct _name_t
{
static constexpr const char* _get_name() { return "ANY"; }
template<typename T>
struct _member_t
{
T any;
};
};
any_t(Select&& select):
_select(std::move(select))
{}
any_t(const Select& select):
_select(select)
{}
any_t(const any_t&) = default;
any_t(any_t&&) = default;
any_t& operator=(const any_t&) = default;
any_t& operator=(any_t&&) = default;
~any_t() = default;
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << "ANY(";
_select.serialize(os, db);
os << ")";
}
private:
Select _select;
};
}
template<typename T>
auto any(T&& t) -> typename detail::any_t<typename operand_t<T, is_select_t>::type>
{
return { std::forward<T>(t) };
}
}
#endif

92
include/sqlpp11/avg.h Normal file
View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2013, 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_AVG_H
#define SQLPP_AVG_H
#include <sstream>
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
namespace detail
{
template<typename Expr>
struct avg_t: public boolean::template operators<avg_t<Expr>>
{
static_assert(is_value_t<Expr>::value, "avg() requires a value expression as argument");
struct _value_type: public Expr::_value_type::_base_value_type
{
using _is_named_expression = tag_yes;
};
struct _name_t
{
static constexpr const char* _get_name() { return "AVG"; }
template<typename T>
struct _member_t
{
T avg;
};
};
avg_t(Expr&& expr):
_expr(std::move(expr))
{}
avg_t(const Expr& expr):
_expr(expr)
{}
avg_t(const avg_t&) = default;
avg_t(avg_t&&) = default;
avg_t& operator=(const avg_t&) = default;
avg_t& operator=(avg_t&&) = default;
~avg_t() = default;
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << "AVG(";
_expr.serialize(os, db);
os << ")";
}
private:
Expr _expr;
};
}
template<typename T>
auto avg(T&& t) -> typename detail::avg_t<typename operand_t<T, is_value_t>::type>
{
return { std::forward<T>(t) };
}
}
#endif

View File

@ -42,7 +42,11 @@ namespace sqlpp
using _valid_args = typename detail::make_set_if_not<is_text_t, First, Args...>::type; using _valid_args = typename detail::make_set_if_not<is_text_t, First, Args...>::type;
static_assert(_valid_args::size::value == 0, "at least one non-text argument detected in concat()"); static_assert(_valid_args::size::value == 0, "at least one non-text argument detected in concat()");
using _value_type = typename First::_value_type::_base_value_type; struct _value_type: public First::_value_type::_base_value_type
{
using _is_named_expression = tag_yes;
};
struct _name_t struct _name_t
{ {
static constexpr const char* _get_name() { return "CONCAT"; } static constexpr const char* _get_name() { return "CONCAT"; }

92
include/sqlpp11/count.h Normal file
View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2013, 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_COUNT_H
#define SQLPP_COUNT_H
#include <sstream>
#include <sqlpp11/numeric.h>
namespace sqlpp
{
namespace detail
{
template<typename Expr>
struct count_t: public numeric::template operators<count_t<Expr>>
{
static_assert(is_value_t<Expr>::value, "count() requires a sql value as argument");
struct _value_type: public numeric
{
using _is_named_expression = tag_yes;
};
struct _name_t
{
static constexpr const char* _get_name() { return "COUNT"; }
template<typename T>
struct _member_t
{
T count;
};
};
count_t(Expr&& expr):
_expr(std::move(expr))
{}
count_t(const Expr& expr):
_expr(expr)
{}
count_t(const count_t&) = default;
count_t(count_t&&) = default;
count_t& operator=(const count_t&) = default;
count_t& operator=(count_t&&) = default;
~count_t() = default;
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << "COUNT(";
_expr.serialize(os, db);
os << ")";
}
private:
Expr _expr;
};
}
template<typename T>
auto count(T&& t) -> typename detail::count_t<typename operand_t<T, is_value_t>::type>
{
return { std::forward<T>(t) };
}
}
#endif

92
include/sqlpp11/exists.h Normal file
View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2013, 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_EXISTS_H
#define SQLPP_EXISTS_H
#include <sstream>
#include <sqlpp11/boolean.h>
namespace sqlpp
{
namespace detail
{
template<typename Select>
struct exists_t: public boolean::template operators<exists_t<Select>>
{
static_assert(is_select_t<Select>::value, "exists() requires a select expression as argument");
struct _value_type: public boolean
{
using _is_named_expression = tag_yes;
};
struct _name_t
{
static constexpr const char* _get_name() { return "EXISTS"; }
template<typename T>
struct _member_t
{
T exists;
};
};
exists_t(Select&& select):
_select(std::move(select))
{}
exists_t(const Select& select):
_select(select)
{}
exists_t(const exists_t&) = default;
exists_t(exists_t&&) = default;
exists_t& operator=(const exists_t&) = default;
exists_t& operator=(exists_t&&) = default;
~exists_t() = default;
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << "EXISTS(";
_select.serialize(os, db);
os << ")";
}
private:
Select _select;
};
}
template<typename T>
auto exists(T&& t) -> typename detail::exists_t<typename operand_t<T, is_select_t>::type>
{
return { std::forward<T>(t) };
}
}
#endif

View File

@ -27,60 +27,20 @@
#ifndef SQLPP_FUNCTIONS_H #ifndef SQLPP_FUNCTIONS_H
#define SQLPP_FUNCTIONS_H #define SQLPP_FUNCTIONS_H
#include <sstream>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/column_types.h> #include <sqlpp11/column_types.h>
#include <sstream> #include <sqlpp11/exists.h>
#include <sqlpp11/any.h>
#include <sqlpp11/some.h>
#include <sqlpp11/count.h>
#include <sqlpp11/min.h>
#include <sqlpp11/max.h>
#include <sqlpp11/avg.h>
#include <sqlpp11/sum.h>
namespace sqlpp namespace sqlpp
{ {
#define SQLPP_MAKE_UNARY_TYPED_FUNCTION(NAME, SQL, CONSTRAINT, VALUE_TYPE) \
namespace detail\
{\
template<typename T>\
struct NAME##_t\
{\
static_assert(CONSTRAINT<typename std::decay<T>::type>::value, #NAME "() argument has constraint: " #CONSTRAINT);\
static_assert(is_expression_t<typename std::decay<T>::type>::value, #NAME "() argument has contraint: is_expression_t");\
using _operand = typename operand_t<T, CONSTRAINT>::type;\
\
struct _op\
{\
struct _value_type: public VALUE_TYPE\
{\
using _is_named_expression = tag_yes;\
};\
struct _name_t\
{\
static constexpr const char* _get_name() { return #SQL; }\
template<typename M>\
struct _member_t\
{\
M NAME;\
};\
};\
};\
\
using type = named_unary_function_t<_op, _operand>;\
};\
}\
template<typename T>\
auto NAME(T&& t) -> typename detail::NAME##_t<T>::type\
{\
return { std::forward<T>(t) };\
}
#define SQLPP_MAKE_UNARY_FUNCTION(NAME, SQL, CONSTRAINT) SQLPP_MAKE_UNARY_TYPED_FUNCTION(NAME, SQL, CONSTRAINT, _operand::_value_type)
SQLPP_MAKE_UNARY_FUNCTION(avg, AVG, is_value_t);
SQLPP_MAKE_UNARY_FUNCTION(min, MIN, is_value_t);
SQLPP_MAKE_UNARY_FUNCTION(max, MAX, is_value_t);
SQLPP_MAKE_UNARY_FUNCTION(sum, SUM, is_value_t);
SQLPP_MAKE_UNARY_FUNCTION(any, ANY, is_select_t);
SQLPP_MAKE_UNARY_FUNCTION(some, SOME, is_select_t);
SQLPP_MAKE_UNARY_TYPED_FUNCTION(count, COUNT, is_expression_t, bigint);
SQLPP_MAKE_UNARY_TYPED_FUNCTION(exists, EXISTS, is_select_t, boolean);
SQLPP_MAKE_UNARY_TYPED_FUNCTION(not_exists, NOT EXISTS, is_select_t, boolean);
template<typename T> template<typename T>
auto value(T&& t) -> typename operand_t<T, is_value_t>::type auto value(T&& t) -> typename operand_t<T, is_value_t>::type
{ {

View File

@ -43,7 +43,11 @@ namespace sqlpp
static_assert(is_text_t<Operand>::value, "Operand for like() has to be a text"); static_assert(is_text_t<Operand>::value, "Operand for like() has to be a text");
static_assert(is_text_t<Pattern>::value, "Pattern for like() has to be a text"); static_assert(is_text_t<Pattern>::value, "Pattern for like() has to be a text");
using _value_type = typename Operand::_value_type::_base_value_type; struct _value_type: public Operand::_value_type::_base_value_type
{
using _is_named_expression = tag_yes;
};
struct _name_t struct _name_t
{ {
static constexpr const char* _get_name() { return "LIKE"; } static constexpr const char* _get_name() { return "LIKE"; }

92
include/sqlpp11/max.h Normal file
View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2013, 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_MAX_H
#define SQLPP_MAX_H
#include <sstream>
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
namespace detail
{
template<typename Expr>
struct max_t: public boolean::template operators<max_t<Expr>>
{
static_assert(is_value_t<Expr>::value, "max() requires a value expression as argument");
struct _value_type: public Expr::_value_type::_base_value_type
{
using _is_named_expression = tag_yes;
};
struct _name_t
{
static constexpr const char* _get_name() { return "MAX"; }
template<typename T>
struct _member_t
{
T max;
};
};
max_t(Expr&& expr):
_expr(std::move(expr))
{}
max_t(const Expr& expr):
_expr(expr)
{}
max_t(const max_t&) = default;
max_t(max_t&&) = default;
max_t& operator=(const max_t&) = default;
max_t& operator=(max_t&&) = default;
~max_t() = default;
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << "MAX(";
_expr.serialize(os, db);
os << ")";
}
private:
Expr _expr;
};
}
template<typename T>
auto max(T&& t) -> typename detail::max_t<typename operand_t<T, is_value_t>::type>
{
return { std::forward<T>(t) };
}
}
#endif

92
include/sqlpp11/min.h Normal file
View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2013, 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_MIN_H
#define SQLPP_MIN_H
#include <sstream>
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
namespace detail
{
template<typename Expr>
struct min_t: public boolean::template operators<min_t<Expr>>
{
static_assert(is_value_t<Expr>::value, "min() requires a value expression as argument");
struct _value_type: public Expr::_value_type::_base_value_type
{
using _is_named_expression = tag_yes;
};
struct _name_t
{
static constexpr const char* _get_name() { return "MIN"; }
template<typename T>
struct _member_t
{
T min;
};
};
min_t(Expr&& expr):
_expr(std::move(expr))
{}
min_t(const Expr& expr):
_expr(expr)
{}
min_t(const min_t&) = default;
min_t(min_t&&) = default;
min_t& operator=(const min_t&) = default;
min_t& operator=(min_t&&) = default;
~min_t() = default;
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << "MIN(";
_expr.serialize(os, db);
os << ")";
}
private:
Expr _expr;
};
}
template<typename T>
auto min(T&& t) -> typename detail::min_t<typename operand_t<T, is_value_t>::type>
{
return { std::forward<T>(t) };
}
}
#endif

93
include/sqlpp11/some.h Normal file
View File

@ -0,0 +1,93 @@
/*
* Copyright (c) 2013, 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_SOME_H
#define SQLPP_SOME_H
#include <sstream>
#include <sqlpp11/boolean.h>
namespace sqlpp
{
namespace detail
{
template<typename Select>
struct some_t: public boolean::template operators<some_t<Select>>
{
static_assert(is_select_t<Select>::value, "some() requires a single column select expression as argument");
static_assert(is_value_t<Select>::value, "some() requires a single column select expression as argument");
struct _value_type: public Select::_value_type::_base_value_type
{
using _is_named_expression = tag_yes;
};
struct _name_t
{
static constexpr const char* _get_name() { return "SOME"; }
template<typename T>
struct _member_t
{
T some;
};
};
some_t(Select&& select):
_select(std::move(select))
{}
some_t(const Select& select):
_select(select)
{}
some_t(const some_t&) = default;
some_t(some_t&&) = default;
some_t& operator=(const some_t&) = default;
some_t& operator=(some_t&&) = default;
~some_t() = default;
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << "SOME(";
_select.serialize(os, db);
os << ")";
}
private:
Select _select;
};
}
template<typename T>
auto some(T&& t) -> typename detail::some_t<typename operand_t<T, is_select_t>::type>
{
return { std::forward<T>(t) };
}
}
#endif

92
include/sqlpp11/sum.h Normal file
View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2013, 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_MAX_H
#define SQLPP_MAX_H
#include <sstream>
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
namespace detail
{
template<typename Expr>
struct max_t: public boolean::template operators<max_t<Expr>>
{
static_assert(is_value_t<Expr>::value, "max() requires a value expression as argument");
struct _value_type: public Expr::_value_type::_base_value_type
{
using _is_named_expression = tag_yes;
};
struct _name_t
{
static constexpr const char* _get_name() { return "MAX"; }
template<typename T>
struct _member_t
{
T max;
};
};
max_t(Expr&& expr):
_expr(std::move(expr))
{}
max_t(const Expr& expr):
_expr(expr)
{}
max_t(const max_t&) = default;
max_t(max_t&&) = default;
max_t& operator=(const max_t&) = default;
max_t& operator=(max_t&&) = default;
~max_t() = default;
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
os << "MAX(";
_expr.serialize(os, db);
os << ")";
}
private:
Expr _expr;
};
}
template<typename T>
auto max(T&& t) -> typename detail::max_t<typename operand_t<T, is_value_t>::type>
{
return { std::forward<T>(t) };
}
}
#endif