diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2014-08-29 12:06:46 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2014-08-29 12:06:46 +0200 |
commit | b985defe92ab9107fa857d2c32b7d5182b351344 (patch) | |
tree | ece83c795e702eaa4ea534e13fa0c35bf983083a /common/inheritance/polymorphism/driver.cxx | |
parent | a3af5aadbe45eccab791eec98859f6ad722c3b58 (diff) |
Pass non-const image to clone_image(), copy_image()
This is necessary since some databases need to steal stuff from the
original image (e.g., LOB descriptors in Oracle).
Diffstat (limited to 'common/inheritance/polymorphism/driver.cxx')
-rw-r--r-- | common/inheritance/polymorphism/driver.cxx | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/common/inheritance/polymorphism/driver.cxx b/common/inheritance/polymorphism/driver.cxx index 7ab6346..672473c 100644 --- a/common/inheritance/polymorphism/driver.cxx +++ b/common/inheritance/polymorphism/driver.cxx @@ -29,6 +29,7 @@ #include "test12.hxx" #include "test13.hxx" #include "test14.hxx" +#include "test15.hxx" #include "test1-odb.hxx" #include "test2-odb.hxx" @@ -44,6 +45,7 @@ #include "test12-odb.hxx" #include "test13-odb.hxx" #include "test14-odb.hxx" +#include "test15-odb.hxx" using namespace std; using namespace odb::core; @@ -2002,6 +2004,56 @@ main (int argc, char* argv[]) t.commit (); } } + + // Test 15: LOB/long data and polymorphism. + // + { + using namespace test15; + + const char data[] = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B"; + + derived d; + d.blob.assign (data, data + sizeof (data)); + + // Persist. + // + { + transaction t (db->begin ()); + base* b (&d); + db->persist (b); + t.commit (); + } + + // Load. + // + { + transaction t (db->begin ()); + auto_ptr<base> pb (db->load<base> (d.id)); + t.commit (); + + derived* pd (dynamic_cast<derived*> (pb.get ())); + assert (pd != 0 && pd->blob == d.blob); + } + + // Query. + // + { + typedef odb::result<base> result; + + transaction t (db->begin ()); + + result r (db->query<base> ()); + result::iterator i (r.begin ()), e (r.end ()); + + assert (i != e); + + derived* pd (dynamic_cast<derived*> (&*i)); + assert (pd != 0 && pd->blob == d.blob); + + assert (++i == e); + t.commit (); + } + } } catch (const odb::exception& e) { |