Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e64f498

Browse files
authored
Number precision from dbms_sql not correct (#908)
* Fixing issue with number from dual and precision being incorrectly read. * Updated tests
1 parent 35dbe64 commit e64f498

6 files changed

Lines changed: 58 additions & 9 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ create or replace package body ut_compound_data_helper is
237237
l_col_type := a_data_info.column_type;
238238
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('VARCHAR2','CHAR') then
239239
l_col_type := 'VARCHAR2('||greatest(a_data_info.column_len,4000)||')';
240+
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('NUMBER') then
241+
--We cannot use a precision and scale as dbms_sql.describe_columns3 return precision 0 for dual table
242+
-- there is also no need for that as we not process data but only read and compare as they are stored
243+
l_col_type := a_data_info.column_type;
240244
else
241245
l_col_type := a_data_info.column_type
242246
||case when a_data_info.column_len is not null

source/expectations/data_values/ut_cursor_column.tpb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ create or replace type body ut_cursor_column as
44
self in out nocopy ut_cursor_column,
55
a_col_name varchar2, a_col_schema_name varchar2,
66
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
7-
a_col_position integer, a_col_type varchar2, a_collection integer,a_access_path in varchar2
7+
a_col_position integer, a_col_type varchar2, a_collection integer,a_access_path in varchar2, a_col_precision in integer,
8+
a_col_scale integer
89
) is
910
begin
1011
self.parent_name := a_parent_name; --Name of the parent if its nested
1112
self.hierarchy_level := a_hierarchy_level; --Hierarchy level
1213
self.column_position := a_col_position; --Position of the column in cursor/ type
1314
self.column_len := a_col_max_len; --length of column
15+
self.column_precision := a_col_precision;
16+
self.column_scale := a_col_scale;
1417
self.column_name := TRIM( BOTH '''' FROM a_col_name); --name of the column
1518
self.column_type_name := coalesce(a_col_type_name,a_col_type); --type name e.g. test_dummy_object or varchar2
1619
self.xml_valid_name := ut_utils.get_valid_xml_name(self.column_name);
@@ -49,10 +52,12 @@ create or replace type body ut_cursor_column as
4952
constructor function ut_cursor_column( self in out nocopy ut_cursor_column,
5053
a_col_name varchar2, a_col_schema_name varchar2,
5154
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
52-
a_col_position integer, a_col_type in varchar2, a_collection integer,a_access_path in varchar2
55+
a_col_position integer, a_col_type in varchar2, a_collection integer,a_access_path in varchar2, a_col_precision in integer,
56+
a_col_scale integer
5357
) return self as result is
5458
begin
55-
init(a_col_name, a_col_schema_name, a_col_type_name, a_col_max_len, a_parent_name,a_hierarchy_level, a_col_position, a_col_type, a_collection,a_access_path);
59+
init(a_col_name, a_col_schema_name, a_col_type_name, a_col_max_len, a_parent_name,a_hierarchy_level, a_col_position,
60+
a_col_type, a_collection,a_access_path,a_col_precision,a_col_scale);
5661
return;
5762
end;
5863

source/expectations/data_values/ut_cursor_column.tps

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@ create or replace type ut_cursor_column force authid current_user as object (
2828
column_type_name varchar2(128),
2929
column_schema varchar2(128),
3030
column_len integer,
31+
column_precision integer,
32+
column_scale integer,
3133
is_sql_diffable number(1, 0),
3234
is_collection number(1, 0),
3335

3436
member procedure init(self in out nocopy ut_cursor_column,
3537
a_col_name varchar2, a_col_schema_name varchar2,
3638
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
37-
a_col_position integer, a_col_type in varchar2, a_collection integer,a_access_path in varchar2),
39+
a_col_position integer, a_col_type in varchar2, a_collection integer,a_access_path in varchar2, a_col_precision in integer,
40+
a_col_scale integer),
3841

3942
constructor function ut_cursor_column( self in out nocopy ut_cursor_column,
4043
a_col_name varchar2, a_col_schema_name varchar2,
4144
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
42-
a_col_position integer, a_col_type in varchar2, a_collection integer, a_access_path in varchar2)
45+
a_col_position integer, a_col_type in varchar2, a_collection integer, a_access_path in varchar2, a_col_precision in integer,
46+
a_col_scale integer)
4347
return self as result,
4448

4549
constructor function ut_cursor_column( self in out nocopy ut_cursor_column) return self as result

source/expectations/data_values/ut_cursor_details.tpb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ create or replace type body ut_cursor_details as
3939
l_idx,
4040
ut_compound_data_helper.get_column_type_desc(l_elements_info.type_code,false),
4141
ut_utils.boolean_to_int(l_is_collection),
42-
a_access_path
42+
a_access_path,
43+
l_elements_info.precision,
44+
l_elements_info.scale
4345
);
4446
if l_element_info.attr_elt_type is not null then
4547
desc_compound_data(
@@ -63,7 +65,9 @@ create or replace type body ut_cursor_details as
6365
l_idx,
6466
ut_compound_data_helper.get_column_type_desc(l_element_info.type_code,false),
6567
ut_utils.boolean_to_int(l_is_collection),
66-
a_access_path
68+
a_access_path,
69+
l_elements_info.precision,
70+
l_elements_info.scale
6771
);
6872
if l_element_info.attr_elt_type is not null then
6973
desc_compound_data(
@@ -114,7 +118,9 @@ create or replace type body ut_cursor_details as
114118
pos,
115119
ut_compound_data_helper.get_column_type_desc(l_columns_desc(pos).col_type,true),
116120
ut_utils.boolean_to_int(l_is_collection),
117-
null
121+
null,
122+
l_columns_desc(pos).col_precision,
123+
l_columns_desc(pos).col_scale
118124
);
119125

120126
if l_columns_desc(pos).col_type = dbms_sql.user_defined_type or l_is_collection then

test/ut3_user/expectations/test_expectations_cursor.pkb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2761,6 +2761,33 @@ Check the query and data for errors.';
27612761
ut3.ut.expect( l_actual ).to_equal( l_expected );
27622762
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_be_greater_than(0);
27632763
end;
2764-
2764+
2765+
procedure number_from_dual is
2766+
l_actual sys_refcursor;
2767+
l_expected sys_refcursor;
2768+
begin
2769+
open l_expected for select
2770+
12345 as n1,
2771+
cast(7456123.89 as number(7,-2)) as n2,
2772+
cast(7456123.89 as number(9,1)) as n3,
2773+
cast(7456123.89 as number(9,2)) as n4,
2774+
cast(7456123.89 as number(9)) as n5,
2775+
cast(7456123.89 as number(*,1)) as n6,
2776+
7456123.89 as n7
2777+
from dual;
2778+
2779+
open l_actual for select
2780+
12345 as n1,
2781+
7456100 as n2,
2782+
7456123.9 as n3,
2783+
7456123.89 as n4,
2784+
7456124 as n5,
2785+
7456123.9 as n6,
2786+
7456123.89 as n7
2787+
from dual;
2788+
ut3.ut.expect(l_actual).to_equal(l_expected);
2789+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
2790+
end;
2791+
27652792
end;
27662793
/

test/ut3_user/expectations/test_expectations_cursor.pks

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,5 +443,8 @@ create or replace package test_expectations_cursor is
443443
--%disabled
444444
procedure nulltowhitespace;
445445

446+
--%test(Check precision of number from dual #907)
447+
procedure number_from_dual;
448+
446449
end;
447450
/

0 commit comments

Comments
 (0)