diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-03-09 09:01:44 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-03-09 09:01:44 +0200 |
commit | e89a00af0b935183af40479f634db0a098c34e4a (patch) | |
tree | 1c3ef33103c8044cba9dec607368607e8f9e7910 /odb/relational/oracle | |
parent | b93bf14256c44ce389617b8d00aa94d828ce5a2f (diff) |
Don't override NOT NULL on Oracle VARCHAR column if it's primary key
Diffstat (limited to 'odb/relational/oracle')
-rw-r--r-- | odb/relational/oracle/schema.cxx | 25 |
1 files changed, 21 insertions, 4 deletions
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); |