diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-10-15 11:33:40 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-10-21 19:25:06 +0200 |
commit | 6508eb18a20a2f0bc48374f3f0a352f1195cc95b (patch) | |
tree | 0aaf5a65d82b7d58721b0020c17885d16f178b3e /odb/relational/mysql | |
parent | b2f0cd834b8f5651985357f8acbe82edd7d11c63 (diff) |
Add support for readonly members
New pragma: readonly. New test: readonly.
Diffstat (limited to 'odb/relational/mysql')
-rw-r--r-- | odb/relational/mysql/source.cxx | 74 |
1 files changed, 56 insertions, 18 deletions
diff --git a/odb/relational/mysql/source.cxx b/odb/relational/mysql/source.cxx index 103c301..25fac41 100644 --- a/odb/relational/mysql/source.cxx +++ b/odb/relational/mysql/source.cxx @@ -200,9 +200,19 @@ namespace relational if (inverse (mi.m, key_prefix_)) os << "if (sk == statement_select)" << "{"; - else if (id (mi.m) || readonly (mi.m)) - os << "if (sk != statement_update)" - << "{"; + // If the whole class is readonly, then we will never be + // called with sk == statement_update. + // + else if (!readonly (*context::top_object)) + { + semantics::class_* c; + + if (id (mi.m) || + readonly (mi.m) || + ((c = composite (mi.t)) && readonly (*c))) + os << "if (sk != statement_update)" + << "{"; + } } return true; @@ -213,8 +223,11 @@ namespace relational { if (var_override_.empty ()) { - if (semantics::class_* c = composite (mi.t)) + semantics::class_* c; + + if ((c = composite (mi.t))) { + bool ro (readonly (*c)); column_count_type const& cc (column_count (*c)); os << "n += " << cc.total << "UL"; @@ -223,7 +236,7 @@ namespace relational // insert = total - inverse // update = total - inverse - readonly // - if (cc.inverse != 0 || cc.readonly != 0) + if (cc.inverse != 0 || (!ro && cc.readonly != 0)) { os << " - (" << endl << "sk == statement_select ? 0 : "; @@ -231,7 +244,7 @@ namespace relational if (cc.inverse != 0) os << cc.inverse << "UL" << endl; - if (cc.readonly != 0) + if (!ro && cc.readonly != 0) { if (cc.inverse != 0) os << " + "; @@ -249,7 +262,23 @@ namespace relational else os << "n++;"; - if (inverse (mi.m, key_prefix_) || id (mi.m) || readonly (mi.m)) + bool block (false); + + // The same logic as in pre(). + // + if (inverse (mi.m, key_prefix_)) + block = true; + else if (!readonly (*context::top_object)) + { + semantics::class_* c; + + if (id (mi.m) || + readonly (mi.m) || + ((c = composite (mi.t)) && readonly (*c))) + block = true; + } + + if (block) os << "}"; else os << endl; @@ -564,10 +593,18 @@ namespace relational os << "// " << name << endl << "//" << endl; - if (id (mi.m) || readonly (mi.m)) - // The block scope is added later, if necessary. - // - os << "if (sk == statement_insert)"; + // If the whole class is readonly, then we will never be + // called with sk == statement_update. + // + if (!readonly (*context::top_object)) + { + semantics::class_* c; + + if (id (mi.m) || + readonly (mi.m) || + ((c = composite (mi.t)) && readonly (*c))) + os << "if (sk == statement_insert)"; + } } // If this is a wrapped composite value, then we need to @@ -583,7 +620,10 @@ namespace relational } if (composite (mi.t)) + { + os << "{"; traits = "composite_value_traits< " + mi.fq_type () + " >"; + } else { // When handling a pointer, mi.t is the id type of the referenced @@ -655,7 +695,9 @@ namespace relational virtual void post (member_info& mi) { - if (!composite (mi.t)) + if (composite (mi.t)) + os << "}"; + else { // When handling a pointer, mi.t is the id type of the referenced // object. @@ -677,15 +719,11 @@ namespace relational virtual void traverse_composite (member_info& mi) { - // Should be a single statement or a block. - // os << "if (" << traits << "::init (" << endl << "i." << mi.var << "value," << endl << member << "," << endl - << "sk))" - << "{" - << "grew = true;" - << "}"; + << "sk))" << endl + << "grew = true;"; } virtual void |