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

Skip to content

Commit 8ceb774

Browse files
committed
Fix to issue when column was removed from the middle of cursor using a exclude or include.
this left a gap in orders and cause an columns mismatch on position for remainder of columns.
1 parent 541809e commit 8ceb774

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

source/expectations/data_values/ut_cursor_details.tpb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ create or replace type body ut_cursor_details as
160160

161161
member procedure filter_columns(self in out nocopy ut_cursor_details, a_match_options ut_matcher_options) is
162162
l_result ut_cursor_details := self;
163+
l_column_tab ut_cursor_column_tab := ut_cursor_column_tab();
164+
l_column ut_cursor_column;
163165
c_xpath_extract_reg constant varchar2(50) := '^((/ROW/)|^(//)|^(/\*/))?(.*)';
164166
begin
165167
if l_result.cursor_columns_info is not null then
@@ -194,6 +196,22 @@ create or replace type body ut_cursor_details as
194196
select 1 from excluded_columns f where regexp_like( '/'||x.access_path, '^/?'||f.col_names||'($|/.*)' )
195197
);
196198
end if;
199+
200+
--Rewrite column order after columns been excluded
201+
for i in (
202+
select parent_name, access_path, display_path, has_nested_col,
203+
transformed_name, hierarchy_level,
204+
row_number() over (partition by parent_name,transformed_name order by column_position) as new_position, xml_valid_name,
205+
column_name, column_type, column_type_name, column_schema,
206+
column_len, column_precision ,column_scale ,is_sql_diffable, is_collection,value(x) col_info
207+
from table(l_result.cursor_columns_info) x) loop
208+
l_column := i.col_info;
209+
l_column.column_position := i.new_position;
210+
l_column_tab.extend;
211+
l_column_tab(l_column_tab.last) := l_column;
212+
end loop;
213+
214+
l_result.cursor_columns_info := l_column_tab;
197215
self := l_result;
198216
end if;
199217
end;

test/ut3_user/expectations/test_expectations_cursor.pkb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,5 +2831,16 @@ Check the query and data for errors.';
28312831
$end
28322832
end;
28332833

2834+
procedure uc_columns_exclude is
2835+
v_actual SYS_REFCURSOR;
2836+
v_expected SYS_REFCURSOR;
2837+
begin
2838+
open v_expected for
2839+
select to_Char(null) id, 'ok' name from dual;
2840+
open v_actual for
2841+
select 'ok' name, to_number(null) id from dual;
2842+
2843+
ut3.ut.expect(v_actual).to_equal(v_expected).exclude('ID');
2844+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
28342845
end;
28352846
/

test/ut3_user/expectations/test_expectations_cursor.pks

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,5 +459,8 @@ create or replace package test_expectations_cursor is
459459

460460
type t_num_tab is table of t_num_rec index by binary_integer;
461461

462+
--%test( Mixed column order exclusion )
463+
procedure uc_columns_exclude;
464+
462465
end;
463466
/

0 commit comments

Comments
 (0)