aboutsummaryrefslogtreecommitdiff
path: root/common/inheritance/polymorphism
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-08-29 12:06:46 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-08-29 12:06:46 +0200
commitb985defe92ab9107fa857d2c32b7d5182b351344 (patch)
treeece83c795e702eaa4ea534e13fa0c35bf983083a /common/inheritance/polymorphism
parenta3af5aadbe45eccab791eec98859f6ad722c3b58 (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')
-rw-r--r--common/inheritance/polymorphism/driver.cxx52
-rw-r--r--common/inheritance/polymorphism/makefile2
-rw-r--r--common/inheritance/polymorphism/test15.hxx45
3 files changed, 98 insertions, 1 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)
{
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 <vector>
+
+#include <odb/core.hxx>
+
+#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<char> blob;
+ };
+}
+
+#endif // TEST15_HXX