diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-10-24 16:32:51 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-10-24 16:32:51 +0200 |
commit | 08a47c70ad517b80b72914d47d547463f576bcd3 (patch) | |
tree | 8a6ab07cf05e8668ea3c91735dfe97e2a98f3f05 /odb/generator.cxx | |
parent | a976183dc95a8b7a9bd7a308c3ea94f08982c426 (diff) |
Generate database schema from database model instead of C++ model
We now first create the so-called database model from C++ model and
then use that to generate the database schema. The new approach also
adds more general support for primary/foreign keys, including multi-
column keys. Finally, for MySQL we now generate out-of-line foreign
key definitions. Because MySQL does not support deferred constraints
checking, deferred foreign keys are written commented out, for
documentation.
Diffstat (limited to 'odb/generator.cxx')
-rw-r--r-- | odb/generator.cxx | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/odb/generator.cxx b/odb/generator.cxx index aa56644..6c1fda4 100644 --- a/odb/generator.cxx +++ b/odb/generator.cxx @@ -93,6 +93,32 @@ generate (options const& ops, semantics::unit& unit, path const& p) { try { + // First create the database model. + // + cutl::shared_ptr<semantics::relational::model> model; + + if (ops.generate_schema ()) + { + auto_ptr<context> ctx (create_context (cerr, unit, ops, 0)); + + switch (ops.database ()) + { + case database::mysql: + case database::oracle: + case database::pgsql: + case database::sqlite: + { + model = relational::model::generate (); + break; + } + case database::tracer: + { + cerr << "error: the tracer database does not have schema" << endl; + throw failed (); + } + } + } + // Output files. // path file (p.leaf ()); @@ -196,7 +222,7 @@ generate (options const& ops, semantics::unit& unit, path const& p) // { cxx_filter filt (hxx); - auto_ptr<context> ctx (create_context (hxx, unit, ops)); + auto_ptr<context> ctx (create_context (hxx, unit, ops, model.get ())); string guard (make_guard (gp + hxx_name, *ctx)); @@ -270,7 +296,7 @@ generate (options const& ops, semantics::unit& unit, path const& p) // { cxx_filter filt (ixx); - auto_ptr<context> ctx (create_context (ixx, unit, ops)); + auto_ptr<context> ctx (create_context (ixx, unit, ops, model.get ())); // Copy prologue. // @@ -313,7 +339,7 @@ generate (options const& ops, semantics::unit& unit, path const& p) // { cxx_filter filt (cxx); - auto_ptr<context> ctx (create_context (cxx, unit, ops)); + auto_ptr<context> ctx (create_context (cxx, unit, ops, model.get ())); cxx << "#include <odb/pre.hxx>" << endl << endl; @@ -363,7 +389,7 @@ generate (options const& ops, semantics::unit& unit, path const& p) // if (sql_schema) { - auto_ptr<context> ctx (create_context (sql, unit, ops)); + auto_ptr<context> ctx (create_context (sql, unit, ops, model.get ())); // Copy prologue. // |