From 61fc247f34255796f5535b52626074b4f92b6bb4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 26 Nov 2010 15:48:28 +0200 Subject: Postpone fetching of the data for cached results This way if an object of the same type is loaded in between iteration, the fetched image won't be messed up. --- odb/mysql/statement.cxx | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'odb/mysql/statement.cxx') diff --git a/odb/mysql/statement.cxx b/odb/mysql/statement.cxx index 0f21917..6edfa16 100644 --- a/odb/mysql/statement.cxx +++ b/odb/mysql/statement.cxx @@ -126,27 +126,20 @@ namespace odb if (!end_) { if (mysql_stmt_store_result (stmt_)) - { throw database_exception (stmt_); - } + + // mysql_stmt_num_rows() returns the number of rows that have been + // fetched by store_result. + // + size_ = rows_ + static_cast (mysql_stmt_num_rows (stmt_)); } + else + size_ = rows_; cached_ = true; } } - std::size_t select_statement:: - result_size () - { - if (!cached_) - throw result_not_cached (); - - // mysql_stmt_num_rows() returns the number of rows that have been - // fetched by store_result. - // - return rows_ + static_cast (mysql_stmt_num_rows (stmt_)); - } - select_statement::result select_statement:: fetch () { @@ -167,9 +160,7 @@ namespace odb { case 0: { - if (!cached_) - rows_++; - + rows_++; return success; } case MYSQL_NO_DATA: @@ -179,9 +170,7 @@ namespace odb } case MYSQL_DATA_TRUNCATED: { - if (!cached_) - rows_++; - + rows_++; return truncated; } default: -- cgit v1.1