You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request #291 from jgebal/feature/refactor_data_values
Refactored ut_data_value, ut_expectation and ut_matchers.
Merging this PR as there are no objections. It opens doors for further improvements with the restructuring that was done.
Parameters `a_mask` and `a_escape_char` represent a valid parameters of the [Oracle like function](https://docs.oracle.com/database/121/SQLRF/conditions007.htm#SQLRF52142)
@@ -118,15 +132,19 @@ Unary matcher that validates if the actual value is not null.
The `a_nulls_are_equal` parameter decides on the behavior of `null=null` comparison (**this comparison by default is true!**)
159
179
180
+
### Comparing cursors
181
+
182
+
The `equal` matcher accepts additional parameter `a_exclude varchar2` or `a_exclude ut_varchar2_list`, when used to compare `cursor` data.
183
+
Those parameters allow passing a list of column names to exclude from data comparison. The list can be a comma separated `varchar2` list or a `ut_varchar2_list` collection.
184
+
The column names accepted by parameter are **case sensitive** and cannot be quoted.
185
+
If `a_exclude` parameter is not specified, all columns are included.
186
+
If a column to be excluded does not exist, the column cannot be excluded and it's name is simply ignored.
187
+
It is useful when testing cursors containing data that is beyond our control (like default or trigger/procedure generated sysdatevalueson columns).
188
+
189
+
```sql
190
+
procedure test_cursors_skip_columns is
191
+
x sys_refcursor;
192
+
y sys_refcursor;
193
+
begin
194
+
open x for select 'text' ignore_me, d.* from user_tables d;
195
+
open y for select sysdate "ADate", d.* from user_tables d;
utPLSQL uses XMLType internally to represent rows of the cursor data. This is by far most flexible and allows comparison of cursors containing LONG, CLOB, BLOB, user defined types and even nested cursors.
204
+
Due to the way Oracle handles DATE data type when converting from cursor data to XML, utPLSQL has no control over the DATE formatting.
205
+
The NLS_DATE_FORMAT setting from the moment the cursor was opened decides ont the formatting of dates used for cursor data comparison.
206
+
By default, Oracle NLS_DATE_FORMAT is timeless, so data of DATE datatype, will be compared ignoring the time part of it.
207
+
208
+
You should use procedures `ut.set_nls`, `ut.reset_nls` around cursors that you want to compare in your tests.
209
+
This way, the DATE data in cursors will get properly formatted for comparison using date-time format.
210
+
211
+
The example below makes use of `ut.set_nls`, `ut.reset_nls`, so that datein`l_expected`and`l_actual` is compared using date-time formatting.
212
+
```sql
213
+
create table events (
214
+
description varchar2(4000),
215
+
event_date date
216
+
);
217
+
218
+
create or replace function get_events(a_date_from date, a_date_to date) return sys_refcursor is
219
+
l_result sys_refcursor;
220
+
begin
221
+
open l_result for
222
+
select description, event_date
223
+
from events
224
+
where event_date between a_date_from and a_date_to;
0 commit comments