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

Skip to content

Commit 169d0fe

Browse files
committed
Changed names on internal columns in cursor & object compare.
Columns: - ITEM_DATA - DATA_ID - ITEM_NO - DUP_NO - POSITION Can now be safely used in cursors. Resolves #997 Added delete on DIFF temp tables after cursor / object compare. Resolves #998
1 parent 8739173 commit 169d0fe

3 files changed

Lines changed: 80 additions & 27 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,46 +28,46 @@ create or replace package body ut_compound_data_helper is
2828
with exp as (
2929
select
3030
ucd.*,
31-
{:duplicate_number:} dup_no
31+
{:duplicate_number:} "UT3$_Dup#No"
3232
from (
3333
select
34-
ucd.item_data
35-
,x.data_id data_id
36-
,position + x.item_no item_no
34+
ucd."UT3$_Item#Data"
35+
,x.data_id "UT3$_Data#Id"
36+
,ucd."UT3$_Position#" + x.item_no "UT3$_Item#No"
3737
{:columns:}
3838
from ut_compound_data_tmp x,
3939
xmltable('/ROWSET/ROW' passing x.item_data columns
40-
item_data xmltype path '*'
41-
,position for ordinality
40+
"UT3$_Item#Data" xmltype path '*'
41+
,"UT3$_Position#" for ordinality
4242
{:xml_to_columns:} ) ucd
43-
where data_id = :exp_guid
43+
where x.data_id = :exp_guid
4444
) ucd
4545
)
4646
, act as (
4747
select
4848
ucd.*,
49-
{:duplicate_number:} dup_no
49+
{:duplicate_number:} "UT3$_Dup#No"
5050
from (
5151
select
52-
ucd.item_data
53-
,x.data_id data_id
54-
,position + x.item_no item_no
52+
ucd."UT3$_Item#Data"
53+
,x.data_id "UT3$_Data#Id"
54+
,ucd."UT3$_Position#" + x.item_no "UT3$_Item#No"
5555
{:columns:}
5656
from ut_compound_data_tmp x,
5757
xmltable('/ROWSET/ROW' passing x.item_data columns
58-
item_data xmltype path '*'
59-
,position for ordinality
58+
"UT3$_Item#Data" xmltype path '*'
59+
,"UT3$_Position#" for ordinality
6060
{:xml_to_columns:} ) ucd
61-
where data_id = :act_guid
61+
where x.data_id = :act_guid
6262
) ucd
6363
)
6464
select
65-
a.item_data as act_item_data,
66-
a.data_id act_data_id,
67-
e.item_data as exp_item_data,
68-
e.data_id exp_data_id,
65+
a."UT3$_Item#Data" as act_item_data,
66+
a."UT3$_Data#Id" act_data_id,
67+
e."UT3$_Item#Data" as exp_item_data,
68+
e."UT3$_Data#Id" exp_data_id,
6969
{:item_no:} as item_no,
70-
nvl(e.dup_no,a.dup_no) dup_no
70+
nvl(e."UT3$_Dup#No",a."UT3$_Dup#No") dup_no
7171
from act a {:join_type:} exp e on ( {:join_condition:} )
7272
where {:where_condition:}]';
7373

@@ -306,16 +306,16 @@ create or replace package body ut_compound_data_helper is
306306
a_join_by_stmt := ut_utils.table_to_clob(l_join_by_list, ' and ');
307307
elsif a_unordered then
308308
-- If no key defined do the join on all columns
309-
a_join_by_stmt := ' e.dup_no = a.dup_no and '||ut_utils.table_to_clob(l_equal_list, ' and ');
309+
a_join_by_stmt := ' e."UT3$_Dup#No" = a."UT3$_Dup#No" and '||ut_utils.table_to_clob(l_equal_list, ' and ');
310310
else
311311
-- Else join on rownumber
312-
a_join_by_stmt := 'a.item_no = e.item_no ';
312+
a_join_by_stmt := 'a."UT3$_Item#No" = e."UT3$_Item#No" ';
313313
end if;
314314
a_not_equal_stmt := ut_utils.table_to_clob(l_not_equal_list, ' or ');
315315
else
316316
--Partition by piece when no data
317317
ut_utils.append_to_clob(a_partition_stmt,' 1 ');
318-
a_join_by_stmt := 'a.item_no = e.item_no ';
318+
a_join_by_stmt := 'a."UT3$_Item#No" = e."UT3$_Item#No" ';
319319
end if;
320320
end;
321321

@@ -349,8 +349,8 @@ create or replace package body ut_compound_data_helper is
349349
begin
350350
return
351351
case
352-
when a_unordered then 'row_number() over ( order by nvl(e.item_no,a.item_no))'
353-
else 'nvl(e.item_no,a.item_no) '
352+
when a_unordered then 'row_number() over ( order by nvl(e."UT3$_Item#No",a."UT3$_Item#No"))'
353+
else 'nvl(e."UT3$_Item#No",a."UT3$_Item#No") '
354354
end;
355355
end;
356356

@@ -387,9 +387,9 @@ create or replace package body ut_compound_data_helper is
387387
end if;
388388
--If its inclusion we expect a actual set to fully match and have no extra elements over expected
389389
if a_inclusion_type then
390-
ut_utils.append_to_clob(l_where_stmt,case when a_is_negated then ' 1 = 1 ' else ' ( a.data_id is null ) ' end);
390+
ut_utils.append_to_clob(l_where_stmt,case when a_is_negated then ' 1 = 1 ' else ' ( a."UT3$_Data#Id" is null ) ' end);
391391
else
392-
ut_utils.append_to_clob(l_where_stmt,' (a.data_id is null or e.data_id is null) ');
392+
ut_utils.append_to_clob(l_where_stmt,' (a."UT3$_Data#Id" is null or e."UT3$_Data#Id" is null) ');
393393
end if;
394394

395395
l_compare_sql := replace(l_compare_sql,'{:where_condition:}',l_where_stmt);
@@ -561,6 +561,8 @@ create or replace package body ut_compound_data_helper is
561561
procedure cleanup_diff is
562562
begin
563563
g_diff_count := 0;
564+
delete from ut_compound_data_diff_tmp;
565+
delete from ut_json_data_diff_tmp;
564566
end;
565567

566568
function get_rows_diff_count return integer is

test/ut3_user/expectations/test_expectations_cursor.pkb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,5 +2825,50 @@ Check the query and data for errors.';
28252825
$end
28262826
end;
28272827

2828+
procedure compare_specific_column_names is
2829+
function get_cursor return sys_refcursor is
2830+
l_result sys_refcursor;
2831+
begin
2832+
open l_result for
2833+
select 'a' as item_data, rownum as data_id, rownum as item_no, rownum as dup_no, rownum as position from dual;
2834+
return l_result;
2835+
end;
2836+
begin
2837+
ut3.ut.expect(get_cursor()).to_equal(get_cursor());
2838+
ut3.ut.expect(get_cursor()).to_equal(get_cursor()).unordered();
2839+
ut3.ut.expect(get_cursor()).to_equal(get_cursor()).join_by('ITEM_DATA,DATA_ID,ITEM_NO,DUP_NO');
2840+
--Assert
2841+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
2842+
end;
2843+
2844+
procedure multiple_cursor_expectations is
2845+
l_actual sys_refcursor;
2846+
l_expected sys_refcursor;
2847+
begin
2848+
open l_actual for select rownum rn from dual connect by level < 5;
2849+
open l_expected for select rownum rn from dual connect by level = 1;
2850+
ut3.ut.expect(l_actual).to_equal(l_expected);
2851+
open l_actual for select rownum rn from dual connect by level < 3;
2852+
open l_expected for select * from (select rownum rn from dual connect by level < 3) order by 1 desc;
2853+
ut3.ut.expect(l_actual).to_equal(l_expected);
2854+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations(1)).to_equal(
2855+
'Actual: refcursor [ count = 4 ] was expected to equal: refcursor [ count = 1 ]
2856+
Diff:
2857+
Rows: [ 3 differences ]
2858+
Row No. 2 - Extra: <RN>2</RN>
2859+
Row No. 3 - Extra: <RN>3</RN>
2860+
Row No. 4 - Extra: <RN>4</RN>'
2861+
);
2862+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations(2)).to_equal(
2863+
'Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]
2864+
Diff:
2865+
Rows: [ 2 differences ]
2866+
Row No. 1 - Actual: <RN>1</RN>
2867+
Row No. 1 - Expected: <RN>2</RN>
2868+
Row No. 2 - Actual: <RN>2</RN>
2869+
Row No. 2 - Expected: <RN>1</RN>'
2870+
);
2871+
end;
2872+
28282873
end;
28292874
/

test/ut3_user/expectations/test_expectations_cursor.pks

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,14 @@ create or replace package test_expectations_cursor is
462462
--%test( Mixed column order exclusion )
463463
procedure uc_columns_exclude;
464464

465-
--%test(Compares cursors with long column names - Issue #952 )
465+
--%test( Compares cursors with long column names - Issue #952 )
466466
procedure compare_long_column_names;
467467

468+
--%test( Compares cursors with specific column names - Issue #997 )
469+
procedure compare_specific_column_names;
470+
471+
--%test( Multiple failures reported correctly - Issue #998 )
472+
procedure multiple_cursor_expectations;
473+
468474
end;
469475
/

0 commit comments

Comments
 (0)