summaryrefslogtreecommitdiff
path: root/odb/relational/sqlite
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-10-26 16:41:51 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-10-26 16:41:51 +0200
commit4fd2c107242fe9f8e6ba7ded2a789f4de2ccd040 (patch)
treefe576a167b94e0a2a042758fa011d7140f18612c /odb/relational/sqlite
parent65101f4943e194e5b423099419612d0e38967cdc (diff)
Implement support for mixed auto/manual id assignment in SQLite
Now one can do: #pragma db id auto odb::nullable<int64_t> id; And then set the id to NULL to get auto-assignment or to the actual value to use a manual id.
Diffstat (limited to 'odb/relational/sqlite')
-rw-r--r--odb/relational/sqlite/source.cxx16
1 files changed, 14 insertions, 2 deletions
diff --git a/odb/relational/sqlite/source.cxx b/odb/relational/sqlite/source.cxx
index 2f6623e..072480d 100644
--- a/odb/relational/sqlite/source.cxx
+++ b/odb/relational/sqlite/source.cxx
@@ -412,9 +412,21 @@ 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)
{
- os << im << "null = true;";
+ // Don't set the id value to NULL if this is a nullable wrapper.
+ // This will allow the user to control whether the value is auto or
+ // manually assigned by using something like this:
+ //
+ // #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 << "null = true;"
+ << endl;
}
virtual string