aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/inverse/driver.cxx41
-rw-r--r--common/relationship/driver.cxx15
-rw-r--r--common/relationship/makefile3
3 files changed, 58 insertions, 1 deletions
diff --git a/common/inverse/driver.cxx b/common/inverse/driver.cxx
index e572be2..139c2b6 100644
--- a/common/inverse/driver.cxx
+++ b/common/inverse/driver.cxx
@@ -161,6 +161,47 @@ main (int argc, char* argv[])
delete *x4_2->o1.begin ();
}
+ // query
+ //
+ {
+ // one(i)-to-one
+ //
+ typedef odb::query<obj2> query;
+ typedef odb::result<obj2> result;
+
+ session s;
+ transaction t (db->begin ());
+
+ result r (db->query<obj2> (query::o1::id == "obj1 1"));
+ assert (r.size () == 1);
+ assert (r.begin ()->id == o2->id);
+ assert (r.begin ()->o1->id == o1_1->id);
+
+ t.commit ();
+ }
+
+ {
+ // one(i)-to-many
+ //
+ typedef odb::query<obj3> query;
+ typedef odb::result<obj3> result;
+
+ session s;
+ transaction t (db->begin ());
+
+ result r (db->query<obj3> (query::o1::id == "obj1 1"));
+
+ assert (r.size () == 2);
+
+ for (result::iterator i (r.begin ()); i != r.end (); ++i)
+ {
+ assert (i->id == o3_1->id || i->id == o3_2->id);
+ assert (i->o1->id == o1_1->id);
+ }
+
+ t.commit ();
+ }
+
delete o1_1;
delete o1_2;
}
diff --git a/common/relationship/driver.cxx b/common/relationship/driver.cxx
index 9266e2b..f7aa79e 100644
--- a/common/relationship/driver.cxx
+++ b/common/relationship/driver.cxx
@@ -96,6 +96,21 @@ main (int argc, char* argv[])
assert (*a1 == a);
}
+ // query
+ //
+ typedef odb::query<aggr> query;
+ typedef odb::result<aggr> result;
+
+ {
+ transaction t (db->begin ());
+
+ result r (db->query<aggr> (query::o1::str == "obj1"));
+ assert (r.size () == 1);
+ assert (r.begin ()->o1->id == a.o1->id);
+
+ t.commit ();
+ }
+
// test NULL pointer
//
delete a.o1;
diff --git a/common/relationship/makefile b/common/relationship/makefile
index a1c0a21..a3857d4 100644
--- a/common/relationship/makefile
+++ b/common/relationship/makefile
@@ -35,7 +35,8 @@ gen := $(addprefix $(out_base)/,$(genf))
$(gen): $(odb)
$(gen): odb := $(odb)
-$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema
+$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \
+--generate-query
$(gen): cpp_options := -I$(out_base)
$(gen): $(common.l.cpp-options)