aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/mysql/object-statements.hxx14
-rw-r--r--odb/mysql/object-statements.txx4
-rw-r--r--odb/mysql/statement.cxx82
-rw-r--r--odb/mysql/statement.hxx38
4 files changed, 67 insertions, 71 deletions
diff --git a/odb/mysql/object-statements.hxx b/odb/mysql/object-statements.hxx
index 9ea9933..0c20b1b 100644
--- a/odb/mysql/object-statements.hxx
+++ b/odb/mysql/object-statements.hxx
@@ -219,6 +219,12 @@ namespace odb
void
update_image_version (std::size_t v) {update_image_version_ = v;}
+ std::size_t
+ update_id_image_version () const { return update_id_image_version_;}
+
+ void
+ update_id_image_version (std::size_t v) {update_id_image_version_ = v;}
+
binding&
update_image_binding () {return update_image_binding_;}
@@ -287,7 +293,6 @@ namespace odb
new (details::shared) update_statement_type (
conn_,
object_traits::update_statement,
- id_image_binding_,
update_image_binding_));
return *update_;
@@ -360,10 +365,13 @@ namespace odb
binding insert_image_binding_;
MYSQL_BIND insert_image_bind_[insert_column_count];
- // Update binding. The suffix of the bind array is object id. The
- // update statement depends on this being one contiguous arrays.
+ // Update binding. Note that the id suffix is bound to id_image_
+ // below instead of image_ which makes this binding effectively
+ // bound to two images. As a result, we have to track versions
+ // for both of them.
//
std::size_t update_image_version_;
+ std::size_t update_id_image_version_;
binding update_image_binding_;
MYSQL_BIND update_image_bind_[update_column_count + id_column_count];
diff --git a/odb/mysql/object-statements.txx b/odb/mysql/object-statements.txx
index 372118d..cf95a4a 100644
--- a/odb/mysql/object-statements.txx
+++ b/odb/mysql/object-statements.txx
@@ -33,7 +33,8 @@ namespace odb
container_statement_cache_ (conn),
select_image_binding_ (select_image_bind_, select_column_count),
insert_image_binding_ (insert_image_bind_, insert_column_count),
- update_image_binding_ (update_image_bind_, update_column_count),
+ update_image_binding_ (update_image_bind_,
+ update_column_count + id_column_count),
id_image_binding_ (update_image_bind_ + update_column_count,
id_column_count)
{
@@ -41,6 +42,7 @@ namespace odb
select_image_version_ = 0;
insert_image_version_ = 0;
update_image_version_ = 0;
+ update_id_image_version_ = 0;
id_image_.version = 0;
id_image_version_ = 0;
diff --git a/odb/mysql/statement.cxx b/odb/mysql/statement.cxx
index d4b5431..7aa036d 100644
--- a/odb/mysql/statement.cxx
+++ b/odb/mysql/statement.cxx
@@ -64,16 +64,16 @@ namespace odb
select_statement::
select_statement (connection& conn,
const string& s,
- binding& cond,
- binding& data)
+ binding& param,
+ binding& result)
: statement (conn),
end_ (false),
cached_ (false),
rows_ (0),
- cond_ (&cond),
- cond_version_ (0),
- data_ (data),
- data_version_ (0)
+ param_ (&param),
+ param_version_ (0),
+ result_ (result),
+ result_version_ (0)
{
conn_.clear ();
@@ -82,14 +82,14 @@ namespace odb
}
select_statement::
- select_statement (connection& conn, const string& s, binding& data)
+ select_statement (connection& conn, const string& s, binding& result)
: statement (conn),
end_ (false),
cached_ (false),
rows_ (0),
- cond_ (0),
- data_ (data),
- data_version_ (0)
+ param_ (0),
+ result_ (result),
+ result_version_ (0)
{
conn_.clear ();
@@ -111,12 +111,12 @@ namespace odb
if (mysql_stmt_reset (stmt_))
translate_error (conn_, stmt_);
- if (cond_ != 0 && cond_version_ != cond_->version)
+ if (param_ != 0 && param_version_ != param_->version)
{
- if (mysql_stmt_bind_param (stmt_, cond_->bind))
+ if (mysql_stmt_bind_param (stmt_, param_->bind))
translate_error (conn_, stmt_);
- cond_version_ = cond_->version;
+ param_version_ = param_->version;
}
if (mysql_stmt_execute (stmt_))
@@ -150,19 +150,19 @@ namespace odb
select_statement::result select_statement::
fetch ()
{
- if (data_version_ != data_.version)
+ if (result_version_ != result_.version)
{
// Make sure that the number of columns in the result returned by
// the database matches the number that we expect. A common cause
// of this assertion is a native view with a number of data members
// not matching the number of columns in the SELECT-list.
//
- assert (mysql_stmt_field_count (stmt_) == data_.count);
+ assert (mysql_stmt_field_count (stmt_) == result_.count);
- if (mysql_stmt_bind_result (stmt_, data_.bind))
+ if (mysql_stmt_bind_result (stmt_, result_.bind))
translate_error (conn_, stmt_);
- data_version_ = data_.version;
+ result_version_ = result_.version;
}
int r (mysql_stmt_fetch (stmt_));
@@ -197,14 +197,14 @@ namespace odb
{
// Re-fetch columns that were truncated.
//
- for (size_t i (0); i < data_.count; ++i)
+ for (size_t i (0); i < result_.count; ++i)
{
- if (*data_.bind[i].error)
+ if (*result_.bind[i].error)
{
- *data_.bind[i].error = 0;
+ *result_.bind[i].error = 0;
if (mysql_stmt_fetch_column (
- stmt_, data_.bind + i, static_cast<unsigned int> (i), 0))
+ stmt_, result_.bind + i, static_cast<unsigned int> (i), 0))
translate_error (conn_, stmt_);
}
}
@@ -244,8 +244,8 @@ namespace odb
}
insert_statement::
- insert_statement (connection& conn, const string& s, binding& data)
- : statement (conn), data_ (data), data_version_ (0)
+ insert_statement (connection& conn, const string& s, binding& param)
+ : statement (conn), param_ (param), param_version_ (0)
{
conn_.clear ();
@@ -261,12 +261,12 @@ namespace odb
if (mysql_stmt_reset (stmt_))
translate_error (conn_, stmt_);
- if (data_version_ != data_.version)
+ if (param_version_ != param_.version)
{
- if (mysql_stmt_bind_param (stmt_, data_.bind))
+ if (mysql_stmt_bind_param (stmt_, param_.bind))
translate_error (conn_, stmt_);
- data_version_ = data_.version;
+ param_version_ = param_.version;
}
if (mysql_stmt_execute (stmt_))
@@ -295,15 +295,8 @@ namespace odb
}
update_statement::
- update_statement (connection& conn,
- const string& s,
- binding& cond,
- binding& data)
- : statement (conn),
- cond_ (cond),
- cond_version_ (0),
- data_ (data),
- data_version_ (0)
+ update_statement (connection& conn, const string& s, binding& param)
+ : statement (conn), param_ (param), param_version_ (0)
{
conn_.clear ();
@@ -319,15 +312,12 @@ namespace odb
if (mysql_stmt_reset (stmt_))
translate_error (conn_, stmt_);
- if (data_version_ != data_.version || cond_version_ != cond_.version)
+ if (param_version_ != param_.version)
{
- // Here we assume that cond_.bind is a suffix of data_.bind.
- //
- if (mysql_stmt_bind_param (stmt_, data_.bind))
+ if (mysql_stmt_bind_param (stmt_, param_.bind))
translate_error (conn_, stmt_);
- cond_version_ = cond_.version;
- data_version_ = data_.version;
+ param_version_ = param_.version;
}
if (mysql_stmt_execute (stmt_))
@@ -353,8 +343,8 @@ namespace odb
}
delete_statement::
- delete_statement (connection& conn, const string& s, binding& cond)
- : statement (conn), cond_ (cond), cond_version_ (0)
+ delete_statement (connection& conn, const string& s, binding& param)
+ : statement (conn), param_ (param), param_version_ (0)
{
conn_.clear ();
@@ -370,12 +360,12 @@ namespace odb
if (mysql_stmt_reset (stmt_))
translate_error (conn_, stmt_);
- if (cond_version_ != cond_.version)
+ if (param_version_ != param_.version)
{
- if (mysql_stmt_bind_param (stmt_, cond_.bind))
+ if (mysql_stmt_bind_param (stmt_, param_.bind))
translate_error (conn_, stmt_);
- cond_version_ = cond_.version;
+ param_version_ = param_.version;
}
if (mysql_stmt_execute (stmt_))
diff --git a/odb/mysql/statement.hxx b/odb/mysql/statement.hxx
index 0c15f8c..55850b6 100644
--- a/odb/mysql/statement.hxx
+++ b/odb/mysql/statement.hxx
@@ -55,12 +55,12 @@ namespace odb
select_statement (connection& conn,
const std::string& statement,
- binding& cond,
- binding& data);
+ binding& param,
+ binding& result);
select_statement (connection& conn,
const std::string& statement,
- binding& data);
+ binding& result);
enum result
{
@@ -119,11 +119,11 @@ namespace odb
std::size_t rows_;
std::size_t size_;
- binding* cond_;
- std::size_t cond_version_;
+ binding* param_;
+ std::size_t param_version_;
- binding& data_;
- std::size_t data_version_;
+ binding& result_;
+ std::size_t result_version_;
};
class LIBODB_MYSQL_EXPORT insert_statement: public statement
@@ -134,7 +134,7 @@ namespace odb
insert_statement (connection& conn,
const std::string& statement,
- binding& data);
+ binding& param);
// Return true if successful and false if the row is a duplicate.
// All other errors are reported by throwing exceptions.
@@ -150,8 +150,8 @@ namespace odb
insert_statement& operator= (const insert_statement&);
private:
- binding& data_;
- std::size_t data_version_;
+ binding& param_;
+ std::size_t param_version_;
};
class LIBODB_MYSQL_EXPORT update_statement: public statement
@@ -160,12 +160,11 @@ namespace odb
virtual
~update_statement ();
- // Asssumes that cond.bind is a suffix of data.bind.
+ // Asssumes that param.bind is a suffix of data.bind.
//
update_statement (connection& conn,
const std::string& statement,
- binding& cond,
- binding& data);
+ binding& param);
void
execute ();
@@ -174,11 +173,8 @@ namespace odb
update_statement& operator= (const update_statement&);
private:
- binding& cond_;
- std::size_t cond_version_;
-
- binding& data_;
- std::size_t data_version_;
+ binding& param_;
+ std::size_t param_version_;
};
class LIBODB_MYSQL_EXPORT delete_statement: public statement
@@ -189,7 +185,7 @@ namespace odb
delete_statement (connection& conn,
const std::string& statement,
- binding& cond);
+ binding& param);
unsigned long long
execute ();
@@ -199,8 +195,8 @@ namespace odb
delete_statement& operator= (const delete_statement&);
private:
- binding& cond_;
- std::size_t cond_version_;
+ binding& param_;
+ std::size_t param_version_;
};
}
}