From 86a83893351adef44574514c303aa880cf3b6d54 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 10 Sep 2013 14:03:21 +0200 Subject: Add soft-add/delete auto id test, LOB/long data test --- evolution/soft-add/driver.cxx | 168 ++++++++++++++++++++++++++++++++++++++- evolution/soft-add/model.hxx | 31 +++++++- evolution/soft-delete/driver.cxx | 140 ++++++++++++++++++++++++++++++++ evolution/soft-delete/model.hxx | 20 +++++ 4 files changed, 355 insertions(+), 4 deletions(-) (limited to 'evolution') diff --git a/evolution/soft-add/driver.cxx b/evolution/soft-add/driver.cxx index 4703a8a..190cc0c 100644 --- a/evolution/soft-add/driver.cxx +++ b/evolution/soft-add/driver.cxx @@ -96,7 +96,7 @@ main (int argc, char* argv[]) try { - db->query (query::str == "abc"); // No such column. + db->query (query::str.is_null ()); // No such column. assert (false); } catch (const odb::exception&) {} @@ -881,6 +881,81 @@ main (int argc, char* argv[]) } } + // Test soft-added member in an object with auto id. + // + { + using namespace test14; + + // None of the database operations should yet include the + // added members. + // + unsigned long id; + { + object o; + o.str = "abc"; + o.num = 123; + + transaction t (db->begin ()); + db->persist (o); + id = o.id; + t.commit (); + } + { + transaction t (db->begin ()); + auto_ptr p (db->load (id)); + assert (p->str == "" && p->num == 123); + t.commit (); + } + + { + 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 (); + } + + object o; + o.str = "bcd"; + o.num = 234; + + { + transaction t (db->begin ()); + db->persist (o); + auto_ptr p (db->load (o.id)); + assert (p->str == "" && p->num == 234); + t.commit (); + } + + o.str += 'e'; + o.num++; + + { + transaction t (db->begin ()); + db->update (o); + auto_ptr p (db->load (o.id)); + assert (p->str == "" && p->num == 235); + t.commit (); + } + + { + transaction t (db->begin ()); + db->erase (o.id); + t.commit (); + } + } + // Test soft-added container member in a non-versioned object. // { @@ -1055,6 +1130,7 @@ main (int argc, char* argv[]) auto_ptr p (db->load (1)); p->str = "abc"; p->vec.push_back (123); + delete p->ptr; p->ptr = new object1 (1); db->update (*p); t.commit (); @@ -1073,7 +1149,7 @@ main (int argc, char* argv[]) typedef odb::result result; transaction t (db->begin ()); - result r (db->query (query::str == "abc" && + result r (db->query (query::str.is_not_null () && query::ptr->id == 1)); result::iterator i (r.begin ()); assert (i != r.end () && @@ -1676,6 +1752,74 @@ main (int argc, char* argv[]) } } + // Test soft-added member in an object with auto id. + // + { + using namespace test14; + + typedef odb::query query; + typedef odb::result result; + + // All the database operations should now include the added + // members. + // + unsigned long id; + { + transaction t (db->begin ()); + result r (db->query (query::num == 123)); + result::iterator i (r.begin ()); + assert (i != r.end ()); + i->str = "abc"; + db->update (*i); + id = i->id; + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr p (db->load (id)); + assert (p->str == "abc" && p->num == 123); + t.commit (); + } + + { + 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 (); + } + + object o; + o.str = "bcd"; + o.num = 234; + + { + transaction t (db->begin ()); + db->persist (o); + auto_ptr p (db->load (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 p (db->load (o.id)); + assert (p->str == "bcde" && p->num == 235); + t.commit (); + } + + { + transaction t (db->begin ()); + db->erase (o); + t.commit (); + } + } + // Test soft-added container member in a non-versioned object. // { @@ -1997,6 +2141,26 @@ main (int argc, char* argv[]) } } + // Test soft-added member in an object with auto id. + // + { + using namespace test14; + + // All the database operations should still include the added + // 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 (); + } + } + // Test soft-added container member in a non-versioned object. // { diff --git a/evolution/soft-add/model.hxx b/evolution/soft-add/model.hxx index 1a7520a..50a7639 100644 --- a/evolution/soft-add/model.hxx +++ b/evolution/soft-add/model.hxx @@ -59,7 +59,11 @@ namespace MODEL_NAMESPACE(MODEL_VERSION) }; #if MODEL_VERSION == 3 - #pragma db member(object::str) added(3) + // Make it a LOB for Oracle and long data for SQL Server. + // + #pragma db member(object::str) added(3) \ + oracle:type("CLOB") \ + mssql:type("VARCHAR(max)") #pragma db member(object::vec) added(3) #pragma db member(object::ptr) added(3) #else @@ -414,7 +418,30 @@ namespace MODEL_NAMESPACE(MODEL_VERSION) }; #if MODEL_VERSION == 3 - #pragma db member(object::str) added(3) default("abc") + #pragma db member(object::str) added(3) default("abc") \ + mysql:type("VARCHAR(255)") +#else + #pragma db member(object::str) transient +#endif + } + + // Test soft-added 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) added(3) #else #pragma db member(object::str) transient #endif 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 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); + id = i->id; + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr p (db->load (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 p (db->load (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 p (db->load (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 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); + id = i->id; + + try + { + db->query (query::str == "abc"); // No such column. + assert (false); + } + catch (const odb::exception&) {} + + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr p (db->load (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 p (db->load (o.id)); + assert (p->str == "" && p->num == 234); + t.commit (); + } + + o.str += 'e'; + o.num++; + + { + transaction t (db->begin ()); + db->update (o); + auto_ptr p (db->load (o.id)); + assert (p->str == "" && p->num == 235); + t.commit (); + } + + { + transaction t (db->begin ()); + db->erase (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. -- cgit v1.1