diff options
-rw-r--r-- | common/view/driver.cxx | 38 | ||||
-rw-r--r-- | common/view/test.hxx | 32 |
2 files changed, 63 insertions, 7 deletions
diff --git a/common/view/driver.cxx b/common/view/driver.cxx index 7d921cd..cd734bd 100644 --- a/common/view/driver.cxx +++ b/common/view/driver.cxx @@ -134,7 +134,7 @@ view4_test (const auto_ptr<database>& db) template <typename V> void -view6_test (const auto_ptr<database>& db) +view6_test (const auto_ptr<database>& db, const odb::query<V>& q) { typedef odb::query<V> query; typedef odb::result<V> result; @@ -143,9 +143,7 @@ view6_test (const auto_ptr<database>& db) transaction t (db->begin ()); { - result r ( - db->query<V> ( - query::employer::name == "Simple Tech, Inc")); + result r (db->query<V> (q)); iterator i (r.begin ()); @@ -312,6 +310,24 @@ main (int argc, char* argv[]) } } + // view1d + // + { + typedef odb::query<view1d> query; + typedef odb::result<view1d> result; + + { + transaction t (db->begin ()); + + { + result r (db->query<view1d> ("age < 31 ORDER BY age")); + view1_check (r); + } + + t.commit (); + } + } + // view2 // view2_test<view2> (db); @@ -412,9 +428,17 @@ main (int argc, char* argv[]) // view6 // - view6_test<view6> (db); - view6_test<view6a> (db); - view6_test<view6b> (db); + view6_test<view6> ( + db, odb::query<view6>::employer::name == "Simple Tech, Inc"); + + view6_test<view6a> ( + db, odb::query<view6a>::employer::name == "Simple Tech, Inc"); + + view6_test<view6b> ( + db, odb::query<view6b>::employer::name == "Simple Tech, Inc"); + + view6_test<view6c> ( + db, "e.name = " + odb::query<view6c>::_val ("Simple Tech, Inc")); // view7 // diff --git a/common/view/test.hxx b/common/view/test.hxx index 37486aa..2497097 100644 --- a/common/view/test.hxx +++ b/common/view/test.hxx @@ -172,6 +172,21 @@ struct view1c unsigned short age; }; +// Assembled SELECT and FROM-lists. +// +#pragma db view table("common_view_person") +struct view1d +{ + #pragma db column("first") + std::string first; + + #pragma db column("last") + std::string last; + + #pragma db column("age") + unsigned short age; +}; + // // Count view plus associated object. // @@ -330,6 +345,23 @@ struct view6b std::string employer; }; +// The same using tables. +// +#pragma db view table("common_view_person" = "p") \ + table("common_view_employer_employees" = "ee": "ee.value = p.id") \ + table("common_view_employer" = "e": "ee.object_id = e.name") +struct view6c +{ + #pragma db column("p.first") + std::string first_name; + + #pragma db column("p"."last") + std::string last_name; + + #pragma db column("e.name") + std::string employer; +}; + // // JOIN via a custom condition. // |