@@ -78,8 +78,21 @@ cdef str DBO_CACHE_SQL_GET_COLUMNS = """
7878 then data_length
7979 else 0
8080 end,
81- nvl(data_precision, 0),
82- nvl(data_scale, 0)
81+ case
82+ when data_precision is null and data_scale is null
83+ then 0
84+ when data_precision is null
85+ then 38
86+ else data_precision
87+ end,
88+ case
89+ when data_precision is null and data_scale is null
90+ and data_type = 'NUMBER'
91+ then -127
92+ when data_scale is null
93+ then 0
94+ else data_scale
95+ end
8396 from all_tab_cols
8497 where owner = :owner
8598 and table_name = substr(:name, 1, length(:name) - 8)
@@ -307,10 +320,13 @@ cdef class BaseThinDbObjectTypeCache:
307320 # process the type code
308321 if attr_type == TNS_OBJ_TDS_TYPE_NUMBER:
309322 ora_type_num = ORA_TYPE_NUM_NUMBER
310- buf.read_sb1(precision)
311- buf.read_sb1(scale)
312- preferred_num_type[0 ] = \
313- get_preferred_num_type(precision[0 ], scale[0 ])
323+ buf.read_sb1(& temp_precision)
324+ buf.read_sb1(& temp_scale)
325+ if temp_precision != 0 or temp_scale != 0 :
326+ precision[0 ] = temp_precision
327+ scale[0 ] = temp_scale
328+ preferred_num_type[0 ] = \
329+ get_preferred_num_type(precision[0 ], scale[0 ])
314330 elif attr_type == TNS_OBJ_TDS_TYPE_FLOAT:
315331 ora_type_num = ORA_TYPE_NUM_NUMBER
316332 buf.skip_raw_bytes(1 ) # precision
@@ -389,13 +405,34 @@ cdef class BaseThinDbObjectTypeCache:
389405 attr_impl.dbtype = DB_TYPE_OBJECT
390406 attr_impl.objtype = attr_typ_impl
391407 else :
392- attr_impl.dbtype = DbType._from_ora_name(type_name)
393- attr_impl.max_size = max_size
394- if precision != 0 or scale != 0 :
395- attr_impl.precision = precision
396- attr_impl.scale = scale
408+ if type_name in (" INTEGER" , " SMALLINT" ):
409+ attr_impl.dbtype = DB_TYPE_NUMBER
410+ attr_impl.precision = 38
411+ attr_impl.scale = 0
412+ elif type_name == " REAL" :
413+ attr_impl.dbtype = DB_TYPE_NUMBER
414+ attr_impl.precision = 63
415+ attr_impl.scale = - 127
416+ elif type_name in (" DOUBLE PRECISION" , " FLOAT" ):
417+ attr_impl.dbtype = DB_TYPE_NUMBER
418+ # the database sends type name "FLOAT" instead of type name
419+ # "REAL" when looking at table metadata but not when examining
420+ # database object attribute metadata so account for that here
421+ if precision != 0 :
422+ attr_impl.precision = precision
423+ else :
424+ attr_impl.precision = 126
425+ attr_impl.scale = - 127
426+ else :
427+ attr_impl.dbtype = DbType._from_ora_name(type_name)
428+ attr_impl.max_size = max_size
429+ if attr_impl.dbtype._ora_type_num == ORA_TYPE_NUM_NUMBER:
430+ attr_impl.precision = precision
431+ attr_impl.scale = scale
432+ if attr_impl.dbtype._ora_type_num == ORA_TYPE_NUM_NUMBER:
397433 attr_impl._preferred_num_type = \
398- get_preferred_num_type(precision, scale)
434+ get_preferred_num_type(attr_impl.precision,
435+ attr_impl.scale)
399436 typ_impl.attrs.append(attr_impl)
400437 typ_impl.attrs_by_name[name] = attr_impl
401438
0 commit comments