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 ++++++++++++++++++++++++++++++ common/inheritance/polymorphism/makefile | 2 +- common/inheritance/polymorphism/test15.hxx | 45 ++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 common/inheritance/polymorphism/test15.hxx 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) { diff --git a/common/inheritance/polymorphism/makefile b/common/inheritance/polymorphism/makefile index bfe66ab..a9cbc4e 100644 --- a/common/inheritance/polymorphism/makefile +++ b/common/inheritance/polymorphism/makefile @@ -7,7 +7,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make cxx_tun := driver.cxx odb_hdr := test1.hxx test2.hxx test3.hxx test4.hxx test5.hxx test6.hxx \ test7.hxx test8.hxx test9.hxx test10.hxx test11.hxx test12.hxx test13.hxx \ -test14.hxx +test14.hxx test15.hxx genf := $(call odb-gen,$(odb_hdr)) gen := $(addprefix $(out_base)/,$(genf)) cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) $(filter %.o,$(gen:.cxx=.o)) diff --git a/common/inheritance/polymorphism/test15.hxx b/common/inheritance/polymorphism/test15.hxx new file mode 100644 index 0000000..d64f935 --- /dev/null +++ b/common/inheritance/polymorphism/test15.hxx @@ -0,0 +1,45 @@ +// file : common/inheritance/polymorphism/test15.hxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST15_HXX +#define TEST15_HXX + +#include + +#include + +#ifdef ODB_COMPILER +# if defined(ODB_DATABASE_PGSQL) +# define BLOB_TYPE "BYTEA" +# elif defined(ODB_DATABASE_MSSQL) +# define BLOB_TYPE "VARBINARY(max)" +# else +# define BLOB_TYPE "BLOB" +# endif +#endif + + +// Test LOB/long data and polymorphism. +// +#pragma db namespace table("t15_") +namespace test15 +{ + #pragma db object polymorphic + struct base + { + virtual ~base () {} + + #pragma db id auto + unsigned long id; + }; + + #pragma db object + struct derived: base + { + #pragma db type(BLOB_TYPE) + std::vector blob; + }; +} + +#endif // TEST15_HXX -- cgit v1.1