aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-22 09:21:32 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-22 09:21:32 +0200
commita94dde17a2e6a41c36dd052bc8d2bbbc224aeb97 (patch)
tree959aa2b294025aa41229dafb885c8d740eb70c0d
parent6a6095112daabd18d445ecf0d4c05e993e54236c (diff)
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.
-rw-r--r--NEWS4
-rw-r--r--odb/context.cxx23
-rw-r--r--odb/options.cli10
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<string> ("table");
+ name += t.get<string> ("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<string> ("table"));
- return p.level == 1 ? name : p.prefix + name;
+ if (p.level != 1)
+ name += p.prefix;
+
+ name += m.get<string> ("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
+ {
+ "<prefix>",
+ "Add <prefix> 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
{
"<dir>",