aboutsummaryrefslogtreecommitdiff
path: root/odb/relational/source.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-04-27 13:32:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-04-27 13:32:45 +0200
commitf8b3ee6d42f5112c4e66a07cc7fdba43ce66aacd (patch)
tree2f3d877c7174e345514fe01cf9e462c1cb18b7ac /odb/relational/source.hxx
parent15b1a95942518c84f8161c59820ea5d0e49a4e54 (diff)
Support for NULL value semantics for composite values
Diffstat (limited to 'odb/relational/source.hxx')
-rw-r--r--odb/relational/source.hxx61
1 files changed, 45 insertions, 16 deletions
diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx
index 594274a..2f2a61e 100644
--- a/odb/relational/source.hxx
+++ b/odb/relational/source.hxx
@@ -1170,26 +1170,41 @@ namespace relational
member = "o." + name;
}
- os << "{";
-
- if (discriminator (mi.m))
- os << "const info_type& di (map->find (typeid (o)));"
- << endl;
-
bool comp (composite (mi.t));
// If this is a wrapped composite value, then we need to "unwrap"
- // it. For simple values this is taken care of by the value_traits
+ // it. If this is a NULL wrapper, then we also need to handle that.
+ // For simple values this is taken care of by the value_traits
// specializations.
//
if (mi.wrapper != 0 && comp)
{
- // Here we need the wrapper type, not the wrapped type.
+ // The wrapper type, not the wrapped type.
//
- member = "wrapper_traits< " + mi.fq_type (false) + " >::" +
- "get_ref (" + member + ")";
+ string const& wt (mi.fq_type (false));
+
+ // If this is a NULL wrapper and the member can be NULL, then
+ // we need to handle the NULL value.
+ //
+ if (null (mi.m, key_prefix_) &&
+ mi.wrapper->template get<bool> ("wrapper-null-handler"))
+ {
+ os << "if (wrapper_traits< " + wt + " >::get_null (" <<
+ member << "))" << endl
+ << "composite_value_traits< " + mi.fq_type () + " >::" <<
+ "set_null (i." << mi.var << "value, sk);"
+ << "else";
+ }
+
+ member = "wrapper_traits< " + wt + " >::get_ref (" + member + ")";
}
+ os << "{";
+
+ if (discriminator (mi.m))
+ os << "const info_type& di (map->find (typeid (o)));"
+ << endl;
+
if (mi.ptr != 0)
{
// When handling a pointer, mi.t is the id type of the referenced
@@ -1431,16 +1446,30 @@ namespace relational
bool comp (composite (mi.t));
- // If this is a wrapped composite value, then we need to
- // "unwrap" it. For simple values this is taken care of
- // by the value_traits specializations.
+ // If this is a wrapped composite value, then we need to "unwrap" it.
+ // If this is a NULL wrapper, then we also need to handle that. For
+ // simple values this is taken care of by the value_traits
+ // specializations.
//
if (mi.wrapper != 0 && comp)
{
- // Here we need the wrapper type, not the wrapped type.
+ // The wrapper type, not the wrapped type.
+ //
+ string const& wt (mi.fq_type (false));
+
+ // If this is a NULL wrapper and the member can be NULL, then
+ // we need to handle the NULL value.
//
- member = "wrapper_traits< " + mi.fq_type (false) + " >::" +
- "set_ref (\n" + member + ")";
+ if (null (mi.m, key_prefix_) &&
+ mi.wrapper->template get<bool> ("wrapper-null-handler"))
+ {
+ os << "if (composite_value_traits< " + mi.fq_type () + " >::" <<
+ "get_null (i." << mi.var << "value))" << endl
+ << "wrapper_traits< " + wt + " >::set_null (" << member + ");"
+ << "else" << endl;
+ }
+
+ member = "wrapper_traits< " + wt + " >::set_ref (" + member + ")";
}
if (mi.ptr != 0)