diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-09-10 14:03:21 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-09-17 12:04:03 +0200 |
commit | 86a83893351adef44574514c303aa880cf3b6d54 (patch) | |
tree | 706ba87b0bd2a8ffbdd3e1e55f6850a2119039cb /evolution/soft-delete | |
parent | 22415f5ec7d53fbad4818ac31a42d6e623b8afa9 (diff) |
Add soft-add/delete auto id test, LOB/long data test
Diffstat (limited to 'evolution/soft-delete')
-rw-r--r-- | evolution/soft-delete/driver.cxx | 140 | ||||
-rw-r--r-- | evolution/soft-delete/model.hxx | 20 |
2 files changed, 160 insertions, 0 deletions
diff --git a/evolution/soft-delete/driver.cxx b/evolution/soft-delete/driver.cxx index 7acf6e1..a5e9927 100644 --- a/evolution/soft-delete/driver.cxx +++ b/evolution/soft-delete/driver.cxx @@ -249,6 +249,22 @@ main (int argc, char* argv[]) } } + // Test soft-deleted member in an object with auto id. + // + { + using namespace test14; + + object o; + 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. @@ -864,6 +880,64 @@ main (int argc, char* argv[]) } } + // Test soft-deleted member in an object with auto id. + // + { + using namespace test14; + + // All the database operations should still include the deleted + // members. + // + unsigned long id; + { + typedef odb::query<object> query; + typedef odb::result<object> result; + + transaction t (db->begin ()); + result r (db->query<object> (query::str == "abc")); + result::iterator i (r.begin ()); + assert (i != r.end () && i->str == "abc" && i->num == 123); + id = i->id; + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr<object> p (db->load<object> (id)); + assert (p->str == "abc" && p->num == 123); + t.commit (); + } + + object o; + o.str = "bcd"; + o.num = 234; + + { + transaction t (db->begin ()); + db->persist (o); + auto_ptr<object> p (db->load<object> (o.id)); + assert (p->str == "bcd" && p->num == 234); + t.commit (); + } + + o.str += 'e'; + o.num++; + + { + transaction t (db->begin ()); + db->update (o); + auto_ptr<object> p (db->load<object> (o.id)); + assert (p->str == "bcde" && p->num == 235); + t.commit (); + } + + { + transaction t (db->begin ()); + db->erase (o); + t.commit (); + } + } + #endif // DATABASE_SQLITE // Test soft-deleted container member in a non-versioned object. @@ -1720,6 +1794,72 @@ main (int argc, char* argv[]) } } + // Test soft-deleted member in an object with auto id. + // + { + using namespace test14; + + // Now none of the database operations should include the + // deleted members. + // + unsigned long id; + { + typedef odb::query<object> query; + typedef odb::result<object> result; + + transaction t (db->begin ()); + result r (db->query<object> (query::num == 123)); + result::iterator i (r.begin ()); + assert (i != r.end () && i->str == "" && i->num == 123); + id = i->id; + + try + { + db->query<object> (query::str == "abc"); // No such column. + assert (false); + } + catch (const odb::exception&) {} + + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr<object> p (db->load<object> (id)); + assert (p->str == "" && p->num == 123); + t.commit (); + } + + object o; + o.str = "bcd"; + o.num = 234; + + { + transaction t (db->begin ()); + db->persist (o); + auto_ptr<object> p (db->load<object> (o.id)); + assert (p->str == "" && p->num == 234); + t.commit (); + } + + o.str += 'e'; + o.num++; + + { + transaction t (db->begin ()); + db->update (o); + auto_ptr<object> p (db->load<object> (o.id)); + assert (p->str == "" && p->num == 235); + t.commit (); + } + + { + transaction t (db->begin ()); + db->erase<object> (o.id); + t.commit (); + } + } + #endif // DATABASE_SQLITE // Test soft-deleted container member in a non-versioned object. diff --git a/evolution/soft-delete/model.hxx b/evolution/soft-delete/model.hxx index 5df2cee..ef5bc68 100644 --- a/evolution/soft-delete/model.hxx +++ b/evolution/soft-delete/model.hxx @@ -413,6 +413,26 @@ namespace MODEL_NAMESPACE(MODEL_VERSION) #endif } + // Test soft-deleted member in an object with auto id. + // + #pragma db namespace table("t14_") + namespace test14 + { + #pragma db object + struct object + { + std::string str; + unsigned long num; + + #pragma db id auto + unsigned long id; + }; + +#if MODEL_VERSION == 3 + #pragma db member(object::str) deleted(3) +#endif + } + #endif // DATABASE_SQLITE // Test soft-deleted container member in a non-versioned object. |