mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Fixed multi_column to handle all_of again
This commit is contained in:
parent
b82a0295cf
commit
5b67061fca
67
include/sqlpp11/detail/copy_tuple_args.h
Normal file
67
include/sqlpp11/detail/copy_tuple_args.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* 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_DETAIL_COPY_TUPLE_ARGS_H
|
||||||
|
#define SQLPP_DETAIL_COPY_TUPLE_ARGS_H
|
||||||
|
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
struct as_tuple
|
||||||
|
{
|
||||||
|
static std::tuple<T> _(T t) { return { t }; };
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
struct as_tuple<std::tuple<Args...>>
|
||||||
|
{
|
||||||
|
static std::tuple<Args...> _(std::tuple<Args...> t) { return t; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<template<typename, typename...> class Target, typename First, typename T>
|
||||||
|
struct copy_tuple_args_impl
|
||||||
|
{
|
||||||
|
static_assert(vendor::wrong_t<T>::value, "copy_tuple_args must be called with a tuple");
|
||||||
|
};
|
||||||
|
|
||||||
|
template<template<typename First, typename...> class Target, typename First, typename... Args>
|
||||||
|
struct copy_tuple_args_impl<Target, First, std::tuple<Args...>>
|
||||||
|
{
|
||||||
|
using type = Target<First, Args...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<template<typename First, typename...> class Target, typename First, typename T>
|
||||||
|
using copy_tuple_args_t = typename copy_tuple_args_impl<Target, First, T>::type;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -30,36 +30,47 @@
|
|||||||
#include <sqlpp11/no_value.h>
|
#include <sqlpp11/no_value.h>
|
||||||
#include <sqlpp11/detail/logic.h>
|
#include <sqlpp11/detail/logic.h>
|
||||||
|
|
||||||
|
#include <sqlpp11/detail/copy_tuple_args.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
template<typename AliasProvider, typename T>
|
template<typename AliasProvider, typename... Columns>
|
||||||
struct multi_column_t
|
struct multi_column_t
|
||||||
{
|
{
|
||||||
static_assert(vendor::wrong_t<T>::value, "invalid argument for multicolumn_t");
|
static_assert(detail::and_t<is_named_expression_t, Columns...>::value, "multi_column parameters need to be named expressions");
|
||||||
};
|
|
||||||
|
|
||||||
template<typename AliasProvider, typename... NamedExpr>
|
|
||||||
struct multi_column_t<AliasProvider, std::tuple<NamedExpr...>>
|
|
||||||
{
|
|
||||||
static_assert(detail::and_t<is_named_expression_t, NamedExpr...>::value, "multi_column parameters need to be named expressions");
|
|
||||||
|
|
||||||
using _name_t = typename AliasProvider::_name_t;
|
using _name_t = typename AliasProvider::_name_t;
|
||||||
|
|
||||||
|
multi_column_t(std::tuple<Columns...> columns):
|
||||||
|
_columns(columns)
|
||||||
|
{}
|
||||||
|
|
||||||
|
multi_column_t(Columns... columns):
|
||||||
|
_columns(columns...)
|
||||||
|
{}
|
||||||
|
|
||||||
|
multi_column_t(const multi_column_t&) = default;
|
||||||
|
multi_column_t(multi_column_t&&) = default;
|
||||||
|
multi_column_t& operator=(const multi_column_t&) = default;
|
||||||
|
multi_column_t& operator=(multi_column_t&&) = default;
|
||||||
|
~multi_column_t() = default;
|
||||||
|
|
||||||
|
|
||||||
struct _value_type: public no_value_t
|
struct _value_type: public no_value_t
|
||||||
{
|
{
|
||||||
using _is_named_expression = std::true_type;
|
using _is_named_expression = std::true_type;
|
||||||
};
|
};
|
||||||
using _is_multi_column = std::true_type;
|
using _is_multi_column = std::true_type;
|
||||||
|
|
||||||
std::tuple<NamedExpr...> _columns;
|
std::tuple<Columns...> _columns;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace vendor
|
namespace vendor
|
||||||
{
|
{
|
||||||
template<typename Context, typename AliasProvider, typename... NamedExpr>
|
template<typename Context, typename AliasProvider, typename... Columns>
|
||||||
struct interpreter_t<Context, multi_column_t<AliasProvider, NamedExpr...>>
|
struct interpreter_t<Context, multi_column_t<AliasProvider, Columns...>>
|
||||||
{
|
{
|
||||||
using T = multi_column_t<AliasProvider, NamedExpr...>;
|
using T = multi_column_t<AliasProvider, Columns...>;
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
static Context& _(const T& t, Context& context)
|
||||||
{
|
{
|
||||||
@ -71,18 +82,20 @@ namespace sqlpp
|
|||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
#warning need to handle all_of here.
|
template<typename AliasProvider, typename... Columns>
|
||||||
template<typename AliasProvider, typename... Expr>
|
|
||||||
using make_multi_column_t =
|
using make_multi_column_t =
|
||||||
multi_column_t<AliasProvider, std::tuple<Expr...>>;
|
detail::copy_tuple_args_t<multi_column_t, AliasProvider,
|
||||||
|
decltype(std::tuple_cat(detail::as_tuple<Columns>::_(std::declval<Columns>())...))>;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename AliasProvider, typename... NamedExpr>
|
template<typename AliasProvider, typename... Columns>
|
||||||
detail::make_multi_column_t<AliasProvider, NamedExpr...> multi_column(const AliasProvider& aliasProvider, NamedExpr... namedExpr)
|
auto multi_column(const AliasProvider&, Columns... columns)
|
||||||
|
-> detail::make_multi_column_t<AliasProvider, Columns...>
|
||||||
{
|
{
|
||||||
return { std::tuple<NamedExpr...>(namedExpr...)};
|
return detail::make_multi_column_t<AliasProvider, Columns...>(std::tuple_cat(detail::as_tuple<Columns>::_(columns)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,6 +48,8 @@
|
|||||||
#include <sqlpp11/vendor/policy.h>
|
#include <sqlpp11/vendor/policy.h>
|
||||||
#include <sqlpp11/vendor/policy_update.h>
|
#include <sqlpp11/vendor/policy_update.h>
|
||||||
|
|
||||||
|
#include <sqlpp11/detail/copy_tuple_args.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
@ -217,37 +219,13 @@ namespace sqlpp
|
|||||||
vendor::no_limit_t,
|
vendor::no_limit_t,
|
||||||
vendor::no_offset_t>;
|
vendor::no_offset_t>;
|
||||||
|
|
||||||
template<typename T>
|
namespace detail
|
||||||
struct as_tuple
|
|
||||||
{
|
{
|
||||||
static std::tuple<T> _(T t) { return { t }; };
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
struct as_tuple<std::tuple<Args...>>
|
|
||||||
{
|
|
||||||
static std::tuple<Args...> _(std::tuple<Args...> t) { return t; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template<template<typename, typename...> class Target, typename First, typename T>
|
|
||||||
struct copy_tuple_args_impl
|
|
||||||
{
|
|
||||||
static_assert(vendor::wrong_t<T>::value, "copy_tuple_args must be called with a tuple");
|
|
||||||
};
|
|
||||||
|
|
||||||
template<template<typename First, typename...> class Target, typename First, typename... Args>
|
|
||||||
struct copy_tuple_args_impl<Target, First, std::tuple<Args...>>
|
|
||||||
{
|
|
||||||
using type = Target<First, Args...>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<template<typename First, typename...> class Target, typename First, typename T>
|
|
||||||
using copy_tuple_args_t = typename copy_tuple_args_impl<Target, First, T>::type;
|
|
||||||
|
|
||||||
template<typename Database, typename... Columns>
|
template<typename Database, typename... Columns>
|
||||||
using make_select_column_list_t =
|
using make_select_column_list_t =
|
||||||
copy_tuple_args_t<vendor::select_column_list_t, Database,
|
copy_tuple_args_t<vendor::select_column_list_t, Database,
|
||||||
decltype(std::tuple_cat(as_tuple<Columns>::_(std::declval<Columns>())...))>;
|
decltype(std::tuple_cat(as_tuple<Columns>::_(std::declval<Columns>())...))>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
blank_select_t<void> select() // FIXME: These should be constexpr
|
blank_select_t<void> select() // FIXME: These should be constexpr
|
||||||
@ -259,9 +237,9 @@ namespace sqlpp
|
|||||||
auto select(Columns... columns)
|
auto select(Columns... columns)
|
||||||
-> vendor::update_policies_t<blank_select_t<void>,
|
-> vendor::update_policies_t<blank_select_t<void>,
|
||||||
vendor::no_select_column_list_t,
|
vendor::no_select_column_list_t,
|
||||||
make_select_column_list_t<void, Columns...>>
|
detail::make_select_column_list_t<void, Columns...>>
|
||||||
{
|
{
|
||||||
return { blank_select_t<void>(), make_select_column_list_t<void, Columns...>(std::tuple_cat(as_tuple<Columns>::_(columns)...)) };
|
return { blank_select_t<void>(), detail::make_select_column_list_t<void, Columns...>(std::tuple_cat(detail::as_tuple<Columns>::_(columns)...)) };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Database>
|
template<typename Database>
|
||||||
@ -272,9 +250,9 @@ namespace sqlpp
|
|||||||
|
|
||||||
template<typename Database, typename... Columns>
|
template<typename Database, typename... Columns>
|
||||||
auto dynamic_select(const Database&, Columns... columns)
|
auto dynamic_select(const Database&, Columns... columns)
|
||||||
-> vendor::update_policies_t<blank_select_t<Database>, vendor::no_select_column_list_t, make_select_column_list_t<void, Columns...>>
|
-> vendor::update_policies_t<blank_select_t<Database>, vendor::no_select_column_list_t, detail::make_select_column_list_t<void, Columns...>>
|
||||||
{
|
{
|
||||||
return { blank_select_t<Database>(), make_select_column_list_t<void, Columns...>(std::tuple_cat(as_tuple<Columns>::_(columns)...)) };
|
return { blank_select_t<Database>(), detail::make_select_column_list_t<void, Columns...>(std::tuple_cat(detail::as_tuple<Columns>::_(columns)...)) };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,7 @@ int main()
|
|||||||
// multi_column
|
// multi_column
|
||||||
*/
|
*/
|
||||||
interpret(multi_column(t.alpha, t.alpha, (t.beta + "cake").as(t.gamma)), printer).flush();
|
interpret(multi_column(t.alpha, t.alpha, (t.beta + "cake").as(t.gamma)), printer).flush();
|
||||||
|
interpret(multi_column(t, all_of(t)), printer).flush();
|
||||||
|
|
||||||
// dynamic select
|
// dynamic select
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user