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

Skip to content

Commit 3677fb1

Browse files
committed
Fixed error with NULL objects passed to ANYDATA for comparison.
1 parent 18cea37 commit 3677fb1

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

source/expectations/data_values/ut_data_value_anydata.tpb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ create or replace type body ut_data_value_anydata as
33
constructor function ut_data_value_anydata(self in out nocopy ut_data_value_anydata, a_value anydata) return self as result is
44
begin
55
self.datavalue := a_value;
6-
self.datatype := 'anydata';
6+
self.datatype := a_value.gettypename;
77
return;
88
end;
99

@@ -15,9 +15,9 @@ create or replace type body ut_data_value_anydata as
1515
begin
1616
if self.datavalue is null then
1717
l_is_null := true;
18-
elsif self.datavalue.gettypename like '%.%' then
19-
--XMLTYPE doesn't like the null beeing passed to ANYDATA so we need to check if anydata holds null Object/collection
2018
--check if typename is a schema based object
19+
elsif self.datavalue.gettypename like '%.%' then
20+
--XMLTYPE doesn't like the null beeing passed to ANYDATA so we need to check if anydata holds null Object/collection
2121
l_anydata_accessor :=
2222
case when self.datavalue.gettype(l_type) = dbms_types.typecode_object then 'getObject' else 'getCollection' end;
2323
execute immediate '
@@ -37,12 +37,14 @@ create or replace type body ut_data_value_anydata as
3737

3838
overriding member function to_string return varchar2 is
3939
l_result varchar2(32767);
40+
l_clob clob;
4041
begin
4142
if self.is_null() then
4243
l_result := ut_utils.to_string( to_char(null) );
4344
else
4445
ut_assert_processor.set_xml_nls_params();
45-
l_result := ut_utils.to_string( xmltype(self.datavalue).getclobval() );
46+
select xmlserialize(content xmltype(self.datavalue) indent) into l_clob from dual;
47+
l_result := ut_utils.to_string( l_clob );
4648
ut_assert_processor.reset_nls_params();
4749
end if;
4850
return l_result;

source/expectations/matchers/equal.tpb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,19 @@ create or replace type body equal as
7878
init(ut_data_value_varchar2(a_expected), a_nulls_are_equal);
7979
return;
8080
end;
81-
81+
8282
constructor function equal(self in out nocopy equal, a_expected yminterval_unconstrained, a_nulls_are_equal boolean := null) return self as result is
8383
begin
8484
init(ut_data_value_yminterval(a_expected), a_nulls_are_equal);
85-
return;
85+
return;
8686
end;
87-
87+
8888
constructor function equal(self in out nocopy equal, a_expected dsinterval_unconstrained, a_nulls_are_equal boolean := null) return self as result is
8989
begin
9090
init(ut_data_value_dsinterval(a_expected), a_nulls_are_equal);
91-
return;
91+
return;
9292
end;
93-
93+
9494
overriding member function run_matcher(self in out nocopy equal, a_actual ut_data_value) return boolean is
9595
l_result boolean;
9696
begin
@@ -100,7 +100,15 @@ create or replace type body equal as
100100
l_actual ut_data_value_anydata := treat(a_actual as ut_data_value_anydata);
101101
begin
102102
ut_assert_processor.set_xml_nls_params();
103-
l_result := equal_with_nulls((xmltype(l_expected.datavalue).getclobval() = xmltype(l_actual.datavalue).getclobval()), a_actual);
103+
--XMLTYPE doesn't like the null being passed from anydata or object types, so we need to check if anydata holds null Object/collection
104+
--This is why equal_with_nulls cannot be used here
105+
if ut_utils.int_to_boolean( nulls_are_equal_flag ) and self.expected.is_null() and a_actual.is_null() then
106+
l_result := true;
107+
elsif self.expected.is_null() or a_actual.is_null() then
108+
l_result := false;
109+
else
110+
l_result := xmltype(l_expected.datavalue).getclobval() = xmltype(l_actual.datavalue).getclobval();
111+
end if;
104112
ut_assert_processor.reset_nls_params();
105113
end;
106114
elsif self.expected is of (ut_data_value_blob) and a_actual is of (ut_data_value_blob) then

0 commit comments

Comments
 (0)