aboutsummaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-04-26 15:54:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-04-26 15:54:19 +0200
commit84cb9f184bc24ef7151ab9931b46311b03219b14 (patch)
treedb976c22d0dfacdf7ceae4e0d27f4f1615bf5cb0 /odb
parent436031d026eb004865faaa21af5213a6f89a6a85 (diff)
Add support for table options in changelog, use to handle MySQL engine
Diffstat (limited to 'odb')
-rw-r--r--odb/relational/changelog.cxx28
-rw-r--r--odb/relational/model.hxx19
-rw-r--r--odb/relational/mysql/model.cxx26
-rw-r--r--odb/relational/mysql/schema.cxx10
-rw-r--r--odb/relational/schema.hxx7
-rw-r--r--odb/semantics/relational/table.cxx17
-rw-r--r--odb/semantics/relational/table.hxx14
7 files changed, 103 insertions, 18 deletions
diff --git a/odb/relational/changelog.cxx b/odb/relational/changelog.cxx
index af1dcea..6fc85b7 100644
--- a/odb/relational/changelog.cxx
+++ b/odb/relational/changelog.cxx
@@ -356,6 +356,9 @@ namespace relational
assert (bt != 0);
alters& ae (g.new_edge<alters> (at, *bt));
+ if (t.options () != ot->options ())
+ diagnose_table (t, "options", ot->options (), t.options ());
+
{
trav_rel::table table;
trav_rel::unames names;
@@ -398,6 +401,31 @@ namespace relational
}
}
+ void
+ diagnose_table (sema_rel::table& t,
+ char const* name,
+ string const& ov,
+ string const& nv)
+ {
+ location const& tl (t.get<location> ("cxx-location"));
+
+ error (tl) << "change to object or container member results in "
+ "the change of the corresponding table " << name;
+
+ if (!ov.empty () || !nv.empty ())
+ cerr << " (old: '" << ov << "', new: '" << nv << "')";
+
+ cerr << endl;
+
+ error (tl) << "this change is not yet handled automatically" << endl;
+ info (tl) << "consider re-implementing this change by adding a " <<
+ "new object or container member with the desired " << name <<
+ ", migrating the data, and deleting the old object or member" <<
+ endl;
+
+ throw operation_failed ();
+ }
+
protected:
model& other;
mode_type mode;
diff --git a/odb/relational/model.hxx b/odb/relational/model.hxx
index 5936ed1..6552048 100644
--- a/odb/relational/model.hxx
+++ b/odb/relational/model.hxx
@@ -468,6 +468,12 @@ namespace relational
id_prefix_ = t;
}
+ virtual string
+ table_options (semantics::data_member&, semantics::type&)
+ {
+ return "";
+ }
+
virtual void
traverse_container (semantics::data_member& m, semantics::type& ct)
{
@@ -495,6 +501,8 @@ namespace relational
t.set ("cxx-location", m.location ());
model_.new_edge<sema_rel::qnames> (model_, t, name);
+ t.options (table_options (m, ct));
+
// object_id
//
{
@@ -675,9 +683,12 @@ namespace relational
{
typedef class_ base;
- class_ (sema_rel::model& model)
- : model_ (model)
+ class_ (sema_rel::model& model): model_ (model) {}
+
+ virtual string
+ table_options (type&)
{
+ return "";
}
virtual void
@@ -702,10 +713,12 @@ namespace relational
string id (class_fq_name (c), 2); // Remove leading '::'.
- sema_rel::table& t(model_.new_node<sema_rel::table> (id));
+ sema_rel::table& t (model_.new_node<sema_rel::table> (id));
t.set ("cxx-location", c.location ());
model_.new_edge<sema_rel::qnames> (model_, t, name);
+ t.options (table_options (c));
+
// Add columns.
//
{
diff --git a/odb/relational/mysql/model.cxx b/odb/relational/mysql/model.cxx
index baec600..36b318f 100644
--- a/odb/relational/mysql/model.cxx
+++ b/odb/relational/mysql/model.cxx
@@ -105,6 +105,32 @@ namespace relational
}
};
entry<object_columns> object_columns_;
+
+ struct member_create: relational::member_create, context
+ {
+ member_create (base const& x): base (x) {}
+
+ virtual string
+ table_options (semantics::data_member&, semantics::type&)
+ {
+ string const& engine (options.mysql_engine ());
+ return engine != "default" ? "ENGINE=" + engine : "";
+ }
+ };
+ entry<member_create> member_create_;
+
+ struct class_: relational::class_, context
+ {
+ class_ (base const& x): base (x) {}
+
+ virtual string
+ table_options (type&)
+ {
+ string const& engine (options.mysql_engine ());
+ return engine != "default" ? "ENGINE=" + engine : "";
+ }
+ };
+ entry<class_> class__;
}
}
}
diff --git a/odb/relational/mysql/schema.cxx b/odb/relational/mysql/schema.cxx
index c44b796..f89bb61 100644
--- a/odb/relational/mysql/schema.cxx
+++ b/odb/relational/mysql/schema.cxx
@@ -297,16 +297,6 @@ namespace relational
}
}
}
-
- virtual void
- create_post ()
- {
- os << ")" << endl;
-
- string const& engine (options.mysql_engine ());
- if (engine != "default")
- os << " ENGINE=" << engine << endl;
- }
};
entry<create_table> create_table_;
diff --git a/odb/relational/schema.hxx b/odb/relational/schema.hxx
index 4e0febf..95dd68c 100644
--- a/odb/relational/schema.hxx
+++ b/odb/relational/schema.hxx
@@ -931,9 +931,12 @@ namespace relational
}
virtual void
- create_post ()
+ create_post (sema_rel::table& t)
{
os << ")" << endl;
+
+ if (!t.options ().empty ())
+ os << " " << t.options () << endl;
}
virtual void
@@ -958,7 +961,7 @@ namespace relational
names (t, n);
- create_post ();
+ create_post (t);
post_statement ();
// Create indexes.
diff --git a/odb/semantics/relational/table.cxx b/odb/semantics/relational/table.cxx
index 17265bd..80add9f 100644
--- a/odb/semantics/relational/table.cxx
+++ b/odb/semantics/relational/table.cxx
@@ -15,7 +15,8 @@ namespace semantics
table::
table (table const& t, qscope& s, graph& g, bool b)
: qnameable (t, g),
- uscope (t, (b ? s.lookup<table, drop_table> (t.name ()) : 0), g)
+ uscope (t, (b ? s.lookup<table, drop_table> (t.name ()) : 0), g),
+ options_ (t.options_)
{
}
@@ -26,7 +27,8 @@ namespace semantics
p,
(b ? s.lookup<table, drop_table> (
p.attribute<qnameable::name_type> ("name")) : 0),
- g)
+ g),
+ options_ (p.attribute ("options", string ()))
{
}
@@ -37,10 +39,19 @@ namespace semantics
}
void table::
+ serialize_attributes (xml::serializer& s) const
+ {
+ qnameable::serialize_attributes (s);
+
+ if (!options_.empty ())
+ s.attribute ("options", options_);
+ }
+
+ void table::
serialize (xml::serializer& s) const
{
s.start_element (xmlns, "table");
- qnameable::serialize_attributes (s);
+ serialize_attributes (s);
uscope::serialize_content (s);
s.end_element ();
}
diff --git a/odb/semantics/relational/table.hxx b/odb/semantics/relational/table.hxx
index ae4c96c..f46eec1 100644
--- a/odb/semantics/relational/table.hxx
+++ b/odb/semantics/relational/table.hxx
@@ -14,6 +14,13 @@ namespace semantics
class table: public qnameable, public uscope
{
public:
+ virtual string const&
+ options () const {return options_;}
+
+ virtual void
+ options (string const& o) {options_ = o;}
+
+ public:
table (string const& id): qnameable (id) {}
table (table const&, qscope&, graph&, bool base = false);
table (xml::parser&, qscope&, graph&, bool base = false);
@@ -30,6 +37,13 @@ namespace semantics
// Resolve ambiguity.
//
using qnameable::scope;
+
+ protected:
+ void
+ serialize_attributes (xml::serializer&) const;
+
+ protected:
+ string options_;
};
class add_table: public table