From a94dde17a2e6a41c36dd052bc8d2bbbc224aeb97 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 22 Aug 2011 09:21:32 +0200 Subject: Add --table-prefix option Assign unique table prefixes to most examples. This makes sure that we don't end up with broken schemas where half of the tables were changed by the next test and the other half has foreign keys that now point to nowhere. --- NEWS | 4 ++++ odb/context.cxx | 23 ++++++++++++++++++----- odb/options.cli | 10 ++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 128e8b7..3f84ddb 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,10 @@ Version 1.6.0 For more information, refer to chapters 11 (for MySQL), 12 (for SQLite) and 13 (for PostgreSQL) in the ODB manual. + * New option, --table-prefix, allows the specification of a prefix that + is added to table and index names. For more information, refer to the + ODB compiler command line interface documentation (man pages). + Version 1.5.0 * Support for the PostgreSQL database. The provided connection factories diff --git a/odb/context.cxx b/odb/context.cxx index 0280c28..68e3f65 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -359,25 +359,38 @@ comp_value_ (semantics::class_& c) string context:: table_name (semantics::class_& t) const { + string name (options.table_prefix ()); + if (t.count ("table")) - return t.get ("table"); + name += t.get ("table"); else - return t.name (); + name += t.name (); + + return name; } string context:: table_name (semantics::data_member& m, table_prefix const& p) const { + string name (options.table_prefix ()); + // If a custom table name was specified, then ignore the top-level // table prefix. // if (m.count ("table")) { - string const& name (m.get ("table")); - return p.level == 1 ? name : p.prefix + name; + if (p.level != 1) + name += p.prefix; + + name += m.get ("table"); + } + else + { + name += p.prefix; + name += public_name_db (m); } - return p.prefix + public_name_db (m); + return name; } string context:: diff --git a/odb/options.cli b/odb/options.cli index 34c35a6..65c9873 100644 --- a/odb/options.cli +++ b/odb/options.cli @@ -142,6 +142,16 @@ class options profile." }; + std::string --table-prefix + { + "", + "Add to table and index names. The prefix is added to both + names that were specified with the \cb{db table} pragma and those + that were automatically derived from class names. If you require a + separator, such as an underscore, between the prefix and the name, + then you should include it into the prefix value." + }; + std::string --output-dir | -o { "", -- cgit v1.1