diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-07-19 13:42:18 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-07-19 13:42:18 +0200 |
commit | 73c98a67ef4ed605cf69e0d212934c4dc1f3eb8e (patch) | |
tree | 8645cd8d06f218ff5d945b1b3b94a58a127753c4 /odb/relational/mysql | |
parent | 12d0d9bbd0f5b7295c50fd5b223e538afe1abbf7 (diff) |
New design for NULL semantics
Now, instead of being specified as part of the SQL type with the type
pragma, there are separate null and not_null pragmas. The not_null
pragma was used to control NULL-ness of object pointers. Now the two
pragmas are used consistently for object pointers and simple values
(and in the future will work for composite values and containers).
Diffstat (limited to 'odb/relational/mysql')
-rw-r--r-- | odb/relational/mysql/context.cxx | 10 | ||||
-rw-r--r-- | odb/relational/mysql/context.hxx | 5 | ||||
-rw-r--r-- | odb/relational/mysql/schema.cxx | 18 | ||||
-rw-r--r-- | odb/relational/mysql/source.cxx | 4 |
4 files changed, 22 insertions, 15 deletions
diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx index e9446c2..431470a 100644 --- a/odb/relational/mysql/context.cxx +++ b/odb/relational/mysql/context.cxx @@ -234,12 +234,9 @@ namespace relational } string context:: - database_type_impl (semantics::type& t, - semantics::names* hint, - semantics::context& ctx, - column_type_flags f) + database_type_impl (semantics::type& t, semantics::names* hint, bool id) { - string r (base_context::database_type_impl (t, hint, ctx, f)); + string r (base_context::database_type_impl (t, hint, id)); if (!r.empty ()) return r; @@ -290,9 +287,6 @@ namespace relational if (e->unsigned_ ()) r += " UNSIGNED"; } - - if ((f & ctf_default_null) == 0) - r += " NOT NULL"; } return r; diff --git a/odb/relational/mysql/context.hxx b/odb/relational/mysql/context.hxx index 019b878..00ebe57 100644 --- a/odb/relational/mysql/context.hxx +++ b/odb/relational/mysql/context.hxx @@ -97,10 +97,7 @@ namespace relational protected: virtual string - database_type_impl (semantics::type&, - semantics::names*, - semantics::context&, - column_type_flags); + database_type_impl (semantics::type&, semantics::names*, bool); public: virtual diff --git a/odb/relational/mysql/schema.cxx b/odb/relational/mysql/schema.cxx index 0b44c53..3848c75 100644 --- a/odb/relational/mysql/schema.cxx +++ b/odb/relational/mysql/schema.cxx @@ -37,11 +37,27 @@ namespace relational } }; - struct object_columns: relational::object_columns + struct object_columns: relational::object_columns, context { object_columns (base const& x): base (x) {} virtual void + null (semantics::data_member& m) + { + if (!context::null (m, prefix_)) + os << " NOT NULL"; + else + { + // MySQL TIMESTAMP is by default NOT NULL. If we want it + // to contain NULL values, we need to explicitly declare + // the column as NULL. + // + if (column_sql_type (m, prefix_).type == sql_type::TIMESTAMP) + os << " NULL"; + } + } + + virtual void constraints (semantics::data_member& m) { base::constraints (m); diff --git a/odb/relational/mysql/source.cxx b/odb/relational/mysql/source.cxx index 17bffdc..d3b4129 100644 --- a/odb/relational/mysql/source.cxx +++ b/odb/relational/mysql/source.cxx @@ -588,7 +588,7 @@ namespace relational { os << "}"; - if (!null_pointer (mi.m, key_prefix_)) + if (!null (mi.m, key_prefix_)) os << "else" << endl << "throw null_pointer ();"; } @@ -786,7 +786,7 @@ namespace relational << endl << "if (i." << mi.var << "null)" << endl; - if (null_pointer (mi.m, key_prefix_)) + if (null (mi.m, key_prefix_)) os << member << " = ptr_traits::pointer_type ();"; else os << "throw null_pointer ();"; |