From b985defe92ab9107fa857d2c32b7d5182b351344 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 29 Aug 2014 12:06:46 +0200 Subject: 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). --- common/inheritance/polymorphism/driver.cxx | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'common/inheritance/polymorphism/driver.cxx') 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 pb (db->load (d.id)); + t.commit (); + + derived* pd (dynamic_cast (pb.get ())); + assert (pd != 0 && pd->blob == d.blob); + } + + // Query. + // + { + typedef odb::result result; + + transaction t (db->begin ()); + + result r (db->query ()); + result::iterator i (r.begin ()), e (r.end ()); + + assert (i != e); + + derived* pd (dynamic_cast (&*i)); + assert (pd != 0 && pd->blob == d.blob); + + assert (++i == e); + t.commit (); + } + } } catch (const odb::exception& e) { -- cgit v1.1