From add8086259fb21f1e42aba6546c55e607d87ce93 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 11 Mar 2011 14:24:25 +0200 Subject: Infrastructure setup and schema generation for SQLite --- odb/generator.cxx | 90 +++++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 50 deletions(-) (limited to 'odb/generator.cxx') diff --git a/odb/generator.cxx b/odb/generator.cxx index a6431ed..60f8e2a 100644 --- a/odb/generator.cxx +++ b/odb/generator.cxx @@ -24,6 +24,7 @@ #include #include +#include using namespace std; using namespace cutl; @@ -96,6 +97,33 @@ generator () { } +static auto_ptr +create_context (ostream& os, semantics::unit& unit, options const& ops) +{ + auto_ptr r; + + switch (ops.database ()) + { + case database::mysql: + { + r.reset (new relational::mysql::context (os, unit, ops)); + break; + } + case database::sqlite: + { + r.reset (new relational::sqlite::context (os, unit, ops)); + break; + } + case database::tracer: + { + r.reset (new context (os, unit, ops)); + break; + } + } + + return r; +} + void generator:: generate (options const& ops, semantics::unit& unit, path const& p) { @@ -103,24 +131,10 @@ generate (options const& ops, semantics::unit& unit, path const& p) { // Process types. // + if (ops.database () != database::tracer) { - auto_ptr ctx; - - switch (ops.database ()) - { - case database::mysql: - { - ctx.reset (new relational::mysql::context (cerr, unit, ops)); - break; - } - case database::tracer: - { - break; - } - } - - if (ctx.get () != 0) - relational::process_types (); + auto_ptr ctx (create_context (cerr, unit, ops)); + relational::process_types (); } // Output files. @@ -232,21 +246,7 @@ generate (options const& ops, semantics::unit& unit, path const& p) // { cxx_filter filt (hxx); - auto_ptr ctx; - - switch (ops.database ()) - { - case database::mysql: - { - ctx.reset (new relational::mysql::context (hxx, unit, ops)); - break; - } - case database::tracer: - { - ctx.reset (new context (hxx, unit, ops)); - break; - } - } + auto_ptr ctx (create_context (hxx, unit, ops)); string guard (make_guard (gp + hxx_name, *ctx)); @@ -285,6 +285,7 @@ generate (options const& ops, semantics::unit& unit, path const& p) switch (ops.database ()) { case database::mysql: + case database::sqlite: { relational::header::generate (); break; @@ -319,21 +320,7 @@ generate (options const& ops, semantics::unit& unit, path const& p) // { cxx_filter filt (ixx); - auto_ptr ctx; - - switch (ops.database ()) - { - case database::mysql: - { - ctx.reset (new relational::mysql::context (ixx, unit, ops)); - break; - } - case database::tracer: - { - ctx.reset (new context (ixx, unit, ops)); - break; - } - } + auto_ptr ctx (create_context (ixx, unit, ops)); // Copy prologue. // @@ -349,6 +336,7 @@ generate (options const& ops, semantics::unit& unit, path const& p) switch (ops.database ()) { case database::mysql: + case database::sqlite: { relational::inline_::generate (); break; @@ -373,6 +361,7 @@ generate (options const& ops, semantics::unit& unit, path const& p) // { cxx_filter filt (cxx); + auto_ptr ctx (create_context (cxx, unit, ops)); cxx << "#include " << endl << endl; @@ -393,14 +382,13 @@ generate (options const& ops, semantics::unit& unit, path const& p) switch (ops.database ()) { case database::mysql: + case database::sqlite: { - relational::mysql::context ctx (cxx, unit, ops); relational::source::generate (); break; } case database::tracer: { - context ctx (cxx, unit, ops); tracer::source::generate (); break; } @@ -422,6 +410,8 @@ generate (options const& ops, semantics::unit& unit, path const& p) // if (sql_schema) { + auto_ptr ctx (create_context (sql, unit, ops)); + // Copy prologue. // append (sql, ops.sql_prologue (), ops.sql_prologue_file ()); @@ -429,8 +419,8 @@ generate (options const& ops, semantics::unit& unit, path const& p) switch (ops.database ()) { case database::mysql: + case database::sqlite: { - relational::mysql::context ctx (sql, unit, ops); relational::schema::generate (); break; } -- cgit v1.1