From bff376808a7684dc8c3752ee84a25f47b75f7075 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Mar 2017 15:34:27 +0200 Subject: Implement support for mixed auto/0 id assignment in MySQL Now one can do: odb::nullable 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. --- odb/relational/mysql/source.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'odb') 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 id; + // + semantics::type& t (utype (m)); + if (wrapper (t) && t.template get ("wrapper-null-handler")) + return; + os << im << "value = 0;" << endl; } -- cgit v1.1