aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/statement.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-09-23 11:59:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-09-23 11:59:05 +0200
commit2c24feb3a45019665cf156660e81824750dd6309 (patch)
tree8c82d1dca559af78f88c8a28fd64cdea8a239a1a /odb/mysql/statement.cxx
parentda518dc1ae7e78c753f5ea4fdfa27b140841de5d (diff)
Add swap(), empty(), and size() to result class template
Diffstat (limited to 'odb/mysql/statement.cxx')
-rw-r--r--odb/mysql/statement.cxx33
1 files changed, 27 insertions, 6 deletions
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 <odb/mysql/connection.hxx>
#include <odb/mysql/exceptions.hxx>
-#include <iostream> // @@ 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<std::size_t> (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_);