aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-03-09 09:01:44 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-03-09 09:01:44 +0200
commite89a00af0b935183af40479f634db0a098c34e4a (patch)
tree1c3ef33103c8044cba9dec607368607e8f9e7910
parentb93bf14256c44ce389617b8d00aa94d828ce5a2f (diff)
Don't override NOT NULL on Oracle VARCHAR column if it's primary key
-rw-r--r--doc/manual.xhtml9
-rw-r--r--odb/relational/oracle/schema.cxx25
2 files changed, 27 insertions, 7 deletions
diff --git a/doc/manual.xhtml b/doc/manual.xhtml
index 6257cf7..e14f2cf 100644
--- a/doc/manual.xhtml
+++ b/doc/manual.xhtml
@@ -13261,10 +13261,13 @@ SHOW integer_datetimes
<p>In Oracle empty <code>VARCHAR2</code> and <code>NVARCHAR2</code>
strings are represented as <code>NULL</code> values. As a result,
- in the generated schema, columns of these types are always
- declared as <code>NULL</code>, even if explicitly declared as
+ in the generated schema, columns of these types are declared as
+ <code>NULL</code> even if explicitly declared as
<code>NOT NULL</code> with the <code>db&nbsp;not_null</code> pragma
- (<a href="#12.4.5">Section 12.4.5, "<code>null/not_null</code>"</a>).</p>
+ (<a href="#12.4.5">Section 12.4.5, "<code>null/not_null</code>"</a>),
+ except for primary key columns. This also means that for object ids
+ that are mapped to these Oracle types, an empty string is an invalid
+ value.</p>
<p>The Oracle ODB runtime library also provides support for mapping the
<code>std::string</code> type to the Oracle <code>CHAR</code>,
diff --git a/odb/relational/oracle/schema.cxx b/odb/relational/oracle/schema.cxx
index 2fd0602..2835520 100644
--- a/odb/relational/oracle/schema.cxx
+++ b/odb/relational/oracle/schema.cxx
@@ -153,9 +153,9 @@ namespace relational
null (sema_rel::column& c)
{
// Oracle interprets empty VARCHAR2 and NVARCHAR2 strings as
- // NULL. As an empty string is always valid within the C++
- // context, VARCHAR2 and NVARCHAR2 columns are always
- // specified as nullable.
+ // NULL. As an empty string is valid within the C++ context,
+ // VARCHAR2 and NVARCHAR2 columns are always specified as
+ // nullable, except when are a part of a primary key.
//
if (!c.null ())
{
@@ -164,7 +164,24 @@ namespace relational
sql_type const& t (parse_sql_type (c.type ()));
if (t.type == sql_type::VARCHAR2 || t.type == sql_type::NVARCHAR2)
- return;
+ {
+ // See if this column is a part of a primary key.
+ //
+ bool pk (false);
+
+ for (sema_rel::column::contained_iterator i (
+ c.contained_begin ()); i != c.contained_end (); ++i)
+ {
+ if (i->key ().is_a<sema_rel::primary_key> ())
+ {
+ pk = true;
+ break;
+ }
+ }
+
+ if (!pk)
+ return;
+ }
}
base::null (c);