mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
cte.h compiles
This commit is contained in:
parent
4112448b5b
commit
12a0d9d698
@ -27,6 +27,7 @@
|
||||
#ifndef SQLPP_CTE_H
|
||||
#define SQLPP_CTE_H
|
||||
|
||||
#include <sqlpp11/result_row_fwd.h>
|
||||
#include <sqlpp11/statement_fwd.h>
|
||||
#include <sqlpp11/type_traits.h>
|
||||
#include <sqlpp11/parameter_list.h>
|
||||
@ -37,6 +38,60 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename AliasProvider, typename Statement, typename... ColumnSpecs>
|
||||
struct cte_t;
|
||||
|
||||
template<typename FieldSpec>
|
||||
struct cte_column_spec_t
|
||||
{
|
||||
using _alias_t = typename FieldSpec::_alias_t;
|
||||
|
||||
using _traits = make_traits<value_type_of<FieldSpec>,
|
||||
tag::must_not_insert,
|
||||
tag::must_not_update,
|
||||
tag_if<tag::can_be_null, can_be_null_t<FieldSpec>::value>
|
||||
>;
|
||||
};
|
||||
|
||||
template<typename AliasProvider, typename Statement, typename ResultRow>
|
||||
struct make_cte_impl
|
||||
{
|
||||
using type = void;
|
||||
};
|
||||
|
||||
template<typename AliasProvider, typename Statement, typename... FieldSpecs>
|
||||
struct make_cte_impl<AliasProvider, Statement, result_row_t<void, FieldSpecs...>>
|
||||
{
|
||||
using type = cte_t<AliasProvider, Statement, cte_column_spec_t<FieldSpecs>...>;
|
||||
};
|
||||
|
||||
template<typename AliasProvider, typename Statement>
|
||||
using make_cte_t = typename make_cte_impl<AliasProvider, Statement, get_result_row_t<Statement>>::type;
|
||||
|
||||
template<typename AliasProvider, typename Statement, typename... ColumnSpecs>
|
||||
struct cte_t: public member_t<ColumnSpecs, column_t<AliasProvider, ColumnSpecs>>... // FIXME
|
||||
{
|
||||
using _alias_t = typename AliasProvider::_alias_t;
|
||||
|
||||
Statement _statement;
|
||||
};
|
||||
|
||||
template<typename Context, typename AliasProvider, typename Statement, typename... ColumnSpecs>
|
||||
struct serializer_t<Context, cte_t<AliasProvider, Statement, ColumnSpecs...>>
|
||||
{
|
||||
using _serialize_check = serialize_check_of<Context, Statement>;
|
||||
using T = cte_t<AliasProvider, Statement, ColumnSpecs...>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
context << name_of<T>::char_ptr() << " AS (";
|
||||
serialize(t._statement, context);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// The cte is displayed as AliasProviderName except within the with:
|
||||
// - the with needs the
|
||||
// AliasProviderName AS (ColumnNames) (select/union)
|
||||
@ -46,7 +101,7 @@ namespace sqlpp
|
||||
{
|
||||
template<typename Statement>
|
||||
auto as(Statement statement)
|
||||
-> cte<AliasProvider, Statement>
|
||||
-> make_cte_t<AliasProvider, Statement>
|
||||
{
|
||||
// FIXME: Need to check stuff here.
|
||||
return { statement };
|
||||
|
@ -28,6 +28,7 @@
|
||||
#define SQLPP_RESULT_ROW_H
|
||||
|
||||
#include <map>
|
||||
#include <sqlpp11/result_row_fwd.h>
|
||||
#include <sqlpp11/field_spec.h>
|
||||
#include <sqlpp11/text.h>
|
||||
#include <sqlpp11/detail/field_index_sequence.h>
|
||||
|
39
include/sqlpp11/result_row_fwd.h
Normal file
39
include/sqlpp11/result_row_fwd.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2014, Roland Bock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef SQLPP_RESULT_ROW_FWD_H
|
||||
#define SQLPP_RESULT_ROW_FWD_H
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Db, typename... FieldSpecs>
|
||||
struct result_row_t;
|
||||
|
||||
template<typename Db, typename... FieldSpecs>
|
||||
struct dynamic_result_row_t;
|
||||
}
|
||||
|
||||
#endif
|
@ -31,6 +31,8 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
// FIXME: We might use field specs here (same as with cte)
|
||||
//
|
||||
// provide type information for sub-selects that are used as named expressions or tables
|
||||
template<typename Select, typename NamedExpr>
|
||||
struct select_column_spec_t
|
||||
|
@ -37,6 +37,9 @@
|
||||
#include <sqlpp11/interpretable_list.h>
|
||||
#include <sqlpp11/logic.h>
|
||||
|
||||
|
||||
#include <sqlpp11/cte.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Database, typename... Expressions>
|
||||
|
Loading…
Reference in New Issue
Block a user