From 17e48b8980d89f0c5c3a00d4066c764093838e5a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 5 Apr 2013 10:51:03 +0200 Subject: Explicitly specify NULL for nullable columns in generated schema --- NEWS | 3 +++ odb/relational/mysql/schema.cxx | 23 ----------------------- odb/relational/schema.hxx | 6 ++++-- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/NEWS b/NEWS index a7cad45..c6b2db3 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,9 @@ Version 2.3.0 * The --output-name option has been renamed to --input-name, which is more semantically correct. + * The generated database schemas now explicitly specify NULL for nullable + columns. + Version 2.2.0 * Multi-database support. This mechanism allows an application to diff --git a/odb/relational/mysql/schema.cxx b/odb/relational/mysql/schema.cxx index 6ce619b..2ae47ae 100644 --- a/odb/relational/mysql/schema.cxx +++ b/odb/relational/mysql/schema.cxx @@ -143,29 +143,6 @@ namespace relational create_column (base const& x): base (x) {} virtual void - null (sema_rel::column& c) - { - // 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 (c.null ()) - { - // This should never fail since we have already parsed this. - // - sql_type const& t (parse_sql_type (c.type ())); - - if (t.type == sql_type::TIMESTAMP) - { - os << " NULL"; - return; - } - } - - base::null (c); - } - - virtual void auto_ (sema_rel::column&) { os << " AUTO_INCREMENT"; diff --git a/odb/relational/schema.hxx b/odb/relational/schema.hxx index 69e8089..fcb176f 100644 --- a/odb/relational/schema.hxx +++ b/odb/relational/schema.hxx @@ -410,8 +410,10 @@ namespace relational virtual void null (sema_rel::column& c) { - if (!c.null ()) - os << " NOT NULL"; + // Specify both cases explicitly for better readability, + // especially in ALTER COLUMN clauses. + // + os << (c.null () ? " NULL" : " NOT NULL"); } virtual void -- cgit v1.1