From 7a1be868574beb4843d189a7d9d758d608da65c9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 27 Sep 2011 11:20:31 +0200 Subject: Add support for associating tables with views --- common/view/driver.cxx | 38 +++++++++++++++++++++++++++++++------- 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& db) template void -view6_test (const auto_ptr& db) +view6_test (const auto_ptr& db, const odb::query& q) { typedef odb::query query; typedef odb::result result; @@ -143,9 +143,7 @@ view6_test (const auto_ptr& db) transaction t (db->begin ()); { - result r ( - db->query ( - query::employer::name == "Simple Tech, Inc")); + result r (db->query (q)); iterator i (r.begin ()); @@ -312,6 +310,24 @@ main (int argc, char* argv[]) } } + // view1d + // + { + typedef odb::query query; + typedef odb::result result; + + { + transaction t (db->begin ()); + + { + result r (db->query ("age < 31 ORDER BY age")); + view1_check (r); + } + + t.commit (); + } + } + // view2 // view2_test (db); @@ -412,9 +428,17 @@ main (int argc, char* argv[]) // view6 // - view6_test (db); - view6_test (db); - view6_test (db); + view6_test ( + db, odb::query::employer::name == "Simple Tech, Inc"); + + view6_test ( + db, odb::query::employer::name == "Simple Tech, Inc"); + + view6_test ( + db, odb::query::employer::name == "Simple Tech, Inc"); + + view6_test ( + db, "e.name = " + odb::query::_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. // -- cgit v1.1