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

Skip to content

Commit 1fbf433

Browse files
authored
Fix/oracle bug with xmlspaces (#895)
* Address issue with whitespace in XML. Cursor describe is ignoring whitespace so max len of column with value ' t ' is showing as 1. XMLTABLE when extracting values from tag with whitespaces its ignoring them. It works properly if there is any character there e.g ' t '. * Update tests
1 parent 421888e commit 1fbf433

4 files changed

Lines changed: 122 additions & 4 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ create or replace package body ut_compound_data_helper is
235235
l_col_type := 'VARCHAR2(50)';
236236
elsif a_data_info.is_sql_diffable = 1 and type_no_length(a_data_info.column_type) then
237237
l_col_type := a_data_info.column_type;
238+
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('VARCHAR2','CHAR') then
239+
l_col_type := 'VARCHAR2('||greatest(a_data_info.column_len,4000)||')';
238240
else
239241
l_col_type := a_data_info.column_type
240242
||case when a_data_info.column_len is not null

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,22 @@ create or replace type body ut_data_value_refcursor as
4949
dbms_xmlgen.setNullHandling(l_ctx, dbms_xmlgen.empty_tag);
5050
dbms_xmlgen.setMaxRows(l_ctx, c_bulk_rows);
5151
loop
52-
l_xml := dbms_xmlgen.getxmltype(l_ctx);
52+
l_xml := dbms_xmlgen.getxmltype(l_ctx);
5353
exit when dbms_xmlgen.getNumRowsProcessed(l_ctx) = 0;
54+
--Bug in oracle 12.2+ where XML binary storage trimming insignificant whitespaces.
55+
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
56+
l_xml := xmltype( replace(l_xml.getClobVal(),'<ROWSET','<ROWSET xml:space=''preserve'''));
57+
$else
58+
null;
59+
$end
5460
l_elements_count := l_elements_count + dbms_xmlgen.getNumRowsProcessed(l_ctx);
5561
execute immediate
5662
'insert into ' || l_ut_owner || '.ut_compound_data_tmp(data_id, item_no, item_data) ' ||
5763
'values (:self_guid, :self_row_count, :l_xml)'
58-
using in self.data_id, l_set_id, l_xml;
64+
using in self.data_id, l_set_id, l_xml;
5965
l_set_id := l_set_id + c_bulk_rows;
6066
end loop;
67+
6168
ut_expectation_processor.reset_nls_params();
6269
dbms_xmlgen.closeContext(l_ctx);
6370
self.elements_count := l_elements_count;
@@ -317,8 +324,7 @@ create or replace type body ut_data_value_refcursor as
317324
l_cursor := ut_compound_data_helper.get_compare_cursor(a_diff_cursor_text,
318325
a_self.data_id, a_other.data_id);
319326
--fetch and save rows for display of diff
320-
fetch l_cursor bulk collect into l_diff_tab limit ut_utils.gc_diff_max_rows;
321-
327+
fetch l_cursor bulk collect into l_diff_tab limit ut_utils.gc_diff_max_rows;
322328
exception when others then
323329
if l_cursor%isopen then
324330
close l_cursor;

test/ut3_user/expectations/test_expectations_cursor.pkb

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,6 +2676,91 @@ Check the query and data for errors.';
26762676
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
26772677

26782678
end;
2679+
2680+
2681+
procedure insginificant_whitespace1 is
2682+
l_actual sys_refcursor;
2683+
l_expected sys_refcursor;
2684+
begin
2685+
open l_expected for
2686+
select column_value t1 from table(ut_varchar2_list(''));
2687+
2688+
open l_actual for
2689+
select column_value t1 from table(ut_varchar2_list(' '));
2690+
--Assert
2691+
ut3.ut.expect( l_actual ).to_equal( l_expected );
2692+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_be_greater_than(0);
2693+
end;
2694+
2695+
procedure insginificant_whitespace2 is
2696+
l_actual sys_refcursor;
2697+
l_expected sys_refcursor;
2698+
begin
2699+
open l_expected for
2700+
select ' t ' t1 from dual;
2701+
2702+
open l_actual for
2703+
select 't' t1 from dual;
2704+
--Assert
2705+
ut3.ut.expect( l_actual ).to_equal( l_expected );
2706+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_be_greater_than(0);
2707+
end;
2708+
2709+
procedure insginificant_whitespace3 is
2710+
l_actual sys_refcursor;
2711+
l_expected sys_refcursor;
2712+
begin
2713+
open l_expected for
2714+
select 't ' t1 from dual;
2715+
2716+
open l_actual for
2717+
select 't' t1 from dual;
2718+
--Assert
2719+
ut3.ut.expect( l_actual ).to_equal( l_expected );
2720+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_be_greater_than(0);
2721+
end;
2722+
2723+
procedure insginificant_whitespace4 is
2724+
l_actual sys_refcursor;
2725+
l_expected sys_refcursor;
2726+
begin
2727+
open l_expected for
2728+
select ' t' t1 from dual;
2729+
2730+
open l_actual for
2731+
select 't' t1 from dual;
2732+
--Assert
2733+
ut3.ut.expect( l_actual ).to_equal( l_expected );
2734+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_be_greater_than(0);
2735+
end;
2736+
2737+
procedure insginificant_whitespace5 is
2738+
l_actual sys_refcursor;
2739+
l_expected sys_refcursor;
2740+
begin
2741+
open l_expected for
2742+
select ' ' t1 from dual;
2743+
2744+
open l_actual for
2745+
select '' t1 from dual;
2746+
--Assert
2747+
ut3.ut.expect( l_actual ).to_equal( l_expected );
2748+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_be_greater_than(0);
2749+
end;
26792750

2751+
procedure nulltowhitespace is
2752+
l_actual sys_refcursor;
2753+
l_expected sys_refcursor;
2754+
begin
2755+
open l_expected for
2756+
select cast(null as varchar2(2)) t1 from dual;
2757+
2758+
open l_actual for
2759+
select ' ' t1 from dual;
2760+
--Assert
2761+
ut3.ut.expect( l_actual ).to_equal( l_expected );
2762+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_be_greater_than(0);
2763+
end;
2764+
26802765
end;
26812766
/

test/ut3_user/expectations/test_expectations_cursor.pks

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,30 @@ create or replace package test_expectations_cursor is
418418
--%test(Check that column name accept non xml characters fix #902)
419419
procedure nonxmlchar_part_of_colname;
420420

421+
422+
/*Oracle Bug not readin properly in xmltable */
423+
--%test ( Compare insiginificant whitespaces scenario 1 )
424+
--%disabled
425+
procedure insginificant_whitespace1;
426+
427+
--%test ( Compare insiginificant whitespaces scenario 2 )
428+
procedure insginificant_whitespace2;
429+
430+
--%test ( Compare insiginificant whitespaces scenario 3 )
431+
procedure insginificant_whitespace3;
432+
433+
--%test ( Compare insiginificant whitespaces scenario 4 )
434+
procedure insginificant_whitespace4;
435+
436+
/*Oracle Bug not readin properly in xmltable */
437+
--%test ( Compare insiginificant whitespaces scenario 5 )
438+
--%disabled
439+
procedure insginificant_whitespace5;
440+
441+
/*Oracle Bug not readin properly in xmltable */
442+
--%test ( Compare null to whitespace )
443+
--%disabled
444+
procedure nulltowhitespace;
445+
421446
end;
422447
/

0 commit comments

Comments
 (0)