diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-04-23 16:48:03 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-04-23 16:48:03 +0200 |
commit | 635d11d74cd873e6f53d05b1d9f091ae112402a5 (patch) | |
tree | 49a9b835aecba11ff666a7d5c34fd1a248881e78 /common/inheritance | |
parent | adfa9c5ffccdd4e5db8c545d9106c0eb1d7bdcb8 (diff) |
Polymorphic inheritance support
Diffstat (limited to 'common/inheritance')
-rw-r--r-- | common/inheritance/driver.cxx | 17 | ||||
-rw-r--r-- | common/inheritance/test.hxx | 12 |
2 files changed, 28 insertions, 1 deletions
diff --git a/common/inheritance/driver.cxx b/common/inheritance/driver.cxx index a0e3725..466ed33 100644 --- a/common/inheritance/driver.cxx +++ b/common/inheritance/driver.cxx @@ -161,6 +161,23 @@ main (int argc, char* argv[]) t.commit (); } + + // views + // + { + typedef odb::query<object2_view> query; + typedef odb::result<object2_view> result; + + transaction t (db->begin ()); + + result r (db->query<object2_view> (query::num == o2.num_)); + result::iterator i (r.begin ()); + assert (i != r.end () && + i->num == o2.num_ && i->id == o2.id_ && i->str == o2.str_); + assert (++i == r.end ()); + + t.commit (); + } } catch (const odb::exception& e) { diff --git a/common/inheritance/test.hxx b/common/inheritance/test.hxx index d679c46..6059337 100644 --- a/common/inheritance/test.hxx +++ b/common/inheritance/test.hxx @@ -90,7 +90,7 @@ struct object1: base #pragma db object struct object2: base { - #pragma db column ("derived_str") + #pragma db column("derived_str") std::string str_; bool @@ -145,4 +145,14 @@ struct empty: base { }; +// View based on the derived object. +// +#pragma db view object(object2) +struct object2_view +{ + unsigned int num; // from abstract_base + unsigned long id; // from base + std::string str; // from object2, hides one from abstract_base +}; + #endif // TEST_HXX |