0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Added template parameter Db to result_entry

This commit is contained in:
rbock 2014-02-21 07:24:07 +01:00
parent b7935b61d5
commit 8c8b95d14e
17 changed files with 67 additions and 57 deletions

View File

@ -98,7 +98,7 @@ namespace sqlpp
bool _is_null; bool _is_null;
}; };
template<bool TrivialIsNull = false> template<typename Db, bool TrivialIsNull = false>
struct _result_entry_t struct _result_entry_t
{ {
_result_entry_t(): _result_entry_t():
@ -190,8 +190,8 @@ namespace sqlpp
}; };
}; };
template<bool TrivialIsNull> template<typename Db, bool TrivialIsNull>
inline std::ostream& operator<<(std::ostream& os, const boolean::_result_entry_t<TrivialIsNull>& e) inline std::ostream& operator<<(std::ostream& os, const boolean::_result_entry_t<Db, TrivialIsNull>& e)
{ {
return os << e.value(); return os << e.value();
} }

View File

@ -98,7 +98,7 @@ namespace sqlpp
bool _is_null; bool _is_null;
}; };
template<bool TrivialIsNull = false> template<typename Db, bool TrivialIsNull = false>
struct _result_entry_t struct _result_entry_t
{ {
using _value_type = integral; using _value_type = integral;
@ -238,8 +238,8 @@ namespace sqlpp
}; };
}; };
template<bool TrivialIsNull> template<typename Db, bool TrivialIsNull>
inline std::ostream& operator<<(std::ostream& os, const floating_point::_result_entry_t<TrivialIsNull>& e) inline std::ostream& operator<<(std::ostream& os, const floating_point::_result_entry_t<Db, TrivialIsNull>& e)
{ {
return os << e.value(); return os << e.value();
} }

View File

@ -98,7 +98,7 @@ namespace sqlpp
bool _is_null; bool _is_null;
}; };
template<bool NullIsTrivial = false> template<typename Db, bool NullIsTrivial = false>
struct _result_entry_t struct _result_entry_t
{ {
using _value_type = integral; using _value_type = integral;
@ -245,8 +245,8 @@ namespace sqlpp
}; };
}; };
template<bool NullIsTrivial> template<typename Db, bool NullIsTrivial>
inline std::ostream& operator<<(std::ostream& os, const integral::_result_entry_t<NullIsTrivial>& e) inline std::ostream& operator<<(std::ostream& os, const integral::_result_entry_t<Db, NullIsTrivial>& e)
{ {
return os << e.value(); return os << e.value();
} }

View File

@ -41,13 +41,13 @@ namespace sqlpp
template<size_t level, size_t index, typename... NamedExpr> template<size_t level, size_t index, typename... NamedExpr>
struct result_row_impl; struct result_row_impl;
template<size_t level, size_t index, typename NamedExpr, typename... Rest> template<size_t level, size_t index, typename Db, typename NamedExpr, typename... Rest>
struct result_row_impl<level, index, NamedExpr, Rest...>: struct result_row_impl<level, index, Db, NamedExpr, Rest...>:
public NamedExpr::_name_t::template _member_t<typename NamedExpr::_value_type::template _result_entry_t<NamedExpr::_trivial_value_is_null>>, public NamedExpr::_name_t::template _member_t<typename NamedExpr::_value_type::template _result_entry_t<Db, NamedExpr::_trivial_value_is_null>>,
public result_row_impl<level, index + 1, Rest...> public result_row_impl<level, index + 1, Db, Rest...>
{ {
using _field = typename NamedExpr::_name_t::template _member_t<typename NamedExpr::_value_type::template _result_entry_t<NamedExpr::_trivial_value_is_null>>; using _field = typename NamedExpr::_name_t::template _member_t<typename NamedExpr::_value_type::template _result_entry_t<Db, NamedExpr::_trivial_value_is_null>>;
using _rest = result_row_impl<level, index + 1, Rest...>; using _rest = result_row_impl<level, index + 1, Db, Rest...>;
static constexpr size_t _last_index = _rest::_last_index; static constexpr size_t _last_index = _rest::_last_index;
result_row_impl() = default; result_row_impl() = default;
@ -84,13 +84,13 @@ namespace sqlpp
} }
}; };
template<size_t level, size_t index, typename AliasProvider, typename... Col, typename... Rest> template<size_t level, size_t index, typename AliasProvider, typename Db, typename... Col, typename... Rest>
struct result_row_impl<level, index, vendor::multi_field_t<AliasProvider, std::tuple<Col...>>, Rest...>: struct result_row_impl<level, index, Db, vendor::multi_field_t<AliasProvider, std::tuple<Col...>>, Rest...>:
public AliasProvider::_name_t::template _member_t<result_row_impl<level, index, Col...>>, // level prevents identical closures to be present twice in the inheritance tree public AliasProvider::_name_t::template _member_t<result_row_impl<level, index, Db, Col...>>, // level prevents identical closures to be present twice in the inheritance tree
public result_row_impl<level, index + sizeof...(Col), Rest...> public result_row_impl<level, index + sizeof...(Col), Db, Rest...>
{ {
using _multi_field = typename AliasProvider::_name_t::template _member_t<result_row_impl<level, index, Col...>>; using _multi_field = typename AliasProvider::_name_t::template _member_t<result_row_impl<level, index, Db, Col...>>;
using _rest = result_row_impl<level, index + sizeof...(Col), Rest...>; using _rest = result_row_impl<level, index + sizeof...(Col), Db, Rest...>;
static constexpr size_t _last_index = _rest::_last_index; static constexpr size_t _last_index = _rest::_last_index;
result_row_impl() = default; result_row_impl() = default;
@ -126,8 +126,8 @@ namespace sqlpp
} }
}; };
template<size_t level, size_t index> template<size_t level, size_t index, typename Db>
struct result_row_impl<level, index> struct result_row_impl<level, index, Db>
{ {
static constexpr size_t _last_index = index; static constexpr size_t _last_index = index;
result_row_impl() = default; result_row_impl() = default;
@ -155,10 +155,10 @@ namespace sqlpp
}; };
} }
template<typename... NamedExpr> template<typename Db, typename... NamedExpr>
struct result_row_t: public detail::result_row_impl<0, 0, NamedExpr...> struct result_row_t: public detail::result_row_impl<0, 0, Db, NamedExpr...>
{ {
using _impl = detail::result_row_impl<0, 0, NamedExpr...>; using _impl = detail::result_row_impl<0, 0, Db, NamedExpr...>;
bool _is_valid; bool _is_valid;
static constexpr size_t _last_static_index = _impl::_last_index; static constexpr size_t _last_static_index = _impl::_last_index;
@ -221,11 +221,11 @@ namespace sqlpp
} }
}; };
template<typename... NamedExpr> template<typename Db, typename... NamedExpr>
struct dynamic_result_row_t: public detail::result_row_impl<0, 0, NamedExpr...> struct dynamic_result_row_t: public detail::result_row_impl<0, 0, Db, NamedExpr...>
{ {
using _impl = detail::result_row_impl<0, 0, NamedExpr...>; using _impl = detail::result_row_impl<0, 0, Db, NamedExpr...>;
using _field_type = detail::text::_result_entry_t<>; using _field_type = detail::text::_result_entry_t<Db, false>;
static constexpr size_t _last_static_index = _impl::_last_index; static constexpr size_t _last_static_index = _impl::_last_index;
bool _is_valid; bool _is_valid;

View File

@ -99,7 +99,8 @@ namespace sqlpp
using _table_set = ::sqlpp::detail::type_set<>; using _table_set = ::sqlpp::detail::type_set<>;
using _column_list_t = ColumnList; using _column_list_t = ColumnList;
using _result_row_t = typename _column_list_t::_result_row_t; template<typename Db>
using _result_row_t = typename _column_list_t::template _result_row_t<Db>;
using _dynamic_names_t = typename _column_list_t::_dynamic_names_t; using _dynamic_names_t = typename _column_list_t::_dynamic_names_t;
using _is_select = std::true_type; using _is_select = std::true_type;
@ -490,13 +491,13 @@ namespace sqlpp
size_t get_no_of_result_columns() const size_t get_no_of_result_columns() const
{ {
return _result_row_t::static_size() + get_dynamic_names().size(); return _column_list_t::static_size() + get_dynamic_names().size();
} }
template<typename Db> template<typename Db>
struct can_run_t struct can_run_t
{ {
//static_assert(is_where_t<Where>::value, "cannot select remove without having a where condition, use .where(true) to remove all rows"); //static_assert(is_where_t<Where>::value, "cannot select select without having a where condition, use .where(true) to remove all rows");
//static_assert(not vendor::is_noop<ColumnList>::value, "cannot run select without having selected anything"); //static_assert(not vendor::is_noop<ColumnList>::value, "cannot run select without having selected anything");
//static_assert(is_from_t<From>::value, "cannot run select without a from()"); //static_assert(is_from_t<From>::value, "cannot run select without a from()");
//static_assert(is_where_t<Where>::value, "cannot run select without having a where condition, use .where(true) to select all rows"); //static_assert(is_where_t<Where>::value, "cannot run select without having a where condition, use .where(true) to select all rows");
@ -509,7 +510,7 @@ namespace sqlpp
// Execute // Execute
template<typename Db> template<typename Db>
auto _run(Db& db) const auto _run(Db& db) const
-> result_t<decltype(db.select(*this)), _result_row_t> -> result_t<decltype(db.select(*this)), _result_row_t<Db>>
{ {
static_assert(can_run_t<Db>::value, "Cannot execute select statement"); static_assert(can_run_t<Db>::value, "Cannot execute select statement");
static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead");

View File

@ -38,6 +38,7 @@ namespace sqlpp
return vendor::serializer_t<Context, T>::_(t, context); return vendor::serializer_t<Context, T>::_(t, context);
} }
/*
namespace vendor // Required if you want to call serialize(sqlpp::value(7), printer), for instance namespace vendor // Required if you want to call serialize(sqlpp::value(7), printer), for instance
{ {
template<typename T, typename Context> template<typename T, typename Context>
@ -47,6 +48,7 @@ namespace sqlpp
return vendor::serializer_t<Context, T>::_(t, context); return vendor::serializer_t<Context, T>::_(t, context);
} }
} }
*/
} }

View File

@ -97,7 +97,7 @@ namespace sqlpp
bool _is_null; bool _is_null;
}; };
template<bool TrivialIsNull = false> template<typename Db, bool TrivialIsNull = false>
struct _result_entry_t struct _result_entry_t
{ {
_result_entry_t(): _result_entry_t():
@ -196,8 +196,8 @@ namespace sqlpp
}; };
}; };
template<bool TrivialIsNull> template<typename Db, bool TrivialIsNull>
inline std::ostream& operator<<(std::ostream& os, const text::_result_entry_t<TrivialIsNull>& e) inline std::ostream& operator<<(std::ostream& os, const text::_result_entry_t<Db, TrivialIsNull>& e)
{ {
return os << e.value(); return os << e.value();
} }

View File

@ -156,9 +156,10 @@ namespace sqlpp
}; };
using _name_t = typename ::sqlpp::detail::get_first_argument_if_unique<Columns...>::_name_t; using _name_t = typename ::sqlpp::detail::get_first_argument_if_unique<Columns...>::_name_t;
template<typename Db>
using _result_row_t = typename std::conditional<_is_dynamic::value, using _result_row_t = typename std::conditional<_is_dynamic::value,
dynamic_result_row_t<make_field_t<Columns>...>, dynamic_result_row_t<Db, make_field_t<Columns>...>,
result_row_t<make_field_t<Columns>...>>::type; result_row_t<Db, make_field_t<Columns>...>>::type;
using _dynamic_names_t = typename dynamic_select_column_list<Database>::_names_t; using _dynamic_names_t = typename dynamic_select_column_list<Database>::_names_t;
@ -198,7 +199,8 @@ namespace sqlpp
struct no_select_column_list_t struct no_select_column_list_t
{ {
using _is_noop = std::true_type; using _is_noop = std::true_type;
using _result_row_t = ::sqlpp::result_row_t<>; template<typename Db>
using _result_row_t = ::sqlpp::result_row_t<Db>;
using _dynamic_names_t = typename dynamic_select_column_list<void>::_names_t; using _dynamic_names_t = typename dynamic_select_column_list<void>::_names_t;
using _value_type = no_value_t; using _value_type = no_value_t;
struct _name_t {}; struct _name_t {};

View File

@ -10,7 +10,7 @@ build_and_run(InterpretTest)
#build_and_run(InsertTest) #build_and_run(InsertTest)
#build_and_run(RemoveTest) #build_and_run(RemoveTest)
#build_and_run(UpdateTest) #build_and_run(UpdateTest)
#build_and_run(SelectTest) build_and_run(SelectTest)
#build_and_run(FunctionTest) #build_and_run(FunctionTest)
#build_and_run(PreparedTest) #build_and_run(PreparedTest)

View File

@ -32,7 +32,7 @@
#include <iostream> #include <iostream>
DbMock db = {}; MockDb db = {};
SQLPP_ALIAS_PROVIDER(kaesekuchen); SQLPP_ALIAS_PROVIDER(kaesekuchen);
int main() int main()

View File

@ -29,8 +29,8 @@
#include <sqlpp11/insert.h> #include <sqlpp11/insert.h>
#include <iostream> #include <iostream>
DbMock db; MockDb db;
DbMock::_serializer_context_t printer; MockDb::_serializer_context_t printer;
int main() int main()
{ {

View File

@ -34,8 +34,8 @@
#include <iostream> #include <iostream>
DbMock db = {}; MockDb db = {};
DbMock::_serializer_context_t printer; MockDb::_serializer_context_t printer;
SQLPP_ALIAS_PROVIDER(kaesekuchen); SQLPP_ALIAS_PROVIDER(kaesekuchen);
int main() int main()
@ -101,7 +101,7 @@ int main()
serialize(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).str(); serialize(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).str();
// functions // functions
serialize(sqlpp::value(7), printer).str(); sqlpp::serialize(sqlpp::value(7), printer).str();// FIXME: Maybe the vendor namespace is not a good idea? argument lives in namespace vendor
serialize(sqlpp::verbatim<sqlpp::detail::integral>("irgendwas integrales"), printer).str(); serialize(sqlpp::verbatim<sqlpp::detail::integral>("irgendwas integrales"), printer).str();
serialize(sqlpp::value_list(std::vector<int>({1,2,3,4,5,6,8})), printer).str(); serialize(sqlpp::value_list(std::vector<int>({1,2,3,4,5,6,8})), printer).str();
serialize(exists(select(t.alpha).from(t)), printer).str(); serialize(exists(select(t.alpha).from(t)), printer).str();

View File

@ -30,7 +30,7 @@
#include <sqlpp11/serializer_context.h> #include <sqlpp11/serializer_context.h>
#include <sqlpp11/connection.h> #include <sqlpp11/connection.h>
struct DbMock: public sqlpp::connection struct MockDb: public sqlpp::connection
{ {
struct _serializer_context_t struct _serializer_context_t
{ {

View File

@ -31,7 +31,7 @@
#include <iostream> #include <iostream>
DbMock db = {}; MockDb db = {};
int main() int main()
{ {

View File

@ -30,8 +30,8 @@
#include "is_regular.h" #include "is_regular.h"
DbMock db; MockDb db;
DbMock::_serializer_context_t printer; MockDb::_serializer_context_t printer;
int main() int main()
{ {

View File

@ -33,8 +33,8 @@
#include <sqlpp11/connection.h> #include <sqlpp11/connection.h>
DbMock db = {}; MockDb db = {};
DbMock::_serializer_context_t printer; MockDb::_serializer_context_t printer;
namespace alias namespace alias
{ {
@ -296,14 +296,19 @@ int main()
{ {
auto a = select(t.alpha); auto a = select(t.alpha);
auto b = select(f.epsilon.as(t.alpha)); auto b = select(f.epsilon.as(t.alpha));
using A = typename decltype(a)::_result_row_t; using A = typename decltype(a)::_result_row_t<MockDb>;
using B = typename decltype(b)::_result_row_t; using B = typename decltype(b)::_result_row_t<MockDb>;
static_assert(std::is_same< static_assert(std::is_same<
decltype(t.alpha)::_value_type::_base_value_type, decltype(t.alpha)::_value_type::_base_value_type,
decltype(f.epsilon)::_value_type::_base_value_type>::value, "Two bigint columns must have identical base_value_type"); decltype(f.epsilon)::_value_type::_base_value_type>::value, "Two bigint columns must have identical base_value_type");
static_assert(std::is_same<A, B>::value, "select with identical columns(name/value_type) need to have identical result_types"); static_assert(std::is_same<A, B>::value, "select with identical columns(name/value_type) need to have identical result_types");
} }
for (const auto& row : db(select(all_of(t)).from(t).where(true)))
{
int64_t a = row.alpha;
}
{ {
auto s = dynamic_select(db, all_of(t)).dynamic_from().dynamic_where().dynamic_limit().dynamic_offset(); auto s = dynamic_select(db, all_of(t)).dynamic_from().dynamic_where().dynamic_limit().dynamic_offset();
s.add_from(t); s.add_from(t);

View File

@ -29,8 +29,8 @@
#include "MockDb.h" #include "MockDb.h"
#include "is_regular.h" #include "is_regular.h"
DbMock db; MockDb db;
DbMock::_serializer_context_t printer; MockDb::_serializer_context_t printer;
int main() int main()
{ {