aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-04-08 11:38:51 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-04-10 18:46:44 +0200
commitffdc07d3242e7e9d93f33eb3dc7c294ef79698ff (patch)
tree97bcd50eb2522cbd0d76a6d8118596bbcd83f4a2
parenta4f25daf17392c9c4b90de60b9d777290706f667 (diff)
Write NULL/NOT NULL before DEFAULT in generated schemas
This way we avoid DEFAULT NULL NULL, except for Oracle which insists on a specific order.
-rw-r--r--odb/relational/oracle/schema.cxx20
-rw-r--r--odb/relational/schema.hxx15
2 files changed, 30 insertions, 5 deletions
diff --git a/odb/relational/oracle/schema.cxx b/odb/relational/oracle/schema.cxx
index 298280e..5d0c107 100644
--- a/odb/relational/oracle/schema.cxx
+++ b/odb/relational/oracle/schema.cxx
@@ -214,6 +214,26 @@ namespace relational
create (ac);
}
+
+ virtual void
+ constraints (sema_rel::column& c, sema_rel::primary_key* pk)
+ {
+ // Oracle wants DEFAULT before NULL even though we can end
+ // up with mouthfulls like DEFAULT NULL NULL.
+ //
+ if (!c.default_ ().empty ())
+ os << " DEFAULT " << c.default_ ();
+
+ null (c);
+
+ // If this is a single-column primary key, generate it inline.
+ //
+ if (pk != 0 && pk->contains_size () == 1)
+ primary_key ();
+
+ if (pk != 0 && pk->auto_ ())
+ auto_ (c);
+ }
};
entry<create_column> create_column_;
diff --git a/odb/relational/schema.hxx b/odb/relational/schema.hxx
index 247dca2..ed0084e 100644
--- a/odb/relational/schema.hxx
+++ b/odb/relational/schema.hxx
@@ -515,12 +515,20 @@ namespace relational
os << quote_id (c.name ()) << " ";
type (c, pk != 0 && pk->auto_ ());
+ constraints (c, pk);
- if (!c.default_ ().empty ())
- os << " DEFAULT " << c.default_ ();
+ if (!c.options ().empty ())
+ os << " " << c.options ();
+ }
+ virtual void
+ constraints (sema_rel::column& c, sema_rel::primary_key* pk)
+ {
null (c);
+ if (!c.default_ ().empty ())
+ os << " DEFAULT " << c.default_ ();
+
// If this is a single-column primary key, generate it inline.
//
if (pk != 0 && pk->contains_size () == 1)
@@ -528,9 +536,6 @@ namespace relational
if (pk != 0 && pk->auto_ ())
auto_ (c);
-
- if (!c.options ().empty ())
- os << " " << c.options ();
}
virtual void