From 2c24feb3a45019665cf156660e81824750dd6309 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 23 Sep 2010 11:59:05 +0200 Subject: Add swap(), empty(), and size() to result class template --- odb/mysql/statement.cxx | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'odb/mysql/statement.cxx') diff --git a/odb/mysql/statement.cxx b/odb/mysql/statement.cxx index 1e822b0..6193f39 100644 --- a/odb/mysql/statement.cxx +++ b/odb/mysql/statement.cxx @@ -8,8 +8,6 @@ #include #include -#include // @@ tmp - using namespace std; namespace odb @@ -68,6 +66,7 @@ namespace odb : statement (conn), end_ (false), cached_ (false), + rows_ (0), image_ (image), image_version_ (0), parameters_ (parameters) @@ -89,6 +88,7 @@ namespace odb free_result (); end_ = false; + rows_ = 0; if (mysql_stmt_reset (stmt_)) throw database_exception (stmt_); @@ -125,18 +125,32 @@ namespace odb void query_statement:: cache () { - if (!cached_ && !end_) + if (!cached_) { - if (mysql_stmt_store_result (stmt_)) + if (!end_) { - std::cerr << "store result failed" << std::endl; - throw database_exception (stmt_); + if (mysql_stmt_store_result (stmt_)) + { + throw database_exception (stmt_); + } } cached_ = true; } } + std::size_t query_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_)); + } + query_statement::result query_statement:: fetch () { @@ -157,6 +171,9 @@ namespace odb { case 0: { + if (!cached_) + rows_++; + return success; } case MYSQL_NO_DATA: @@ -166,6 +183,9 @@ namespace odb } case MYSQL_DATA_TRUNCATED: { + if (!cached_) + rows_++; + return truncated; } default: @@ -198,6 +218,7 @@ namespace odb { end_ = true; cached_ = false; + rows_ = 0; if (mysql_stmt_free_result (stmt_)) throw database_exception (stmt_); -- cgit v1.1