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

Skip to content

Commit a1e8113

Browse files
committed
Fixed 11g R2 compatibility.
1 parent 0a6a43e commit a1e8113

2 files changed

Lines changed: 61 additions & 41 deletions

File tree

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,51 @@ create or replace type body ut_data_value_refcursor as
136136
end;
137137

138138
overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2 ) return varchar2 is
139-
c_max_rows constant integer := 20;
140-
l_results ut_utils.t_clob_tab;
141-
l_result clob;
142-
l_result_string varchar2(32767);
143-
l_ut_owner varchar2(250) := ut_utils.ut_owner;
144-
l_diff_row_count integer;
145-
l_actual ut_data_value_refcursor;
146-
l_diff_id raw(16);
147-
l_column_diffs ut_refcursor_helper.tt_column_diffs;
148-
l_row_diffs ut_refcursor_helper.tt_row_diffs;
149-
l_exclude_list ut_varchar2_list := ut_varchar2_list();
150-
l_exclude_xpath varchar2(32767);
139+
c_max_rows constant integer := 20;
140+
l_results ut_utils.t_clob_tab := ut_utils.t_clob_tab();
141+
l_result clob;
142+
l_result_string varchar2(32767);
143+
l_ut_owner varchar2(250) := ut_utils.ut_owner;
144+
l_diff_row_count integer;
145+
l_actual ut_data_value_refcursor;
146+
l_diff_id raw(16);
147+
l_column_diffs ut_refcursor_helper.tt_column_diffs := ut_refcursor_helper.tt_column_diffs();
148+
l_row_diffs ut_refcursor_helper.tt_row_diffs;
149+
l_exclude_xpath varchar2(32767);
150+
function get_col_diff_text(a_col ut_refcursor_helper.t_column_diffs) return varchar2 is
151+
begin
152+
return
153+
case a_col.diff_type
154+
when '-' then
155+
' Column <'||a_col.expected_name||'> [data-type: '||a_col.expected_type||'] is missing. Expected column position: '||a_col.expected_pos||'.'
156+
when '+' then
157+
' Column <'||a_col.actual_name||'> [position: '||a_col.actual_pos||', data-type: '||a_col.actual_type||'] is not expected in results.'
158+
when 't' then
159+
' Column <'||a_col.actual_name||'> data-type is invalid. Expected: '||a_col.expected_type||',' ||' actual: '||a_col.actual_type||'.'
160+
when 'p' then
161+
' Column <'||a_col.actual_name||'> is misplaced. Expected position: '||a_col.expected_pos||',' ||' actual position: '||a_col.actual_pos||'.'
162+
end;
163+
end;
164+
function add_incomparable_cols_to_xpath(
165+
a_column_diffs ut_refcursor_helper.tt_column_diffs, a_exclude_xpath varchar2
166+
) return varchar2 is
167+
l_incomparable_cols ut_varchar2_list := ut_varchar2_list();
168+
l_result varchar2(32767);
169+
begin
170+
for i in 1 .. a_column_diffs.count loop
171+
if a_column_diffs(i).diff_type in ('-','+') then
172+
l_incomparable_cols.extend;
173+
l_incomparable_cols(l_incomparable_cols.last) := coalesce(a_column_diffs(i).expected_name,a_column_diffs(i).actual_name);
174+
end if;
175+
end loop;
176+
l_result := ut_utils.to_xpath(l_incomparable_cols);
177+
if a_exclude_xpath is not null and l_result is not null then
178+
l_result := l_result ||'|'||a_exclude_xpath;
179+
else
180+
l_result := coalesce(a_exclude_xpath, l_result);
181+
end if;
182+
return l_result;
183+
end;
151184
begin
152185
if not a_other is of (ut_data_value_refcursor) then
153186
raise value_error;
@@ -157,54 +190,40 @@ create or replace type body ut_data_value_refcursor as
157190
dbms_lob.createtemporary(l_result,true);
158191

159192
if not self.is_null and not l_actual.is_null then
160-
161193
l_column_diffs := ut_refcursor_helper.get_columns_diff(self.columns_info, l_actual.columns_info, a_exclude_xpath, a_include_xpath);
162194

163-
select case diff_type
164-
when '-' then ' Column <'||expected_name||'> [data-type: '||expected_type||'] is missing. Expected column position: '||expected_pos||'.'
165-
when '+' then ' Column <'||actual_name||'> [position: '||actual_pos||', data-type: '||actual_type||'] is not expected in results.'
166-
when 't' then ' Column <'||actual_name||'> data-type is invalid. Expected: '||expected_type||', actual: '||actual_type||'.'
167-
when 'p' then ' Column <'||actual_name||'> is misplaced. Expected position: '||expected_pos||', actual position: '||actual_pos||'.'
168-
end diff_msg
169-
bulk collect into l_results
170-
from table(l_column_diffs)
171-
order by expected_pos, actual_pos;
172-
173-
if l_results.count > 0 then
195+
if l_column_diffs.count > 0 then
174196
ut_utils.append_to_clob(l_result,chr(10) || 'Columns:' || chr(10));
175-
ut_utils.append_to_clob(l_result,l_results);
176197
end if;
177198

178-
select coalesce(expected_name,actual_name)
179-
bulk collect into l_exclude_list
180-
from table(l_column_diffs)
181-
where diff_type in ('-','+');
182-
end if;
183-
l_exclude_xpath := ut_utils.to_xpath(l_exclude_list);
184-
if a_exclude_xpath is not null then
185-
l_exclude_xpath := l_exclude_xpath || a_exclude_xpath;
199+
for i in 1 .. l_column_diffs.count loop
200+
l_results.extend;
201+
l_results(l_results.last) := get_col_diff_text(l_column_diffs(i));
202+
end loop;
203+
ut_utils.append_to_clob(l_result, l_results);
204+
l_results.delete;
186205
end if;
187206

207+
l_exclude_xpath := add_incomparable_cols_to_xpath(l_column_diffs, a_exclude_xpath);
208+
188209
l_diff_id := dbms_crypto.hash(self.data_set_guid||l_actual.data_set_guid,2);
189210
-- First tell how many rows are different
190211
execute immediate 'select count(*) from ' || l_ut_owner || '.ut_data_set_diff_tmp where diff_id = :diff_id' into l_diff_row_count using l_diff_id;
191212

192213
if l_diff_row_count > 0 then
193214
l_row_diffs := ut_refcursor_helper.get_rows_diff(
194-
self.data_set_guid, l_actual.data_set_guid, l_diff_id,
195-
c_max_rows, l_exclude_xpath, a_include_xpath
215+
self.data_set_guid, l_actual.data_set_guid, l_diff_id, c_max_rows, l_exclude_xpath, a_include_xpath
196216
);
197217

198-
select ' Row No. '||rn||' - '||rpad(diff_type,10)||diffed_row diff
199-
bulk collect into l_results
200-
from table(l_row_diffs)
201-
order by rn, diff_type;
202-
203-
if l_results.count = 0 then
218+
if l_row_diffs.count = 0 then
204219
ut_utils.append_to_clob(l_result,chr(10) || 'Rows:'||chr(10)||' All rows are different as the columns are not matching.');
205220
else
206221
ut_utils.append_to_clob(l_result,chr(10) || 'Rows: [ diff count = ' || to_char(l_diff_row_count) ||' ]' || chr(10));
207222
end if;
223+
for i in 1 .. l_row_diffs.count loop
224+
l_results.extend;
225+
l_results(l_results.last) := ' Row No. '||l_row_diffs(i).rn||' - '||rpad(l_row_diffs(i).diff_type,10)||l_row_diffs(i).diffed_row;
226+
end loop;
208227
ut_utils.append_to_clob(l_result,l_results);
209228
end if;
210229

source/expectations/data_values/ut_refcursor_helper.pkb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ create or replace package body ut_refcursor_helper is
193193
)act
194194
on exp.item_no = act.item_no
195195
where exp.item_no is null or act.item_no is null
196+
order by 1, 2
196197
]'
197198
bulk collect into l_results
198199
using a_diff_id, a_max_rows,

0 commit comments

Comments
 (0)