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

Skip to content

Commit ae982a6

Browse files
committed
Initial checkin
1 parent 584cfcd commit ae982a6

8 files changed

Lines changed: 136 additions & 34 deletions

File tree

source/core/ut_utils.pkb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,5 +798,20 @@ create or replace package body ut_utils is
798798
return l_valid_name;
799799
end;
800800

801+
function add_prefix(a_list ut_varchar2_list, a_prefix varchar2, a_connector varchar2 := '/') return ut_varchar2_list is
802+
l_result ut_varchar2_list := ut_varchar2_list();
803+
l_idx binary_integer;
804+
begin
805+
if a_prefix is not null then
806+
l_idx := a_list.first;
807+
while l_idx is not null loop
808+
l_result.extend;
809+
l_result(l_idx) := a_prefix||a_connector||trim(leading a_connector from a_list(l_idx));
810+
l_idx := a_list.next(l_idx);
811+
end loop;
812+
end if;
813+
return l_result;
814+
end;
815+
801816
end ut_utils;
802817
/

source/core/ut_utils.pks

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,10 @@ create or replace package ut_utils authid definer is
387387
*/
388388
function get_valid_xml_name(a_name varchar2) return varchar2;
389389

390+
/**
391+
* Add prefix word to elements of list
392+
*/
393+
function add_prefix(a_list ut_varchar2_list, a_prefix varchar2, a_connector varchar2 := '/') return ut_varchar2_list;
394+
390395
end ut_utils;
391396
/

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ create or replace package body ut_compound_data_helper is
335335
l_not_equal_stmt clob;
336336
l_where_stmt clob;
337337
l_ut_owner varchar2(250) := ut_utils.ut_owner;
338-
338+
l_join_by_list ut_varchar2_list;
339+
339340
function get_join_type(a_inclusion_compare in boolean,a_negated in boolean) return varchar2 is
340341
begin
341342
return
@@ -356,12 +357,22 @@ create or replace package body ut_compound_data_helper is
356357
end;
357358

358359
begin
360+
/**
361+
* We already estabilished cursor equality so now we add anydata root if we compare anydata
362+
* to join by.
363+
*/
364+
l_join_by_list :=
365+
case
366+
when a_other is of (ut_data_value_anydata) then ut_utils.add_prefix(a_join_by_list, a_other.cursor_details.get_root)
367+
else a_join_by_list
368+
end;
369+
359370
dbms_lob.createtemporary(l_compare_sql, true);
360371
--Initiate a SQL template with placeholders
361372
ut_utils.append_to_clob(l_compare_sql, g_compare_sql_template);
362373
--Generate a pieceso of dynamic SQL that will substitute placeholders
363374
gen_sql_pieces_out_of_cursor(
364-
a_other.cursor_details.cursor_columns_info, a_join_by_list, a_unordered,
375+
a_other.cursor_details.cursor_columns_info, l_join_by_list, a_unordered,
365376
l_xmltable_stmt, l_select_stmt, l_partition_stmt, l_join_on_stmt,
366377
l_not_equal_stmt
367378
);
@@ -374,7 +385,7 @@ create or replace package body ut_compound_data_helper is
374385
l_compare_sql := replace(l_compare_sql,'{:join_type:}',get_join_type(a_inclusion_type,a_is_negated));
375386
l_compare_sql := replace(l_compare_sql,'{:join_condition:}',l_join_on_stmt);
376387

377-
if l_not_equal_stmt is not null and ((a_join_by_list.count > 0 and not a_is_negated) or (not a_unordered)) then
388+
if l_not_equal_stmt is not null and ((l_join_by_list.count > 0 and not a_is_negated) or (not a_unordered)) then
378389
ut_utils.append_to_clob(l_where_stmt,' ( '||l_not_equal_stmt||' ) or ');
379390
end if;
380391
--If its inclusion we expect a actual set to fully match and have no extra elements over expected

source/expectations/data_values/ut_cursor_details.tpb

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,25 @@ create or replace type body ut_cursor_details as
146146

147147
member function get_missing_join_by_columns( a_expected_columns ut_varchar2_list ) return ut_varchar2_list is
148148
l_result ut_varchar2_list;
149+
l_prefix varchar2(125);
149150
begin
151+
if self.is_anydata = 1 then
152+
l_prefix := get_root;
153+
end if;
154+
--regexp_replace(c.access_path,'^\/?([^\/]+\/){1}')
150155
select fl.column_value
151156
bulk collect into l_result
152157
from table(a_expected_columns) fl
153158
where not exists (
154159
select 1 from table(self.cursor_columns_info) c
155-
where regexp_like(c.access_path, '^'||fl.column_value||'($|/.*)')
160+
where regexp_like(c.access_path,'^/?'||
161+
case
162+
when self.is_anydata = 1 then
163+
l_prefix||'/'||trim (leading '/' from fl.column_value)
164+
else
165+
fl.column_value
166+
end||'($|/.*)'
167+
)
156168
)
157169
order by fl.column_value;
158170
return l_result;
@@ -162,9 +174,14 @@ create or replace type body ut_cursor_details as
162174
l_result ut_cursor_details := self;
163175
l_column_tab ut_cursor_column_tab := ut_cursor_column_tab();
164176
l_column ut_cursor_column;
177+
l_prefix varchar2(125);
165178
c_xpath_extract_reg constant varchar2(50) := '^((/ROW/)|^(//)|^(/\*/))?(.*)';
166179
begin
167180
if l_result.cursor_columns_info is not null then
181+
182+
if self.is_anydata = 1 then
183+
l_prefix := get_root;
184+
end if;
168185

169186
--limit columns to those on the include items minus exclude items
170187
if a_match_options.include.items.count > 0 then
@@ -181,8 +198,16 @@ create or replace type body ut_cursor_details as
181198
bulk collect into l_result.cursor_columns_info
182199
from table(self.cursor_columns_info) x
183200
where exists(
184-
select 1 from included_columns f where regexp_like( x.access_path, '^/?'||f.col_names||'($|/.*)' )
185-
);
201+
select 1 from included_columns f where regexp_like(x.access_path,'^/?'||
202+
case
203+
when self.is_anydata = 1 then
204+
l_prefix||'/'||trim(leading '/' from f.col_names)
205+
else
206+
f.col_names
207+
end||'($|/.*)'
208+
)
209+
)
210+
or x.hierarchy_level = case when self.is_anydata = 1 then 1 else 0 end ;
186211
end if;
187212
elsif a_match_options.exclude.items.count > 0 then
188213
with excluded_columns as (
@@ -193,7 +218,13 @@ create or replace type body ut_cursor_details as
193218
bulk collect into l_result.cursor_columns_info
194219
from table(self.cursor_columns_info) x
195220
where not exists(
196-
select 1 from excluded_columns f where regexp_like( '/'||x.access_path, '^/?'||f.col_names||'($|/.*)' )
221+
select 1 from excluded_columns f where regexp_like(x.access_path,'^/?'||
222+
case
223+
when self.is_anydata = 1 then
224+
l_prefix||'/'||trim(leading '/' from f.col_names)
225+
else
226+
f.col_names
227+
end||'($|/.*)' )
197228
);
198229
end if;
199230

@@ -226,8 +257,30 @@ create or replace type body ut_cursor_details as
226257
from table(self.cursor_columns_info) t
227258
where (a_parent_name is null and parent_name is null and hierarchy_level = 1 and column_name is not null)
228259
having count(*) > 0;
229-
230260
return l_result;
231261
end;
262+
263+
member procedure has_anydata(self in out nocopy ut_cursor_details, a_is_anydata in boolean :=false) is
264+
begin
265+
self.is_anydata := case when nvl(a_is_anydata,false) then 1 else 0 end;
266+
end;
267+
268+
member function has_anydata return boolean is
269+
begin
270+
return ut_utils.int_to_boolean(nvl(self.is_anydata,0));
271+
end;
272+
273+
member function get_root return varchar2 is
274+
l_root varchar2(250);
275+
begin
276+
if self.cursor_columns_info.count > 0 then
277+
select x.access_path into l_root from table(self.cursor_columns_info) x
278+
where x.hierarchy_level = 1;
279+
else
280+
l_root := null;
281+
end if;
282+
return l_root;
283+
end;
284+
232285
end;
233286
/

source/expectations/data_values/ut_cursor_details.tps

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ create or replace type ut_cursor_details force authid current_user as object (
1616
limitations under the License.
1717
*/
1818
cursor_columns_info ut_cursor_column_tab,
19-
19+
20+
/*if type is anydata we need to skip level 1 on joinby / inlude / exclude as its artificial cursor*/
21+
is_anydata number(1,0),
2022
constructor function ut_cursor_details(self in out nocopy ut_cursor_details) return self as result,
2123
constructor function ut_cursor_details(
2224
self in out nocopy ut_cursor_details,a_cursor_number in number
@@ -29,9 +31,12 @@ create or replace type ut_cursor_details force authid current_user as object (
2931
a_level in integer,
3032
a_access_path in varchar2
3133
),
32-
member function contains_collection return boolean,
33-
member function get_missing_join_by_columns( a_expected_columns ut_varchar2_list ) return ut_varchar2_list,
34+
member function contains_collection return boolean,
35+
member function get_missing_join_by_columns( a_expected_columns ut_varchar2_list ) return ut_varchar2_list,
3436
member procedure filter_columns(self in out nocopy ut_cursor_details, a_match_options ut_matcher_options),
35-
member function get_xml_children(a_parent_name varchar2 := null) return xmltype
37+
member function get_xml_children(a_parent_name varchar2 := null) return xmltype,
38+
member procedure has_anydata(self in out nocopy ut_cursor_details, a_is_anydata in boolean := false),
39+
member function has_anydata return boolean,
40+
member function get_root return varchar2
3641
)
3742
/

source/expectations/data_values/ut_data_value_anydata.tpb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ create or replace type body ut_data_value_anydata as
8484
self.extract_cursor(l_refcursor);
8585
l_cursor_number := dbms_sql.to_cursor_number(l_refcursor);
8686
self.cursor_details := ut_cursor_details(l_cursor_number);
87+
self.cursor_details.has_anydata(true);
8788
dbms_sql.close_cursor(l_cursor_number);
8889
elsif not l_refcursor%isopen then
8990
raise cursor_not_open;
@@ -139,5 +140,6 @@ create or replace type body ut_data_value_anydata as
139140
raise value_error;
140141
end if;
141142
end;
143+
142144
end;
143145
/

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ create or replace type body ut_data_value_refcursor as
9595
extract_cursor(l_cursor);
9696
l_cursor_number := dbms_sql.to_cursor_number(l_cursor);
9797
self.cursor_details := ut_cursor_details(l_cursor_number);
98+
self.cursor_details.has_anydata(false);
9899
dbms_sql.close_cursor(l_cursor_number);
99100
elsif not l_cursor%isopen then
100101
raise cursor_not_open;
@@ -250,8 +251,14 @@ create or replace type body ut_data_value_refcursor as
250251
if l_diff_row_count > 0 then
251252
l_row_diffs := ut_compound_data_helper.get_rows_diff_by_sql(
252253
l_self_cols, l_other_cols, l_self.data_id, l_other.data_id,
253-
l_diff_id, a_match_options.join_by.items, a_match_options.unordered,
254-
a_match_options.ordered_columns(), self.extract_path
254+
l_diff_id,
255+
case
256+
when
257+
l_self.cursor_details.is_anydata = 1 then ut_utils.add_prefix(a_match_options.join_by.items, l_self.cursor_details.get_root)
258+
else
259+
a_match_options.join_by.items
260+
end,
261+
a_match_options.unordered,a_match_options.ordered_columns(), self.extract_path
255262
);
256263
l_message := chr(10)
257264
||'Rows: [ ' || l_diff_row_count ||' differences'
@@ -359,17 +366,18 @@ create or replace type body ut_data_value_refcursor as
359366
l_other := treat(a_other as ut_data_value_refcursor);
360367
l_other.cursor_details.filter_columns( a_match_options );
361368
l_self.cursor_details.filter_columns( a_match_options );
362-
369+
363370
if a_match_options.join_by.items.count > 0 then
364371
l_result :=
365372
l_self.cursor_details.get_missing_join_by_columns( a_match_options.join_by.items ).count
366373
+ l_other.cursor_details.get_missing_join_by_columns( a_match_options.join_by.items ).count;
367374
end if;
368-
375+
369376
if l_result = 0 then
370377
if not l_self.is_null() and not l_other.is_null() and not l_self.cursor_details.equals( l_other.cursor_details, a_match_options ) then
371378
l_result := 1;
372379
end if;
380+
373381
l_diff_cursor_text := ut_compound_data_helper.gen_compare_sql(
374382
l_other,
375383
a_match_options.join_by.items,

0 commit comments

Comments
 (0)