aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-04-05 10:51:03 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-04-10 18:46:44 +0200
commit17e48b8980d89f0c5c3a00d4066c764093838e5a (patch)
tree2c48164e1a1f9b34cc4cfde2a531f29f7f13a7fb
parent853d76b58e96aab4e6182cc1234652dfcdd74c14 (diff)
Explicitly specify NULL for nullable columns in generated schema
-rw-r--r--NEWS3
-rw-r--r--odb/relational/mysql/schema.cxx23
-rw-r--r--odb/relational/schema.hxx6
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