aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-09-20 11:53:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-09-20 11:53:04 +0200
commit18a040773c389de7be48111efc0f3cf7252ffc68 (patch)
treee68e5edde6a7f321e03172ecd5684d26644978c9
parentf70b64e2c4f9861d7013492b609212ed78e840f5 (diff)
Change query syntax to use . for composite and -> for object pointer access
Also make non-inverse query columns act as both an object pointer and a normal column. The latter allows us to use natural expressions such as query<employee>::employer.is_null ().
-rw-r--r--common/composite/driver.cxx4
-rw-r--r--common/erase-query/driver.cxx25
-rw-r--r--common/inheritance/driver.cxx4
-rw-r--r--common/inverse/driver.cxx4
-rw-r--r--common/relationship-query/driver.cxx14
-rw-r--r--common/relationship/driver.cxx2
-rw-r--r--common/view/driver.cxx8
-rw-r--r--common/view/test.hxx4
8 files changed, 45 insertions, 20 deletions
diff --git a/common/composite/driver.cxx b/common/composite/driver.cxx
index e1dfef8..606f367 100644
--- a/common/composite/driver.cxx
+++ b/common/composite/driver.cxx
@@ -90,7 +90,7 @@ main (int argc, char* argv[])
{
transaction t (db->begin ());
- result r (db->query<person> (query::name::first == "Joe"));
+ result r (db->query<person> (query::name.first == "Joe"));
assert (!r.empty ());
assert (*r.begin () == p);
@@ -104,7 +104,7 @@ main (int argc, char* argv[])
{
transaction t (db->begin ());
- result r (db->query<person> (query::name::flags::alias));
+ result r (db->query<person> (query::name.flags.alias));
assert (!r.empty ());
assert (*r.begin () == p);
diff --git a/common/erase-query/driver.cxx b/common/erase-query/driver.cxx
index 2137377..5085207 100644
--- a/common/erase-query/driver.cxx
+++ b/common/erase-query/driver.cxx
@@ -112,6 +112,31 @@ main (int argc, char* argv[])
}
*/
+ // For now we can only do column-based tests, like is_null().
+ //
+ {
+ object o11 (1);
+ object o12 (2);
+ object o13 (3);
+ object2 o2;
+
+ o12.o2 = &o2;
+
+ transaction t (db->begin ());
+ db->persist (o2);
+ db->persist (o13);
+ db->persist (o12);
+ db->persist (o11);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ assert (db->erase_query<object> (query::o2.is_null ()) == 2);
+ db->erase_query<object> ();
+ t.commit ();
+ }
+
// Make sure container data is deleted.
//
{
diff --git a/common/inheritance/driver.cxx b/common/inheritance/driver.cxx
index ce72863..0106b5b 100644
--- a/common/inheritance/driver.cxx
+++ b/common/inheritance/driver.cxx
@@ -143,7 +143,7 @@ main (int argc, char* argv[])
transaction t (db->begin ());
- assert (!db->query<base> (b_query::comp::num == 10).empty ());
+ assert (!db->query<base> (b_query::comp.num == 10).empty ());
assert (!db->query<object1> (o1_query::num1 == 21).empty ());
assert (!db->query<object2> (o2_query::num == 2).empty ());
@@ -155,7 +155,7 @@ main (int argc, char* argv[])
// Query condition with referenced composite member in base class.
//
{
- r_result r (db->query<reference> (r_query::o1::comp::num == 11));
+ r_result r (db->query<reference> (r_query::o1->comp.num == 11));
assert (!r.empty ());
delete r.begin ()->o1_;
}
diff --git a/common/inverse/driver.cxx b/common/inverse/driver.cxx
index c07b751..17fc5d6 100644
--- a/common/inverse/driver.cxx
+++ b/common/inverse/driver.cxx
@@ -172,7 +172,7 @@ main (int argc, char* argv[])
session s;
transaction t (db->begin ());
- result r (db->query<obj2> (query::o1::id == "obj1 1"));
+ result r (db->query<obj2> (query::o1->id == "obj1 1"));
assert (!r.empty ());
assert (r.begin ()->id == o2->id);
assert (r.begin ()->o1->id == o1_1->id);
@@ -190,7 +190,7 @@ main (int argc, char* argv[])
session s;
transaction t (db->begin ());
- result r (db->query<obj3> (query::o1::id == "obj1 1"));
+ result r (db->query<obj3> (query::o1->id == "obj1 1"));
size_t n (0);
for (result::iterator i (r.begin ()); i != r.end (); ++i)
diff --git a/common/relationship-query/driver.cxx b/common/relationship-query/driver.cxx
index 57a6215..2e0068e 100644
--- a/common/relationship-query/driver.cxx
+++ b/common/relationship-query/driver.cxx
@@ -109,11 +109,11 @@ main (int argc, char* argv[])
transaction t (db->begin ());
p_result pr (db->query<person> (
- p_query::residence::location::code == "ZA"));
+ p_query::residence.location->code == "ZA"));
assert (size (pr) == 1);
e_result er (db->query<employee> (
- e_query::residence::location::code == "ZA"));
+ e_query::residence.location->code == "ZA"));
assert (size (er) == 1);
t.commit ();
@@ -125,10 +125,10 @@ main (int argc, char* argv[])
session s;
transaction t (db->begin ());
- p_result pr (db->query<person> (p_query::husband::last_name == "Doe"));
+ p_result pr (db->query<person> (p_query::husband->last_name == "Doe"));
assert (size (pr) == 1);
- e_result er (db->query<employee> (e_query::husband::last_name == "Doe"));
+ e_result er (db->query<employee> (e_query::husband->last_name == "Doe"));
assert (size (er) == 1);
t.commit ();
@@ -142,8 +142,8 @@ main (int argc, char* argv[])
e_result r (
db->query<employee> (
- e_query::employed_by::name == "Simple Tech, Inc" &&
- e_query::nationality::code == "US"));
+ e_query::employed_by->name == "Simple Tech, Inc" &&
+ e_query::nationality->code == "US"));
assert (size (r) == 1);
@@ -158,7 +158,7 @@ main (int argc, char* argv[])
p_result r (
db->query<person> (
- p_query::husband::residence::location == "CA"));
+ p_query::husband->residence.location == "CA"));
assert (size (r) == 1);
diff --git a/common/relationship/driver.cxx b/common/relationship/driver.cxx
index 3ce7e8c..e2ac749 100644
--- a/common/relationship/driver.cxx
+++ b/common/relationship/driver.cxx
@@ -105,7 +105,7 @@ main (int argc, char* argv[])
{
transaction t (db->begin ());
- result r (db->query<aggr> (query::o1::str == "obj1"));
+ result r (db->query<aggr> (query::o1->str == "obj1"));
assert (!r.empty ());
assert (r.begin ()->o1->id == a.o1->id);
assert (size (r) == 1);
diff --git a/common/view/driver.cxx b/common/view/driver.cxx
index 8450b34..847d21b 100644
--- a/common/view/driver.cxx
+++ b/common/view/driver.cxx
@@ -505,8 +505,8 @@ main (int argc, char* argv[])
{
result r (db->query<view10> (
- query::measures::weight > 60 &&
- query::measures::hight < 190));
+ query::measures.weight > 60 &&
+ query::measures.hight < 190));
result::iterator i (r.begin ());
@@ -535,9 +535,7 @@ main (int argc, char* argv[])
transaction t (db->begin ());
{
- result r (db->query<view11> (
- query::measures::weight > 60 &&
- query::measures::hight < 190));
+ result r (db->query<view11> ());
result::iterator i (r.begin ());
diff --git a/common/view/test.hxx b/common/view/test.hxx
index 3ba6745..dc3439c 100644
--- a/common/view/test.hxx
+++ b/common/view/test.hxx
@@ -382,7 +382,9 @@ struct view10
//
// Composite in object.
//
-#pragma db view object(person) query((?) + "ORDER BY" + person::age)
+#pragma db view object(person) \
+ query((person::measures.weight > 60 && person::measures.hight < 190) \
+ + "ORDER BY" + person::age)
struct view11
{
std::string last_name;