aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/statement.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-11-26 15:48:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-11-26 15:48:28 +0200
commit61fc247f34255796f5535b52626074b4f92b6bb4 (patch)
tree347d00cedcee85f7d75a5976a210ab07ef33c7be /odb/mysql/statement.cxx
parentba8430c002627705d559b5dd9d78ae7611476520 (diff)
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.
Diffstat (limited to 'odb/mysql/statement.cxx')
-rw-r--r--odb/mysql/statement.cxx29
1 files changed, 9 insertions, 20 deletions
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<size_t> (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<std::size_t> (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: