diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-04-22 14:07:32 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-04-22 14:07:32 +0200 |
commit | 587db8c7ca28d5cd1722307073aa31aed5b89d0a (patch) | |
tree | b5295accedf2cd946d5df22ed5fbfa78290e89dc /odb/relational/common.cxx | |
parent | 584f3602038919957f62848a03deb5b5bd9cc9ba (diff) |
Initial support for non-polymorphic inheritance
Every class gets a separate table. New test: common/inheritance.
Diffstat (limited to 'odb/relational/common.cxx')
-rw-r--r-- | odb/relational/common.cxx | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/odb/relational/common.cxx b/odb/relational/common.cxx index 3e6461b..6032548 100644 --- a/odb/relational/common.cxx +++ b/odb/relational/common.cxx @@ -25,17 +25,37 @@ namespace relational } query_columns:: - query_columns (semantics::class_& cl) //@@ context::object + query_columns (semantics::class_& c) //@@ context::object : ptr_ (true), decl_ (false) { - scope_ = "access::object_traits< " + cl.fq_name () + " >::query_type"; - table_ = table_qname (cl); + scope_ = "access::object_traits< " + c.fq_name () + " >::query_columns"; + table_ = table_qname (c); } void query_columns:: - composite (semantics::data_member& m, semantics::class_& c) + object (semantics::class_& c) { - string name (public_name (m)); + // We only want members for objects unless we are traversing a + // pointer, in which case we need the whole thing. + // + if (!ptr_) + inherits (c); + + names (c); + } + + void query_columns:: + composite (semantics::data_member* m, semantics::class_& c) + { + // Base type. + // + if (m == 0) + { + object_columns_base::composite (m, c); + return; + } + + string name (public_name (*m)); if (decl_) { @@ -73,6 +93,16 @@ namespace relational // in queries). So we will have to duplicate the columns (sans // the pointers). // + // There are a number of problems with this approach: Regarding (1), + // the class have to be defined during ODB compilation in which + // case the ODB compiler will hunt down the #include statement + // and add it to the generated code. Regarding (2), things get + // complicated really quickly once we bring inheritance into + // the picture (name conflicts, etc). Plus, it is nice to reuse + // things. So the long-term solution is probably to make it a + // template with the table name as an argument. + // + if (ptr_) { ptr_ = false; @@ -123,7 +153,18 @@ namespace relational } else { - string column (table_ + '.' + quote_id (col_name)); + // Use the default table alias unless we are generating members + // for a referenced object. + // + string column; + + if (!ptr_) + column = table_; + else + column = "_"; + + column += '.'; + column += quote_id (col_name); os << "const " << db << "::query_column<" << endl << " " << type << "," << endl |