From 5125cad0209640b61007b921637c78504a4924d2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 26 Apr 2013 13:16:57 +0200 Subject: Add --sqlite-override-null option --- odb/options.cli | 9 +++++++++ odb/relational/model.hxx | 14 +++++++++----- odb/relational/sqlite/model.cxx | 6 ++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/odb/options.cli b/odb/options.cli index c3bb908..63bbbb8 100644 --- a/odb/options.cli +++ b/odb/options.cli @@ -961,6 +961,15 @@ class options // SQLite-specific options. // + bool --sqlite-override-null + { + "Make all columns in the generated database schema allow \cb{NULL} + values. This is primarily useful in schema migration since SQLite + does not support dropping of columns. By making all columns \cb{NULL} + we can later \"delete\" them by setting their values to \cb{NULL}. + Note that this option overrides even the \cb{not_null} pragma." + }; + bool --sqlite-lax-auto-id { "Do not force monotonically increasing automatically-assigned diff --git a/odb/relational/model.hxx b/odb/relational/model.hxx index c50b6b5..5936ed1 100644 --- a/odb/relational/model.hxx +++ b/odb/relational/model.hxx @@ -102,20 +102,18 @@ namespace relational virtual bool traverse_column (semantics::data_member& m, string const& name, bool) { - bool id (object_columns_base::id ()); // Id or part of. - bool null (!id && object_columns_base::null ()); - string col_id (id_prefix_ + (key_prefix_.empty () ? m.name () : key_prefix_)); sema_rel::column& c ( - model_.new_node (col_id, column_type (), null)); + model_.new_node ( + col_id, column_type (), null (m))); c.set ("cxx-location", m.location ()); model_.new_edge (table_, c, name); // An id member cannot have a default value. // - if (!id) + if (!object_columns_base::id ()) { string const& d (default_ (m)); @@ -134,6 +132,12 @@ namespace relational return true; } + virtual bool + null (semantics::data_member&) + { + return !object_columns_base::id () && object_columns_base::null (); + } + virtual string default_null (semantics::data_member&) { diff --git a/odb/relational/sqlite/model.cxx b/odb/relational/sqlite/model.cxx index 78977cc..63a5302 100644 --- a/odb/relational/sqlite/model.cxx +++ b/odb/relational/sqlite/model.cxx @@ -23,6 +23,12 @@ namespace relational { object_columns (base const& x): base (x) {} + virtual bool + null (semantics::data_member& m) + { + return options.sqlite_override_null () || base::null (m); + } + virtual string default_enum (semantics::data_member& m, tree en, string const&) { -- cgit v1.1