aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-10-30 17:52:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-11-01 14:30:22 +0200
commitc11ace0f4a665ac0dfb269860ef04dce284b75f5 (patch)
treeb32c1c7380260e0c69988d614063bfd17a1a3493
parent139d9cad5830521e7dc0a60d8e6334d27533036c (diff)
Rework statement interfaces wrt param/result passing
-rw-r--r--odb/relational/source.hxx48
1 files changed, 31 insertions, 17 deletions
diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx
index 6296f74..dcc9c23 100644
--- a/odb/relational/source.hxx
+++ b/odb/relational/source.hxx
@@ -2716,36 +2716,50 @@ namespace relational
if (cc.total != cc.id + cc.inverse + cc.readonly)
{
- // Initialize id image.
+ // Initialize object and id images.
//
os << "id_image_type& i (sts.id_image ());"
<< "init (i, obj." << id->name () << ");"
+ << endl
+ << "image_type& im (sts.image ());"
+ << "if (init (im, obj, statement_update))" << endl
+ << "im.version++;"
<< endl;
- os << "binding& idb (sts.id_image_binding ());"
- << "if (i.version != sts.id_image_version () || idb.version == 0)"
- << "{"
- << "bind (idb.bind, i);"
- << "sts.id_image_version (i.version);"
- << "idb.version++;"
- << "}";
-
- // Initialize data image.
+ // Update binding is bound to two images (object and id)
+ // so we have to track both versions.
//
- os << "image_type& im (sts.image ());"
+ os << "bool u (false);" // Avoid incrementing version twice.
<< "binding& imb (sts.update_image_binding ());"
- << endl
- << "if (init (im, obj, statement_update))" << endl
- << "im.version++;"
- << endl
<< "if (im.version != sts.update_image_version () || " <<
"imb.version == 0)"
<< "{"
<< "bind (imb.bind, im, statement_update);"
<< "sts.update_image_version (im.version);"
<< "imb.version++;"
- << "}"
- << "sts.update_statement ().execute ();";
+ << "u = true;"
+ << "}";
+
+ // To update the id part of the update binding we have to do
+ // it indirectly via the id binding, which just points to the
+ // suffix of the update bind array (see object_statements).
+ //
+ os << "binding& idb (sts.id_image_binding ());"
+ << "if (i.version != sts.update_id_image_version () || " <<
+ "idb.version == 0)"
+ << "{"
+ << "bind (idb.bind, i);"
+ << "sts.update_id_image_version (i.version);"
+ << "if (!u)" << endl
+ << "imb.version++;"
+ << endl
+ // Update the id binding versions since we rebound it.
+ //
+ << "sts.id_image_version (i.version);"
+ << "idb.version++;"
+ << "}";
+
+ os << "sts.update_statement ().execute ();";
}
else
{