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

Skip to content

Commit 1356f39

Browse files
committed
Update to cursor comparision
1 parent 6cb5fe7 commit 1356f39

11 files changed

Lines changed: 72 additions & 47 deletions

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ create or replace package body ut_compound_data_helper is
444444
ut_utils.append_to_clob(a_equal_stmt,l_sql_stmt);
445445
end;
446446

447+
--TODO : Scenario where join by is on whole type not a column of type e.g. NESTEDTABLE
447448
procedure generate_partition_stmt(a_data_info ut_cursor_column, a_partition_stmt in out nocopy clob,a_pk_table in ut_varchar2_list,a_col_name in varchar2) is
448449
l_alias varchar2(10) := 'ucd.';
449450
l_pk_tab ut_varchar2_list := coalesce(a_pk_table,ut_varchar2_list());
@@ -486,10 +487,20 @@ create or replace package body ut_compound_data_helper is
486487
begin
487488
if a_data_info.is_sql_diffable = 0 then
488489
l_col_type := 'XMLTYPE';
490+
--TODO : Is it right to use timestamp ?
489491
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type = 'DATE' then
490492
l_col_type := 'TIMESTAMP';
493+
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('TIMESTAMP','TIMESTAMP WITH TIME ZONE') then
494+
l_col_type := a_data_info.column_type;
495+
--TODO : Oracle bug : https://community.oracle.com/thread/1957521
496+
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type = 'TIMESTAMP WITH LOCAL TIME ZONE' then
497+
l_col_type := 'VARCHAR2(50)';
498+
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('INTERVAL DAY TO SECOND','INTERVAL YEAR TO MONTH') then
499+
l_col_type := a_data_info.column_type;
491500
else
492-
l_col_type := a_data_info.column_type||case when a_data_info.column_len is not null then '('||a_data_info.column_len||')' else null end;
501+
l_col_type := a_data_info.column_type||case when a_data_info.column_len is not null then
502+
'('||a_data_info.column_len||')'
503+
else null end;
493504
end if;
494505
l_sql_stmt := ' '||a_col_name||' '||l_col_type||q'[ PATH ']'||a_data_info.access_path||q'[',]';
495506
ut_utils.append_to_clob(a_sql_stmt, l_sql_stmt);
@@ -654,7 +665,7 @@ create or replace package body ut_compound_data_helper is
654665
end if;
655666
ut_utils.append_to_clob(l_compare_sql,l_temp_string);
656667

657-
dbms_output.put_line(l_compare_sql);
668+
--dbms_output.put_line(l_compare_sql);
658669
return l_compare_sql;
659670
end;
660671

@@ -689,15 +700,17 @@ create or replace package body ut_compound_data_helper is
689700
l_sql varchar2(32767) :=
690701
q'[with
691702
sorted as
692-
(select r_num,regexp_substr(t.column_value, '[^/]+', 1, commas.column_value) as colval,commas.column_value lev
703+
(select r_num,regexp_substr(t.column_value, '[^/]+', 1, commas.column_value) as colval,commas.column_value lev,
704+
t.column_value access_path
693705
from (select row_number() over(order by 1) r_num, column_value from ((table(:a_current_list)))) t,
694706
table(cast(multiset
695707
(select level from dual connect by level <= length(regexp_replace(t.column_value,'[^/]+')) + 1) as sys.odcinumberlist)) commas
696708
order by r_num,lev),
697709
hier as
698-
(select r_num,lev,colval column_name,lag(colval, 1) over(partition by r_num order by lev) parent_name from sorted),
710+
(select r_num,lev,colval column_name,lag(colval, 1) over(partition by r_num order by lev) parent_name , access_path
711+
from sorted),
699712
constructed as (
700-
select lev,column_name,parent_name from hier),
713+
select lev,column_name,parent_name,access_path from hier),
701714
t1(column_name, parent_name) AS (
702715
select column_name,parent_name from table(:a_cursor_info) where parent_name is null
703716
union all
@@ -712,7 +725,7 @@ create or replace package body ut_compound_data_helper is
712725
l_result ut_cursor_column_tab := ut_cursor_column_tab();
713726
begin
714727
l_sql := l_sql || q'[select ut_cursor_column(i.column_name,i.column_schema,i.column_type_name, i.column_prec,i.column_scale,i.column_len, i.parent_name,
715-
i.hierarchy_level,i.column_position, i.column_type)
728+
i.hierarchy_level,i.column_position, i.column_type, i.is_collection)
716729
from t1 join table(:a_cursor_info) i on ( nvl(t1.parent_name,1) = nvl(i.parent_name,1) and t1.column_name = i.column_name)]';
717730
if a_include then
718731
l_sql := l_sql || ' join constructed c on ( nvl(t1.parent_name,1) = nvl(c.parent_name,1) and t1.column_name = c.column_name)';
@@ -732,7 +745,7 @@ create or replace package body ut_compound_data_helper is
732745
l_sql varchar2(32767) := get_cursor_vs_list_sql;
733746
l_result ut_varchar2_list := ut_varchar2_list();
734747
begin
735-
l_sql := l_sql || q'[select c.parent_name || case when c.parent_name is null then null else '/' end ||c.column_name
748+
l_sql := l_sql || q'[select c.access_path
736749
from t1 join table(:a_cursor_info) i on ( nvl(t1.parent_name,1) = nvl(i.parent_name,1) and t1.column_name = i.column_name)]';
737750
l_sql := l_sql ||'right outer join constructed c on ( nvl(t1.parent_name,1) = nvl(c.parent_name,1) and t1.column_name = c.column_name)
738751
where t1.column_name is null';

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,21 @@ create or replace type body ut_compound_data_value as
229229
if (ut_utils.gc_diff_max_rows > l_sql_rowcount ) then
230230
ut_compound_data_helper.insert_diffs_result(l_diff_tab,l_diff_id);
231231
end if;
232-
233232
l_sql_rowcount := l_sql_rowcount + l_diff_tab.count;
234233
if (ut_utils.gc_diff_max_rows <= l_sql_rowcount and l_max_rows != ut_utils.gc_bc_fetch_limit ) then
235234
l_max_rows := ut_utils.gc_bc_fetch_limit;
236235
end if;
237-
end loop;
236+
end loop;
237+
238+
ut_compound_data_helper.set_rows_diff(l_sql_rowcount);
238239
--result is OK only if both are same
239-
if l_sql_rowcount = 0 and ( self.elements_count = l_other.elements_count or a_inclusion_compare )then
240-
l_result := 0;
241-
else
242-
ut_compound_data_helper.set_rows_diff(l_sql_rowcount);
243-
l_result := 1;
244-
end if;
245-
return l_result;
240+
if l_sql_rowcount = 0 and ( self.elements_count = l_other.elements_count or a_inclusion_compare )then
241+
l_result := 0;
242+
else
243+
l_result := 1;
244+
end if;
245+
246+
return l_result;
246247

247248
end;
248249

source/expectations/data_values/ut_curr_usr_compound_helper.pkb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,22 @@ create or replace package body ut_curr_usr_compound_helper is
3434
return ut_utils.boolean_to_int(is_sql_compare_allowed(a_type_name));
3535
end;
3636

37-
function is_collection (a_owner varchar2,a_type_name varchar2) return boolean is
37+
function is_collection (a_owner varchar2,a_type_name varchar2, a_anytype_code in integer :=null) return boolean is
3838
l_type_view varchar2(200) := ut_metadata.get_dba_view('dba_types');
3939
l_typecode varchar2(100);
4040
begin
41-
execute immediate 'select typecode from '||l_type_view ||'
42-
where owner = :owner and type_name = :typename'
43-
into l_typecode using a_owner,a_type_name;
4441

45-
return l_typecode = 'COLLECTION';
42+
if a_anytype_code is null then
43+
44+
execute immediate 'select typecode from '||l_type_view ||'
45+
where owner = :owner and type_name = :typename'
46+
into l_typecode using a_owner,a_type_name;
47+
48+
return l_typecode = 'COLLECTION';
49+
else
50+
return a_anytype_code in (dbms_types.typecode_varray,dbms_types.typecode_table,dbms_types.typecode_namedcollection);
51+
end if;
52+
4653
exception
4754
when no_data_found then
4855
return false;

source/expectations/data_values/ut_curr_usr_compound_helper.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ create or replace package ut_curr_usr_compound_helper authid current_user is
44

55
function is_sql_compare_int(a_type_name varchar2) return integer;
66

7-
function is_collection (a_owner varchar2,a_type_name varchar2) return boolean;
7+
function is_collection (a_owner varchar2,a_type_name varchar2, a_anytype_code in integer :=null) return boolean;
88

99
--TODO Depracate once switch fully to type
1010
procedure get_columns_info(

source/expectations/data_values/ut_cursor_column.tpb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ create or replace type body ut_cursor_column as
33
member procedure init(self in out nocopy ut_cursor_column,
44
a_col_name varchar2, a_col_schema_name varchar2,
55
a_col_type_name varchar2, a_col_prec integer, a_col_scale integer,
6-
a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level number := 1,
7-
a_col_position number, a_col_type varchar2) is
6+
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) is
88
begin
99
self.parent_name := a_parent_name;
1010
self.hierarchy_level := a_hierarchy_level;
@@ -29,7 +29,7 @@ create or replace type body ut_cursor_column as
2929
ut_utils.boolean_to_int(ut_curr_usr_compound_helper.is_sql_compare_allowed(self.column_type))
3030
end;
3131
--TODO : Part of the constructor same as has nested ??
32-
self.is_collection := ut_utils.boolean_to_int(ut_curr_usr_compound_helper.is_collection(a_col_schema_name,a_col_type_name));
32+
self.is_collection := a_collection;
3333
--TODO : fix that as is nasty hardcode
3434
self.has_nested_col := case when lower(self.column_type) = 'user_defined_type' and self.is_collection = 0 then 1 else 0 end;
3535
end;
@@ -42,11 +42,11 @@ create or replace type body ut_cursor_column as
4242
constructor function ut_cursor_column( self in out nocopy ut_cursor_column,
4343
a_col_name varchar2, a_col_schema_name varchar2,
4444
a_col_type_name varchar2, a_col_prec integer, a_col_scale integer,
45-
a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level number := 1,
46-
a_col_position number, a_col_type in varchar2) return self as result is
45+
a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
46+
a_col_position integer, a_col_type in varchar2, a_collection integer) return self as result is
4747
begin
4848
init(a_col_name, a_col_schema_name, a_col_type_name, a_col_prec,
49-
a_col_scale, a_col_max_len, a_parent_name,a_hierarchy_level, a_col_position, a_col_type);
49+
a_col_scale, a_col_max_len, a_parent_name,a_hierarchy_level, a_col_position, a_col_type, a_collection);
5050
return;
5151
end;
5252
end;

source/expectations/data_values/ut_cursor_column.tps

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ create or replace type ut_cursor_column force authid current_user as object
2020
member procedure init(self in out nocopy ut_cursor_column,
2121
a_col_name varchar2, a_col_schema_name varchar2,
2222
a_col_type_name varchar2, a_col_prec integer, a_col_scale integer,
23-
a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level number := 1,
24-
a_col_position number, a_col_type in varchar2),
23+
a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
24+
a_col_position integer, a_col_type in varchar2, a_collection integer),
2525

2626
constructor function ut_cursor_column( self in out nocopy ut_cursor_column,
2727
a_col_name varchar2, a_col_schema_name varchar2,
2828
a_col_type_name varchar2, a_col_prec integer, a_col_scale integer,
29-
a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level number := 1,
30-
a_col_position number, a_col_type in varchar2)
29+
a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
30+
a_col_position integer, a_col_type in varchar2, a_collection integer)
3131
return self as result
3232
)
3333
/

source/expectations/data_values/ut_cursor_details.tpb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ create or replace type body ut_cursor_details as
33
order member function compare(a_other ut_cursor_details) return integer is
44
l_diffs integer;
55
begin
6+
67
select count(1) into l_diffs
78
from table(self.cursor_info) a full outer join table(a_other.cursor_info) e
89
on ( decode(a.parent_name,e.parent_name,1,0)= 1 and a.column_name = e.column_name and
9-
REPLACE(a.column_type,'VARCHAR','CHAR') = REPLACE(e.column_type,'VARCHAR','CHAR')
10+
REPLACE(a.column_type,'VARCHAR2','CHAR') = REPLACE(e.column_type,'VARCHAR2','CHAR')
1011
and a.column_position = e.column_position )
1112
where a.column_name is null or e.column_name is null;
13+
1214
return l_diffs;
1315
end;
1416

@@ -69,7 +71,8 @@ create or replace type body ut_cursor_details as
6971
l_csid pls_integer;
7072
l_csfrm pls_integer;
7173
l_attr_elt_type anytype;
72-
l_anytype anytype;
74+
l_anytype anytype;
75+
l_is_collection boolean;
7376
begin
7477
self.cursor_info := ut_cursor_column_tab();
7578
l_cursor_number := dbms_sql.to_cursor_number(a_cursor);
@@ -79,6 +82,7 @@ create or replace type body ut_cursor_details as
7982
a_cursor := dbms_sql.to_refcursor(l_cursor_number);
8083

8184
for cur in 1 .. l_columns_count loop
85+
l_is_collection := ut_curr_usr_compound_helper.is_collection(l_columns_desc(cur).col_schema_name,l_columns_desc(cur).col_type_name);
8286
self.cursor_info.extend;
8387
self.cursor_info(cursor_info.last) := ut_cursor_column( l_columns_desc(cur).col_name,
8488
l_columns_desc(cur).col_schema_name,
@@ -89,11 +93,10 @@ create or replace type body ut_cursor_details as
8993
null,
9094
1,
9195
cur,
92-
ut_curr_usr_compound_helper.get_column_type_desc(l_columns_desc(cur).col_type,true)
96+
ut_curr_usr_compound_helper.get_column_type_desc(l_columns_desc(cur).col_type,true),
97+
ut_utils.boolean_to_int(l_is_collection)
9398
);
94-
if l_columns_desc(cur).col_type = dbms_sql.user_defined_type
95-
and
96-
not ut_curr_usr_compound_helper.is_collection(l_columns_desc(cur).col_schema_name,l_columns_desc(cur).col_type_name) then
99+
if l_columns_desc(cur).col_type = dbms_sql.user_defined_type and not l_is_collection then
97100
l_anytype := get_user_defined_type(l_columns_desc(cur).col_schema_name , l_columns_desc(cur).col_type_name );
98101
for i in 1 .. get_anytype_attribute_count(l_anytype) loop
99102
l_attribute_typecode := l_anytype.getattreleminfo(pos => i, --First attribute
@@ -105,17 +108,19 @@ create or replace type body ut_cursor_details as
105108
attr_elt_type => l_attr_elt_type,
106109
aname => l_aname);
107110

111+
l_is_collection := ut_curr_usr_compound_helper.is_collection(l_columns_desc(cur).col_schema_name,l_columns_desc(cur).col_type_name,l_attribute_typecode);
108112
self.cursor_info.extend;
109113
self.cursor_info(cursor_info.last) := ut_cursor_column( l_aname,
110-
null,
114+
l_columns_desc(cur).col_schema_name,
111115
null,
112116
l_prec,
113117
l_scale,
114118
l_len,
115119
l_columns_desc(cur).col_name,
116120
2,
117121
i,
118-
ut_curr_usr_compound_helper.get_column_type_desc(l_attribute_typecode,false)
122+
ut_curr_usr_compound_helper.get_column_type_desc(l_attribute_typecode,false),
123+
ut_utils.boolean_to_int(l_is_collection)
119124
);
120125
end loop;
121126
end if;

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ create or replace type body ut_data_value_refcursor as
248248
l_result := case when (l_pk_missing_tab.count > 0) then 1 else 0 end;
249249
end if;
250250

251+
251252
if l_result = 0 then
252253
if (self.cursor_details is not null and l_actual.cursor_details is not null) and (self.cursor_details != l_actual.cursor_details) then
253254
l_result := 1;

source/expectations/matchers/ut_include.tpb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ create or replace type body ut_include as
5151
overriding member function run_matcher(self in out nocopy ut_include, a_actual ut_data_value) return boolean is
5252
l_result boolean;
5353
l_actual ut_data_value;
54+
l_result1 integer;
5455
begin
5556
--TODO : Join by exclude an include should show differences
5657
if self.expected.data_type = a_actual.data_type then

source/expectations/ut_expectation.tpb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@ create or replace type body ut_expectation as
3333
l_message varchar2(32767);
3434
begin
3535
--Negated matcher for include option.
36-
if (l_matcher is of (ut_include)) then
37-
l_expectation_result := l_matcher.run_matcher( self.actual_data );
38-
else
39-
l_expectation_result := l_matcher.run_matcher_negated( self.actual_data );
40-
end if;
36+
l_expectation_result := l_matcher.run_matcher_negated( self.actual_data );
4137
l_expectation_result := coalesce(l_expectation_result,false);
38+
4239
l_message := coalesce( l_matcher.error_message( self.actual_data ), l_matcher.failure_message_when_negated( self.actual_data ) );
4340
ut_expectation_processor.add_expectation_result( ut_expectation_result( ut_utils.to_test_result( l_expectation_result ), self.description, l_message ) );
4441
end;

0 commit comments

Comments
 (0)