aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-03-27 15:34:27 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-03-27 15:34:27 +0200
commitbff376808a7684dc8c3752ee84a25f47b75f7075 (patch)
tree3f1268b2982f14349da301abcb2ee124edefcfe6
parent7e8e204a812cf551e735fc02e2e8a827304d085e (diff)
Implement support for mixed auto/0 id assignment in MySQL
Now one can do: odb::nullable<int64_t> id; And then, when used with NO_AUTO_VALUE_ON_ZERO, set the id to NULL to get auto-assignment or to 0 to use 0 as the id.
-rw-r--r--odb/relational/mysql/source.cxx13
1 files changed, 12 insertions, 1 deletions
diff --git a/odb/relational/mysql/source.cxx b/odb/relational/mysql/source.cxx
index 2ff630c..21ae9de 100644
--- a/odb/relational/mysql/source.cxx
+++ b/odb/relational/mysql/source.cxx
@@ -677,8 +677,19 @@ namespace relational
class_ (base const& x): base (x) {}
virtual void
- init_auto_id (semantics::data_member&, string const& im)
+ init_auto_id (semantics::data_member& m, string const& im)
{
+ // Don't set the id value to 0 if this is a nullable wrapper. This
+ // will allow the user to use the NO_AUTO_VALUE_ON_ZERO mode by
+ // making it NULL when they want the auto semantics:
+ //
+ // #pragma db auto
+ // odb::nullable<int64_t> id;
+ //
+ semantics::type& t (utype (m));
+ if (wrapper (t) && t.template get<bool> ("wrapper-null-handler"))
+ return;
+
os << im << "value = 0;"
<< endl;
}