From 80e573568e1a7274a796a29e5b85603d2608c136 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sat, 17 Aug 2013 11:26:58 +0200 Subject: [PATCH] Fixed result to not consume rows with operator* and operator-> --- include/sqlpp11/result.h | 46 +++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/include/sqlpp11/result.h b/include/sqlpp11/result.h index 81e09c1c..cf5cc4b0 100644 --- a/include/sqlpp11/result.h +++ b/include/sqlpp11/result.h @@ -34,28 +34,36 @@ namespace sqlpp { template - struct result_t + class result_t { - using db_result_t = typename Db::result; + using db_result_t = typename Db::_result; + db_result_t _result; + raw_result_row_t _raw_result_row; + raw_result_row_t _end; + + public: + result_t(db_result_t&& result): + _result(std::forward(result)), + _raw_result_row(_result.next()), + _end({}) + {} + + result_t(const result_t&) = delete; + result_t(result_t&&) = default; + result_t& operator=(const result_t&) = delete; + result_t& operator=(result_t&&) = default; + // Iterator class iterator { public: - iterator(db_result_t& result): - _result(result), - _raw_result_row({}), - _result_row(_raw_result_row) - { - std::cerr << "result::iterator::end-constructor" << std::endl; - } - - iterator(db_result_t& result, const raw_result_row_t& raw_result_row): + iterator(db_result_t& result, raw_result_row_t& raw_result_row): _result(result), _raw_result_row(raw_result_row), _result_row(_raw_result_row) { - std::cerr << "result::iterator::begin-constructor" << std::endl; + std::cerr << "result::iterator::constructor" << std::endl; } const ResultRow& operator*() const @@ -85,23 +93,28 @@ namespace sqlpp } db_result_t& _result; - raw_result_row_t _raw_result_row; + raw_result_row_t& _raw_result_row; ResultRow _result_row; }; + size_t size() const + { + return _result.num_rows(); + } + iterator begin() { - return iterator(_result, _result.next()); + return iterator(_result, _raw_result_row); } iterator end() { - return _result; + return iterator(_result, _end); } const ResultRow operator*() { - return {_result.next()}; + return {_raw_result_row}; } iterator operator->() @@ -109,7 +122,6 @@ namespace sqlpp return begin(); } - db_result_t _result; }; }