From 2defeff18e83c3cc52bb5d1748f83b377453c8d5 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Fri, 13 Sep 2013 07:24:41 +0200 Subject: [PATCH] Introduced field template to make result_row_t less specific. It is sufficient to have name and type. There is no need for the result "to know" what exact expression was used to define the column. Surprisingly, template alias creates new templates (in contrast to non-template using, which really just creates an alias of a type). template struct A{}; struct X { template using U = A; }; struct Y { template using U = A; template<> using U = X; }; template class X> struct Z{}; static_assert(std::is_same, Y::U>::value, "class aliases are really just aliases"); static_assert(not std::is_same, Z>::value, "template aliases are new templates"); int main() { } --- include/sqlpp11/result_row.h | 4 ++-- include/sqlpp11/select.h | 3 ++- tests/SelectTest.cpp | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index 509a9acd..150e5101 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -28,7 +28,7 @@ #define SQLPP_RESULT_ROW_H #include -#include +#include #include namespace sqlpp { @@ -59,7 +59,7 @@ namespace sqlpp }; template - struct result_row_impl>, Rest...>: + struct result_row_impl>, Rest...>: public AliasProvider::template _member_t>, // level prevents identical closures to be present twice in the inheritance tree public result_row_impl { diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 7c31177f..62a67703 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -102,7 +103,7 @@ namespace sqlpp using add_limit_t = select_t; using add_offset_t = select_t; - using _result_row_t = result_row_t; + using _result_row_t = result_row_t...>; // Indicators using _value_type = typename std::conditional< diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 027a9fc2..2aef3709 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -38,6 +38,7 @@ DbMock db; int main() { TabSample t; + TabFoo f; // Test a table { @@ -249,6 +250,17 @@ int main() static_assert(not sqlpp::is_value_t::value, "a multi_column is not a value"); } + // Test that result sets with identical name/value combinations have identical types + { + auto a = select(t.alpha); + auto b = select(f.omega.as(t.alpha)); + using A = typename decltype(a)::_result_row_t; + using B = typename decltype(b)::_result_row_t; + static_assert(std::is_same::value, "Two bigint columns must have identical base_value_type"); + //A x = std::declval(); + static_assert(std::is_same::value, "select with identical columns(name/value_type) need to have identical result_types"); + } + static_assert(sqlpp::is_select_flag_t::value, "sqlpp::all has to be a select_flag"); using T = sqlpp::detail::wrap_operand::type;