aboutsummaryrefslogtreecommitdiff
path: root/odb/option-functions.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-10-25 10:35:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-10-25 10:35:36 +0200
commitd1ad30f7a517e69bc87d1347224f1c9ab38493b3 (patch)
tree95189ae91fcce6366f0a121f67b483f3c1b962e7 /odb/option-functions.cxx
parent7fc555e53f0a03c93fe31ad9850b1e5d885c44f6 (diff)
Static multi-database support
Add new options (--multi-database, --default-database). Generate common code to -odb.?xx files and database-specific to -odb-<db>.?xx.
Diffstat (limited to 'odb/option-functions.cxx')
-rw-r--r--odb/option-functions.cxx61
1 files changed, 60 insertions, 1 deletions
diff --git a/odb/option-functions.cxx b/odb/option-functions.cxx
index 6b7442e..aca4943 100644
--- a/odb/option-functions.cxx
+++ b/odb/option-functions.cxx
@@ -3,6 +3,7 @@
// license : GNU GPL v3; see accompanying LICENSE file
#include <set>
+#include <utility> // std::make_pair()
#include <odb/option-functions.hxx>
@@ -11,6 +12,8 @@ using namespace std;
void
process_options (options& o)
{
+ database db (o.database ()[0]);
+
// If --generate-schema-only was specified, then set --generate-schema
// as well.
//
@@ -23,8 +26,12 @@ process_options (options& o)
{
set<schema_format> f;
- switch (o.database ())
+ switch (db)
{
+ case database::common:
+ {
+ break; // No schema for common.
+ }
case database::mssql:
case database::mysql:
case database::oracle:
@@ -42,4 +49,56 @@ process_options (options& o)
o.schema_format (f);
}
+
+ // Set default --*--file-suffix values.
+ //
+ {
+ database cm (database::common);
+
+ o.odb_file_suffix ().insert (make_pair (cm, string ("-odb")));
+ o.sql_file_suffix ().insert (make_pair (cm, string ("")));
+ o.schema_file_suffix ().insert (make_pair (cm, string ("-schema")));
+ }
+
+ if (o.multi_database () == multi_database::disabled)
+ {
+ o.odb_file_suffix ().insert (make_pair (db, string ("-odb")));
+ o.sql_file_suffix ().insert (make_pair (db, string ("")));
+ o.schema_file_suffix ().insert (make_pair (db, string ("-schema")));
+ }
+ else
+ {
+ o.odb_file_suffix ().insert (
+ make_pair (db, string ("-odb-") + db.string ()));
+ o.sql_file_suffix ().insert (
+ make_pair (db, string ("-") + db.string ()));
+ o.schema_file_suffix ().insert (
+ make_pair (db, string ("-schema-") + db.string ()));
+ }
+
+ // Set default --default-database value.
+ //
+ if (!o.default_database_specified ())
+ {
+ switch (o.multi_database ())
+ {
+ case multi_database::disabled:
+ {
+ o.default_database (db);
+ o.default_database_specified (true);
+ break;
+ }
+ case multi_database::dynamic:
+ {
+ o.default_database (database::common);
+ o.default_database_specified (true);
+ break;
+ }
+ case multi_database::static_:
+ {
+ // No default database unless explicitly specified.
+ break;
+ }
+ }
+ }
}