mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Merge branch 'feature/auto-alias-named-functions' into develop
This commit is contained in:
commit
8886551d04
@ -39,19 +39,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>;
|
||||
using _nodes = detail::type_vector<Select>;
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "any_";
|
||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
||||
template<typename T>
|
||||
struct _member_t
|
||||
{
|
||||
T any;
|
||||
T& operator()() { return any; }
|
||||
const T& operator()() const { return any; }
|
||||
};
|
||||
};
|
||||
|
||||
any_t(Select select):
|
||||
_select(select)
|
||||
{}
|
||||
|
66
include/sqlpp11/auto_alias.h
Normal file
66
include/sqlpp11/auto_alias.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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_AUTO_ALIAS_H
|
||||
#define SQLPP_AUTO_ALIAS_H
|
||||
|
||||
#include <sqlpp11/alias.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename T, typename Enable = void>
|
||||
struct has_auto_alias_t
|
||||
{
|
||||
static constexpr bool value = false;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct has_auto_alias_t<T, typename std::enable_if<not wrong_t<typename T::_auto_alias_t>::value>::type>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template<typename T, typename Enable = void>
|
||||
struct auto_alias_impl
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct auto_alias_impl<T, typename std::enable_if<has_auto_alias_t<T>::value>::type>
|
||||
{
|
||||
using type = expression_alias_t<T, typename T::_auto_alias_t>;
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
using auto_alias_t = typename detail::auto_alias_impl<T>::type;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -32,17 +32,8 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Flag, typename Expr>
|
||||
struct avg_t:
|
||||
public expression_operators<avg_t<Flag, Expr>, floating_point>,
|
||||
public alias_operators<avg_t<Flag, Expr>>
|
||||
struct avg_alias_t
|
||||
{
|
||||
using _traits = make_traits<floating_point, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
|
||||
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "avg() used with flag other than 'distinct'");
|
||||
static_assert(is_numeric_t<Expr>::value, "avg() requires a value expression as argument");
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "avg_";
|
||||
@ -55,6 +46,20 @@ namespace sqlpp
|
||||
const T& operator()() const { return avg; }
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Flag, typename Expr>
|
||||
struct avg_t:
|
||||
public expression_operators<avg_t<Flag, Expr>, floating_point>,
|
||||
public alias_operators<avg_t<Flag, Expr>>
|
||||
{
|
||||
using _traits = make_traits<floating_point, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
|
||||
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "avg() used with flag other than 'distinct'");
|
||||
static_assert(is_numeric_t<Expr>::value, "avg() requires a value expression as argument");
|
||||
|
||||
using _auto_alias_t = avg_alias_t;
|
||||
|
||||
avg_t(Expr expr):
|
||||
_expr(expr)
|
||||
|
@ -37,14 +37,8 @@ namespace sqlpp
|
||||
{
|
||||
struct text;
|
||||
|
||||
template<typename... Args>
|
||||
struct concat_t:
|
||||
public expression_operators<concat_t<Args...>, text>,
|
||||
public alias_operators<concat_t<Args...>>
|
||||
struct concat_alias_t
|
||||
{
|
||||
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Args...>;
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "concat_";
|
||||
@ -55,6 +49,17 @@ namespace sqlpp
|
||||
T concat;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
struct concat_t:
|
||||
public expression_operators<concat_t<Args...>, text>,
|
||||
public alias_operators<concat_t<Args...>>
|
||||
{
|
||||
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Args...>;
|
||||
|
||||
using _auto_alias_t = concat_alias_t;
|
||||
|
||||
concat_t(Args... args):
|
||||
_args(args...)
|
||||
|
@ -33,18 +33,8 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Flag, typename Expr>
|
||||
struct count_t:
|
||||
public expression_operators<count_t<Flag, Expr>, integral>,
|
||||
public alias_operators<count_t<Flag, Expr>>
|
||||
struct count_alias_t
|
||||
{
|
||||
using _traits = make_traits<integral, tag::is_expression, tag::is_selectable>;
|
||||
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
using _can_be_null = std::false_type;
|
||||
|
||||
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "count() used with flag other than 'distinct'");
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "count_";
|
||||
@ -57,6 +47,21 @@ namespace sqlpp
|
||||
const T& operator()() const { return count; }
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Flag, typename Expr>
|
||||
struct count_t:
|
||||
public expression_operators<count_t<Flag, Expr>, integral>,
|
||||
public alias_operators<count_t<Flag, Expr>>
|
||||
{
|
||||
using _traits = make_traits<integral, tag::is_expression/*, tag::is_selectable*/>;
|
||||
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
using _can_be_null = std::false_type;
|
||||
|
||||
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "count() used with flag other than 'distinct'");
|
||||
|
||||
using _auto_alias_t = count_alias_t;
|
||||
|
||||
count_t(const Expr expr):
|
||||
_expr(expr)
|
||||
|
@ -28,6 +28,7 @@
|
||||
#define SQLPP_DETAIL_COPY_TUPLE_ARGS_H
|
||||
|
||||
#include <tuple>
|
||||
#include <sqlpp11/auto_alias.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
@ -37,21 +38,21 @@ namespace sqlpp
|
||||
namespace detail
|
||||
{
|
||||
template<typename T>
|
||||
struct as_tuple
|
||||
struct as_column_tuple
|
||||
{
|
||||
static std::tuple<T> _(T t) { return std::tuple<T>{ t }; }
|
||||
static std::tuple<auto_alias_t<T>> _(T t) { return std::tuple<auto_alias_t<T>>{ auto_alias_t<T>{t} }; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct as_tuple<all_of_t<T>>
|
||||
struct as_column_tuple<all_of_t<T>>
|
||||
{
|
||||
static typename all_of_t<T>::_column_tuple_t _(all_of_t<T>) { return { }; }
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
struct as_tuple<std::tuple<Args...>>
|
||||
struct as_column_tuple<std::tuple<Args...>>
|
||||
{
|
||||
static std::tuple<Args...> _(std::tuple<Args...> t) { return t; }
|
||||
static std::tuple<auto_alias_t<Args>...> _(std::tuple<Args...> t) { return t; }
|
||||
};
|
||||
|
||||
template<template<typename, typename...> class Target, typename First, typename T>
|
||||
|
@ -32,16 +32,8 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Select>
|
||||
struct exists_t:
|
||||
public expression_operators<exists_t<Select>, boolean>,
|
||||
public alias_operators<exists_t<Select>>
|
||||
struct exists_alias_t
|
||||
{
|
||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Select>;
|
||||
|
||||
static_assert(is_select_t<Select>::value, "exists() requires a select expression as argument");
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "exists_";
|
||||
@ -54,6 +46,19 @@ namespace sqlpp
|
||||
const T& operator()() const { return exists; }
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Select>
|
||||
struct exists_t:
|
||||
public expression_operators<exists_t<Select>, boolean>,
|
||||
public alias_operators<exists_t<Select>>
|
||||
{
|
||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Select>;
|
||||
|
||||
static_assert(is_select_t<Select>::value, "exists() requires a select expression as argument");
|
||||
|
||||
using _auto_alias_t = exists_alias_t;
|
||||
|
||||
exists_t(Select select):
|
||||
_select(select)
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include <sqlpp11/not_in.h>
|
||||
#include <sqlpp11/is_null.h>
|
||||
#include <sqlpp11/is_not_null.h>
|
||||
#include <sqlpp11/value_type.h>
|
||||
#include <sqlpp11/exists.h>
|
||||
#include <sqlpp11/any.h>
|
||||
#include <sqlpp11/concat.h>
|
||||
@ -44,6 +43,7 @@
|
||||
#include <sqlpp11/max.h>
|
||||
#include <sqlpp11/avg.h>
|
||||
#include <sqlpp11/sum.h>
|
||||
#include <sqlpp11/value_type.h>
|
||||
#include <sqlpp11/verbatim.h> // Csaba Csoma suggests: unsafe_sql instead of verbatim
|
||||
#include <sqlpp11/verbatim_table.h>
|
||||
#include <sqlpp11/value_or_null.h>
|
||||
|
@ -35,16 +35,8 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Operand, typename... Args>
|
||||
struct in_t:
|
||||
public expression_operators<in_t<Operand, Args...>, boolean>,
|
||||
public alias_operators<in_t<Operand, Args...>>
|
||||
struct in_alias_t
|
||||
{
|
||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Operand, Args...>;
|
||||
|
||||
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "in_";
|
||||
@ -55,6 +47,19 @@ namespace sqlpp
|
||||
T in;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Operand, typename... Args>
|
||||
struct in_t:
|
||||
public expression_operators<in_t<Operand, Args...>, boolean>,
|
||||
public alias_operators<in_t<Operand, Args...>>
|
||||
{
|
||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Operand, Args...>;
|
||||
|
||||
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
|
||||
|
||||
using _auto_alias_t = in_alias_t;
|
||||
|
||||
in_t(Operand operand, Args... args):
|
||||
_operand(operand),
|
||||
|
@ -34,14 +34,8 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Operand>
|
||||
struct is_not_null_t:
|
||||
public expression_operators<is_not_null_t<Operand>, boolean>,
|
||||
public alias_operators<is_not_null_t<Operand>>
|
||||
struct is_not_null_alias_t
|
||||
{
|
||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Operand>;
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "is_not_null_";
|
||||
@ -52,6 +46,17 @@ namespace sqlpp
|
||||
T is_not_null;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Operand>
|
||||
struct is_not_null_t:
|
||||
public expression_operators<is_not_null_t<Operand>, boolean>,
|
||||
public alias_operators<is_not_null_t<Operand>>
|
||||
{
|
||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Operand>;
|
||||
|
||||
using _auto_alias_t = is_not_null_alias_t;
|
||||
|
||||
is_not_null_t(Operand operand):
|
||||
_operand(operand)
|
||||
|
@ -34,6 +34,20 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
struct is_null_alias_t
|
||||
{
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "is_null_";
|
||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
||||
template<typename T>
|
||||
struct _member_t
|
||||
{
|
||||
T is_null;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Operand>
|
||||
struct is_null_t:
|
||||
public expression_operators<is_null_t<Operand>, boolean>,
|
||||
@ -42,16 +56,7 @@ namespace sqlpp
|
||||
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Operand>;
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "is_nnull_";
|
||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
||||
template<typename T>
|
||||
struct _member_t
|
||||
{
|
||||
T is_null;
|
||||
};
|
||||
};
|
||||
using _auto_alias_t = is_null_alias_t;
|
||||
|
||||
is_null_t(Operand operand):
|
||||
_operand(operand)
|
||||
|
@ -32,14 +32,8 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Expr>
|
||||
struct max_t:
|
||||
public expression_operators<max_t<Expr>, value_type_of<Expr>>,
|
||||
public alias_operators<max_t<Expr>>
|
||||
struct max_alias_t
|
||||
{
|
||||
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "max_";
|
||||
@ -52,6 +46,17 @@ namespace sqlpp
|
||||
const T& operator()() const { return max; }
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Expr>
|
||||
struct max_t:
|
||||
public expression_operators<max_t<Expr>, value_type_of<Expr>>,
|
||||
public alias_operators<max_t<Expr>>
|
||||
{
|
||||
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
|
||||
using _auto_alias_t = max_alias_t;
|
||||
|
||||
max_t(Expr expr):
|
||||
_expr(expr)
|
||||
|
@ -32,14 +32,8 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Expr>
|
||||
struct min_t:
|
||||
public expression_operators<min_t<Expr>, value_type_of<Expr>>,
|
||||
public alias_operators<min_t<Expr>>
|
||||
struct min_alias_t
|
||||
{
|
||||
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "min_";
|
||||
@ -52,6 +46,17 @@ namespace sqlpp
|
||||
const T& operator()() const { return min; }
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Expr>
|
||||
struct min_t:
|
||||
public expression_operators<min_t<Expr>, value_type_of<Expr>>,
|
||||
public alias_operators<min_t<Expr>>
|
||||
{
|
||||
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
|
||||
using _auto_alias_t = min_alias_t;
|
||||
|
||||
min_t(Expr expr):
|
||||
_expr(expr)
|
||||
|
@ -130,14 +130,14 @@ namespace sqlpp
|
||||
template<typename... Columns>
|
||||
using make_multi_column_t =
|
||||
detail::copy_tuple_args_t<multi_column_t, void,
|
||||
decltype(std::tuple_cat(detail::as_tuple<Columns>::_(std::declval<Columns>())...))>;
|
||||
decltype(std::tuple_cat(detail::as_column_tuple<Columns>::_(std::declval<Columns>())...))>;
|
||||
}
|
||||
|
||||
template<typename... Columns>
|
||||
auto multi_column(Columns... columns)
|
||||
-> detail::make_multi_column_t<Columns...>
|
||||
{
|
||||
return detail::make_multi_column_t<Columns...>(std::tuple_cat(detail::as_tuple<Columns>::_(columns)...));
|
||||
return detail::make_multi_column_t<Columns...>(std::tuple_cat(detail::as_column_tuple<Columns>::_(columns)...));
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,6 +35,20 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
struct not_in_alias_t
|
||||
{
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "not_in_";
|
||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
||||
template<typename T>
|
||||
struct _member_t
|
||||
{
|
||||
T in;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Operand, typename... Args>
|
||||
struct not_in_t:
|
||||
public expression_operators<not_in_t<Operand, Args...>, boolean>,
|
||||
@ -45,16 +59,7 @@ namespace sqlpp
|
||||
|
||||
static_assert(sizeof...(Args) > 0, "not_in() requires at least one argument");
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "not_in_";
|
||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
||||
template<typename T>
|
||||
struct _member_t
|
||||
{
|
||||
T not_in;
|
||||
};
|
||||
};
|
||||
using _auto_alias_t = not_in_alias_t;
|
||||
|
||||
not_in_t(Operand operand, Args... args):
|
||||
_operand(operand),
|
||||
|
@ -188,17 +188,18 @@ namespace sqlpp
|
||||
template<typename NamedExpression, typename TableCheckRequired = std::true_type>
|
||||
void add(NamedExpression namedExpression)
|
||||
{
|
||||
using named_expression = auto_alias_t<NamedExpression>;
|
||||
static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column");
|
||||
static_assert(is_selectable_t<NamedExpression>::value, "invalid named expression argument in selected_columns::add()");
|
||||
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<NamedExpression>::value, "named expression uses tables unknown to this statement in selected_columns::add()");
|
||||
static_assert(is_selectable_t<named_expression>::value, "invalid named expression argument in selected_columns::add()");
|
||||
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<named_expression>::value, "named expression uses tables unknown to this statement in selected_columns::add()");
|
||||
using column_names = detail::make_type_set_t<typename Columns::_alias_t...>;
|
||||
static_assert(not detail::is_element_of<typename NamedExpression::_alias_t, column_names>::value, "a column of this name is present in the select already");
|
||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, NamedExpression>;
|
||||
static_assert(not detail::is_element_of<typename named_expression::_alias_t, column_names>::value, "a column of this name is present in the select already");
|
||||
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, named_expression>;
|
||||
_serialize_check::_();
|
||||
|
||||
using ok = logic::all_t<
|
||||
_is_dynamic::value,
|
||||
is_selectable_t<NamedExpression>::value,
|
||||
is_selectable_t<named_expression>::value,
|
||||
_serialize_check::type::value
|
||||
>;
|
||||
|
||||
@ -209,7 +210,7 @@ namespace sqlpp
|
||||
template<typename NamedExpression>
|
||||
void _add_impl(NamedExpression namedExpression, const std::true_type&)
|
||||
{
|
||||
return _data._dynamic_columns.emplace_back(namedExpression);
|
||||
return _data._dynamic_columns.emplace_back(auto_alias_t<NamedExpression>{namedExpression});
|
||||
}
|
||||
|
||||
template<typename NamedExpression>
|
||||
@ -338,15 +339,15 @@ namespace sqlpp
|
||||
namespace detail
|
||||
{
|
||||
template<typename... Columns>
|
||||
auto tuple_merge(Columns... columns) -> decltype(std::tuple_cat(as_tuple<Columns>::_(columns)...))
|
||||
auto column_tuple_merge(Columns... columns) -> decltype(std::tuple_cat(as_column_tuple<Columns>::_(columns)...))
|
||||
{
|
||||
return std::tuple_cat(as_tuple<Columns>::_(columns)...);
|
||||
return std::tuple_cat(as_column_tuple<Columns>::_(columns)...);
|
||||
}
|
||||
|
||||
template<typename Database, typename... Columns>
|
||||
using make_select_column_list_t =
|
||||
copy_tuple_args_t<select_column_list_t, Database,
|
||||
decltype(tuple_merge(std::declval<Columns>()...))>;
|
||||
decltype(column_tuple_merge(std::declval<Columns>()...))>;
|
||||
|
||||
}
|
||||
|
||||
@ -395,9 +396,9 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
static constexpr auto _check_args(T... args) -> decltype(_check_tuple(detail::tuple_merge(args...)))
|
||||
static constexpr auto _check_args(T... args) -> decltype(_check_tuple(detail::column_tuple_merge(args...)))
|
||||
{
|
||||
return _check_tuple(detail::tuple_merge(args...));
|
||||
return _check_tuple(detail::column_tuple_merge(args...));
|
||||
}
|
||||
|
||||
template<typename Check, typename T>
|
||||
@ -412,7 +413,7 @@ namespace sqlpp
|
||||
static_assert(sizeof...(Args), "at least one selectable expression (e.g. a column) required in columns()");
|
||||
static_assert(decltype(_check_args(args...))::value, "at least one argument is not a selectable expression in columns()");
|
||||
|
||||
return _columns_impl<void>(_check_args(args...), detail::tuple_merge(args...));
|
||||
return _columns_impl<void>(_check_args(args...), detail::column_tuple_merge(args...));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
@ -422,7 +423,7 @@ namespace sqlpp
|
||||
static_assert(not std::is_same<_database_t, void>::value, "dynamic_columns must not be called in a static statement");
|
||||
static_assert(decltype(_check_args(args...))::value, "at least one argument is not a selectable expression in columns()");
|
||||
|
||||
return _columns_impl<_database_t>(_check_args(args...), detail::tuple_merge(args...));
|
||||
return _columns_impl<_database_t>(_check_args(args...), detail::column_tuple_merge(args...));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -39,19 +39,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>;
|
||||
using _nodes = detail::type_vector<Select>;
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "some_";
|
||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
||||
template<typename T>
|
||||
struct _member_t
|
||||
{
|
||||
T some;
|
||||
T& operator()() { return some; }
|
||||
const T& operator()() const { return some; }
|
||||
};
|
||||
};
|
||||
|
||||
some_t(Select select):
|
||||
_select(select)
|
||||
{}
|
||||
|
@ -32,17 +32,8 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Flag, typename Expr>
|
||||
struct sum_t:
|
||||
public expression_operators<sum_t<Flag, Expr>, value_type_of<Expr>>,
|
||||
public alias_operators<sum_t<Flag, Expr>>
|
||||
struct sum_alias_t
|
||||
{
|
||||
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
|
||||
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "sum() used with flag other than 'distinct'");
|
||||
static_assert(is_numeric_t<Expr>::value, "sum() requires a numeric expression as argument");
|
||||
|
||||
struct _alias_t
|
||||
{
|
||||
static constexpr const char _literal[] = "sum_";
|
||||
@ -55,6 +46,20 @@ namespace sqlpp
|
||||
const T& operator()() const { return sum; }
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Flag, typename Expr>
|
||||
struct sum_t:
|
||||
public expression_operators<sum_t<Flag, Expr>, value_type_of<Expr>>,
|
||||
public alias_operators<sum_t<Flag, Expr>>
|
||||
{
|
||||
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
|
||||
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "sum() used with flag other than 'distinct'");
|
||||
static_assert(is_numeric_t<Expr>::value, "sum() requires a numeric expression as argument");
|
||||
|
||||
using _auto_alias_t = sum_alias_t;
|
||||
|
||||
sum_t(Expr expr):
|
||||
_expr(expr)
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "Sample.h"
|
||||
#include "MockDb.h"
|
||||
#include <sqlpp11/auto_alias.h>
|
||||
#include <sqlpp11/alias_provider.h>
|
||||
#include <sqlpp11/select.h>
|
||||
#include <sqlpp11/functions.h>
|
||||
@ -256,11 +257,11 @@ int Function(int, char**)
|
||||
{
|
||||
using TI = decltype(avg(t.alpha));
|
||||
using TF = decltype(avg(f.omega));
|
||||
static_assert(sqlpp::is_selectable_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::has_auto_alias_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
|
||||
static_assert(not sqlpp::is_integral_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_floating_point_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_selectable_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::has_auto_alias_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement");
|
||||
static_assert(not sqlpp::is_integral_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement");
|
||||
@ -271,15 +272,15 @@ int Function(int, char**)
|
||||
using TI = decltype(count(t.alpha));
|
||||
using TT = decltype(count(t.beta));
|
||||
using TF = decltype(count(f.omega));
|
||||
static_assert(sqlpp::is_selectable_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::has_auto_alias_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_integral_t<TI>::value, "type requirement");
|
||||
static_assert(not sqlpp::is_floating_point_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_selectable_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::has_auto_alias_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::is_integral_t<TF>::value, "type requirement");
|
||||
static_assert(not sqlpp::is_floating_point_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::is_selectable_t<TT>::value, "type requirement");
|
||||
static_assert(sqlpp::has_auto_alias_t<TT>::value, "type requirement");
|
||||
static_assert(sqlpp::is_numeric_t<TT>::value, "type requirement");
|
||||
static_assert(sqlpp::is_integral_t<TT>::value, "type requirement");
|
||||
static_assert(not sqlpp::is_floating_point_t<TT>::value, "type requirement");
|
||||
@ -292,15 +293,15 @@ int Function(int, char**)
|
||||
using TI = decltype(max(t.alpha));
|
||||
using TF = decltype(max(f.omega));
|
||||
using TT = decltype(max(t.beta));
|
||||
static_assert(sqlpp::is_selectable_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::has_auto_alias_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_integral_t<TI>::value, "type requirement");
|
||||
static_assert(not sqlpp::is_floating_point_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_selectable_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::has_auto_alias_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement");
|
||||
static_assert(not sqlpp::is_integral_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::is_selectable_t<TT>::value, "type requirement");
|
||||
static_assert(sqlpp::has_auto_alias_t<TT>::value, "type requirement");
|
||||
static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement");
|
||||
static_assert(sqlpp::is_text_t<TT>::value, "type requirement");
|
||||
}
|
||||
@ -310,7 +311,7 @@ int Function(int, char**)
|
||||
using TI = decltype(min(t.alpha));
|
||||
using TF = decltype(min(f.omega));
|
||||
using TT = decltype(min(t.beta));
|
||||
static_assert(sqlpp::is_selectable_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::has_auto_alias_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_integral_t<TI>::value, "type requirement");
|
||||
static_assert(not sqlpp::is_floating_point_t<TI>::value, "type requirement");
|
||||
@ -327,7 +328,7 @@ int Function(int, char**)
|
||||
{
|
||||
using TI = decltype(sum(t.alpha));
|
||||
using TF = decltype(sum(f.omega));
|
||||
static_assert(sqlpp::is_selectable_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::has_auto_alias_t<TF>::value, "type requirement");
|
||||
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
|
||||
static_assert(sqlpp::is_integral_t<TI>::value, "type requirement");
|
||||
static_assert(not sqlpp::is_floating_point_t<TI>::value, "type requirement");
|
||||
|
@ -53,6 +53,7 @@ int Select(int, char**)
|
||||
const auto tab_a = f.as(sqlpp::alias::a);
|
||||
|
||||
getColumn(db, t.alpha);
|
||||
select(count(t.alpha));
|
||||
|
||||
for (const auto& row : db(select(sqlpp::value(false).as(sqlpp::alias::a))))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user