From c1877f84f3596f67245abe6658b08c050bd1e686 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 4 Sep 2012 11:22:07 +0200 Subject: NULL handling improvements Add support for specifying NULL-ness for types with built-in mapping. Handle Oracle [N]VARCHAR2 and SQLite FLOAT oddities using this mechanism instead of overriding it at the schema generation level. Also use the is_null argument that is passed to value_traits::init_image() to indicate whether the value can be NULL. --- odb/relational/oracle/context.cxx | 46 +++++++++++++++++++++------------------ odb/relational/oracle/schema.cxx | 44 ------------------------------------- 2 files changed, 25 insertions(+), 65 deletions(-) (limited to 'odb/relational/oracle') diff --git a/odb/relational/oracle/context.cxx b/odb/relational/oracle/context.cxx index 01b690a..4ba8659 100644 --- a/odb/relational/oracle/context.cxx +++ b/odb/relational/oracle/context.cxx @@ -20,38 +20,41 @@ namespace relational { struct type_map_entry { - const char* const cxx_type; - const char* const db_type; - const char* const db_id_type; + char const* const cxx_type; + char const* const db_type; + char const* const db_id_type; + bool const null; }; type_map_entry type_map[] = { - {"bool", "NUMBER(1)", 0}, + {"bool", "NUMBER(1)", 0, false}, - {"char", "NUMBER(3)", 0}, - {"signed char", "NUMBER(3)", 0}, - {"unsigned char", "NUMBER(3)", 0}, + {"char", "NUMBER(3)", 0, false}, + {"signed char", "NUMBER(3)", 0, false}, + {"unsigned char", "NUMBER(3)", 0, false}, - {"short int", "NUMBER(5)", 0}, - {"short unsigned int", "NUMBER(5)", 0}, + {"short int", "NUMBER(5)", 0, false}, + {"short unsigned int", "NUMBER(5)", 0, false}, - {"int", "NUMBER(10)", 0}, - {"unsigned int", "NUMBER(10)", 0}, + {"int", "NUMBER(10)", 0, false}, + {"unsigned int", "NUMBER(10)", 0, false}, - {"long int", "NUMBER(19)", 0}, - {"long unsigned int", "NUMBER(20)", 0}, + {"long int", "NUMBER(19)", 0, false}, + {"long unsigned int", "NUMBER(20)", 0, false}, - {"long long int", "NUMBER(19)", 0}, - {"long long unsigned int", "NUMBER(20)", 0}, + {"long long int", "NUMBER(19)", 0, false}, + {"long long unsigned int", "NUMBER(20)", 0, false}, - {"float", "BINARY_FLOAT", 0}, - {"double", "BINARY_DOUBLE", 0}, + {"float", "BINARY_FLOAT", 0, false}, + {"double", "BINARY_DOUBLE", 0, false}, - {"::std::string", "VARCHAR2(512)", 0}, + // Oracle treats empty VARCHAR2 (and NVARCHAR2) strings as NULL. + // + {"::std::string", "VARCHAR2(512)", 0, true}, - {"::size_t", "NUMBER(20)", 0}, - {"::std::size_t", "NUMBER(20)", 0} + {"::size_t", "NUMBER(20)", 0, false}, + {"::std::size_t", "NUMBER(20)", 0, false} }; } @@ -92,7 +95,8 @@ namespace relational type_map_type::value_type v ( e.cxx_type, - db_type_type (e.db_type, e.db_id_type ? e.db_id_type : e.db_type)); + db_type_type ( + e.db_type, e.db_id_type ? e.db_id_type : e.db_type, e.null)); data_->type_map_.insert (v); } diff --git a/odb/relational/oracle/schema.cxx b/odb/relational/oracle/schema.cxx index 29c1130..f07e0d6 100644 --- a/odb/relational/oracle/schema.cxx +++ b/odb/relational/oracle/schema.cxx @@ -159,50 +159,6 @@ namespace relational }; entry create_table_; - struct create_column: relational::create_column, context - { - create_column (base const& x): base (x) {} - - virtual void - null (sema_rel::column& c) - { - // Oracle interprets empty VARCHAR2 and NVARCHAR2 strings as - // 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 ()) - { - // This should never fail since we have already parsed this. - // - sql_type const& t (parse_sql_type (c.type ())); - - if (t.type == sql_type::VARCHAR2 || t.type == sql_type::NVARCHAR2) - { - // 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 ()) - { - pk = true; - break; - } - } - - if (!pk) - return; - } - } - - base::null (c); - } - }; - entry create_column_; - struct create_foreign_key: relational::create_foreign_key, context { create_foreign_key (schema_format f, relational::create_table& ct) -- cgit v1.1