From 59293cddb0d37a2bf37e579aa42da00fc9cfc5dc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 4 Sep 2013 13:40:31 +0200 Subject: View versioning support --- evolution/soft-delete/driver.cxx | 64 ++++++++++++++++++++++++++++++++++++++++ evolution/soft-delete/makefile | 2 +- evolution/soft-delete/model.hxx | 30 +++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/evolution/soft-delete/driver.cxx b/evolution/soft-delete/driver.cxx index 23f0c9b..d0debce 100644 --- a/evolution/soft-delete/driver.cxx +++ b/evolution/soft-delete/driver.cxx @@ -104,6 +104,22 @@ main (int argc, char* argv[]) } } + // Test view with soft-deleted member. + // + { + using namespace test6; + + object o (1); + o.str = "abc"; + o.num = 123; + + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + } + #endif // DATABASE_SQLITE // Test soft-deleted container member in a non-versioned object. @@ -255,6 +271,26 @@ main (int argc, char* argv[]) } } + // Test view with soft-deleted member. + // + { + using namespace test6; + + // All the database operations should still include the deleted + // members. + // + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + result r (db->query (query::str == "abc")); + result::iterator i (r.begin ()); + assert (i != r.end () && i->str == "abc" && i->num == 123); + t.commit (); + } + } + #endif // DATABASE_SQLITE // Test soft-deleted container member in a non-versioned object. @@ -504,6 +540,34 @@ main (int argc, char* argv[]) } } + // Test view with soft-deleted member. + // + { + using namespace test6; + + // Now none of the database operations should include the + // deleted members. + // + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + result r (db->query (query::num == 123)); + result::iterator i (r.begin ()); + assert (i != r.end () && i->str == "" && i->num == 123); + + try + { + db->query (query::str == "abc"); // No such column. + assert (false); + } + catch (const odb::exception&) {} + + t.commit (); + } + } + #endif // DATABASE_SQLITE // Test soft-deleted container member in a non-versioned object. diff --git a/evolution/soft-delete/makefile b/evolution/soft-delete/makefile index da284c7..12d02a3 100644 --- a/evolution/soft-delete/makefile +++ b/evolution/soft-delete/makefile @@ -36,7 +36,7 @@ $(cxx_obj) $(cxx_od): $(common.l.cpp-options) $(gen): $(odb) $(gen): odb := $(odb) -$(gen) $(dist): odb_common_options = --generate-query \ +$(gen) $(dist): odb_common_options = --generate-query --generate-prepared \ --generate-schema --at-once --table-prefix evo_soft_d_ $(gen): odb_common_options += --database $(db_id) $(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog diff --git a/evolution/soft-delete/model.hxx b/evolution/soft-delete/model.hxx index 78a4cfe..6abdd39 100644 --- a/evolution/soft-delete/model.hxx +++ b/evolution/soft-delete/model.hxx @@ -148,6 +148,36 @@ namespace MODEL_NAMESPACE(MODEL_VERSION) #endif } + // Test view with soft-deleted member. + // + #pragma db namespace table("t6_") + namespace test6 + { + #pragma db object + struct object + { + object (unsigned long id = 0): id_ (id) {} + + #pragma db id + unsigned long id_; + + std::string str; + unsigned long num; + }; + + #pragma db view object(object) + struct view + { + std::string str; + unsigned long num; + }; + +#if MODEL_VERSION == 3 + #pragma db member(object::str) deleted(3) + #pragma db member(view::str) deleted(3) +#endif + } + #endif // DATABASE_SQLITE // Test soft-deleted container member in a non-versioned object. -- cgit v1.1