diff --git a/include/sqlpp11/result_field_base.h b/include/sqlpp11/result_field_base.h index 924ad69d..01f66758 100644 --- a/include/sqlpp11/result_field_base.h +++ b/include/sqlpp11/result_field_base.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -27,13 +27,13 @@ #ifndef SQLPP_RESULT_FIELD_BASE_H #define SQLPP_RESULT_FIELD_BASE_H -#include -#include #include -#include -#include -#include #include +#include +#include +#include +#include +#include namespace sqlpp { @@ -42,6 +42,7 @@ namespace sqlpp { using _db_t = Db; using _field_spec_t = FieldSpec; + using _alias_t = typename FieldSpec::_alias_t; using _cpp_value_type = typename value_type_of::_cpp_value_type; using _cpp_storage_type = StorageType; @@ -116,9 +117,8 @@ namespace sqlpp return _value; } - operator typename std::conditional<_null_is_trivial or (not _can_be_null::value), - _cpp_value_type, - bad_statement>::type() const + operator typename std::conditional<_null_is_trivial or (not _can_be_null::value), _cpp_value_type, bad_statement>:: + type() const { return value(); } diff --git a/include/sqlpp11/result_row.h b/include/sqlpp11/result_row.h index c583280d..59397496 100644 --- a/include/sqlpp11/result_row.h +++ b/include/sqlpp11/result_row.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, Roland Bock + * Copyright (c) 2013-2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -28,12 +28,12 @@ #define SQLPP_RESULT_ROW_H #include -#include +#include +#include #include #include #include -#include -#include +#include namespace sqlpp { @@ -70,6 +70,18 @@ namespace sqlpp { _field::operator()()._post_bind(target, index); } + + template + void _apply(Callable& callable) const + { + callable(_field::operator()()); + } + + template + void _apply(const Callable& callable) const + { + callable(_field::operator()()); + } }; template @@ -104,6 +116,18 @@ namespace sqlpp { _multi_field::operator()()._post_bind(target); } + + template + void _apply(Callable& callable) const + { + _multi_field::operator()()._apply(callable); + } + + template + void _apply(const Callable& callable) const + { + _multi_field::operator()()._apply(callable); + } }; template @@ -137,6 +161,20 @@ namespace sqlpp using swallow = int[]; (void)swallow{(result_field::_post_bind(target), 0)...}; } + + template + void _apply(Callable& callable) const + { + using swallow = int[]; + (void)swallow{(result_field::_apply(callable), 0)...}; + } + + template + void _apply(const Callable& callable) const + { + using swallow = int[]; + (void)swallow{(result_field::_apply(callable), 0)...}; + } }; } @@ -199,6 +237,18 @@ namespace sqlpp { _impl::_post_bind(target); } + + template + void _apply(Callable& callable) const + { + _impl::_apply(callable); + } + + template + void _apply(const Callable& callable) const + { + _impl::_apply(callable); + } }; template @@ -291,6 +341,32 @@ namespace sqlpp ++index; } } + + template + void _apply(Callable& callable) const + { + _impl::_apply(callable); + + std::size_t index = _field_index_sequence::_next_index; + for (const auto& field_name : _dynamic_field_names) + { + _dynamic_fields.at(field_name)._apply(callable); + ++index; + } + } + + template + void _apply(const Callable& callable) const + { + _impl::_apply(callable); + + std::size_t index = _field_index_sequence::_next_index; + for (const auto& field_name : _dynamic_field_names) + { + _dynamic_fields.at(field_name)._apply(callable); + ++index; + } + } }; template @@ -307,6 +383,18 @@ namespace sqlpp template using is_static_result_row_t = typename is_static_result_row_impl::type; + + template + void for_each_field(const Row& row, const Callable& callable) + { + row._apply(callable); + } + + template + void for_each_field(const Row& row, Callable& callable) + { + row._apply(callable); + } } #endif diff --git a/tests/Select.cpp b/tests/Select.cpp index 54b17639..f8ccd287 100644 --- a/tests/Select.cpp +++ b/tests/Select.cpp @@ -23,14 +23,14 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include "Sample.h" #include "MockDb.h" +#include "Sample.h" #include "is_regular.h" +#include #include -#include -#include #include +#include +#include #include template @@ -43,6 +43,15 @@ int64_t getColumn(Db&& db, const Column& column) return 0; } +struct to_cerr +{ + template + auto operator()(const Field& field) const -> void + { + std::cerr << get_sql_name(field) << " = " << field << std::endl; + } +}; + int Select(int, char* []) { MockDb db = {}; @@ -168,5 +177,10 @@ int Select(int, char* []) std::cerr << row.beta << std::endl; } + for (const auto& row : db(select(all_of(t)).from(t).unconditionally())) + { + for_each_field(row, to_cerr{}); + } + return 0; }