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

Skip to content

Commit cad7bad

Browse files
committed
Added description fo timestamp bind-variable comparison in cursor.
Resolves #771
1 parent 5bb077d commit cad7bad

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

docs/userguide/expectations.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ utPLSQL is capable of comparing compound data-types including:
445445
- Cursors, nested table and varray types are compared as **ordered lists of elements**. If order of elements differ, expectation will fail.
446446
- Comparison of compound data is data-type aware. So a column `ID NUMBER` in a cursor is not the same as `ID VARCHAR2(100)`, even if they both hold the same numeric values.
447447
- Comparison of cursor columns containing `DATE` will only compare date part **and ignore time** by default. See [Comparing cursor data containing DATE fields](#comparing-cursor-data-containing-date-fields) to check how to enable date-time comparison in cursors.
448+
- Comparison of cursor returning `TIMESTAMP` **columns** against cursor returning `TIMESTAMP` **bind variables** requires variables to be casted to proper precision. This is an Oracle SQL - PLSQL compatibility issue and usage of CAST is the only known workaround for now.
449+
See [Comparing cursor data containing TIMESTAMP bind variables](#comparing-cursor-data-containing-timestamp-bind-variables) for examples.
448450
- To compare nested table/varray type you need to convert it to `anydata` by using `anydata.convertCollection()`
449451
- To compare object type you need to convert it to `anydata` by using `anydata.convertObject()`
450452
- It is possible to compare PL/SQL records, collections, varrays and associative arrays. To compare this types of data, use cursor comparison feature of utPLSQL and TABLE operator in SQL query
@@ -749,6 +751,100 @@ In the above example:
749751
- The test `get_events_for_date_range` will succeed, as the `l_expected_bad_date` cursor contains different date-time then the cursor returned by `get_events` function call.
750752
- The test `bad_test` will fail, as the column `event_date` will get compared as DATE without TIME.
751753

754+
### Comparing cursor data containing TIMESTAMP bind variables
755+
756+
To properly compare `timestamp` column data returned by cursor against bind variable data from another cursor, a conversion needs to be done.
757+
758+
This applies to `timestamp`,`timestamp with timezone`, `timestamp with local timezone` data types.
759+
760+
Example below illustrates usage of `cast` operator to assure appropriate precision is applied on timestamp bind-variables in cursor result-set
761+
```sql
762+
drop table timestamps;
763+
create table timestamps (
764+
ts3 timestamp (3),
765+
ts6 timestamp (6),
766+
ts9 timestamp (9)
767+
);
768+
769+
create or replace package timestamps_api is
770+
procedure load (
771+
i_timestamp3 timestamps.ts3%type,
772+
i_timestamp6 timestamps.ts6%type,
773+
i_timestamp9 timestamps.ts9%type
774+
);
775+
end;
776+
/
777+
778+
create or replace package body timestamps_api is
779+
procedure load (
780+
i_timestamp3 timestamps.ts3%type,
781+
i_timestamp6 timestamps.ts6%type,
782+
i_timestamp9 timestamps.ts9%type
783+
)
784+
is
785+
begin
786+
insert into timestamps (ts3, ts6, ts9)
787+
values (i_timestamp3, i_timestamp6, i_timestamp9);
788+
end;
789+
end;
790+
/
791+
792+
793+
create or replace package test_timestamps_api is
794+
-- %suite
795+
796+
-- %test(Loads data into timestamps table)
797+
procedure test_load;
798+
end;
799+
/
800+
801+
create or replace package body test_timestamps_api is
802+
procedure test_load is
803+
l_time timestamp(9);
804+
l_expected sys_refcursor;
805+
l_actual sys_refcursor;
806+
begin
807+
--Arrange
808+
l_time := systimestamp;
809+
810+
open l_expected for
811+
select
812+
cast(l_time as timestamp(3)) as ts3,
813+
cast(l_time as timestamp(6)) as ts6,
814+
cast(l_time as timestamp(9)) as ts9
815+
from dual;
816+
817+
--Act
818+
timestamps_api.load (
819+
l_time, l_time, l_time
820+
);
821+
822+
--Assert
823+
open l_actual for
824+
select ts3, ts6, ts9
825+
from timestamps;
826+
827+
ut.expect (l_actual).to_equal (l_expected);
828+
829+
end;
830+
end;
831+
/
832+
833+
begin
834+
ut.run ('test_timestamps_api');
835+
end;
836+
/
837+
```
838+
839+
The execution of the above runs successfully
840+
```
841+
test_timestamps_api
842+
Loads data into timestamps table [.046 sec]
843+
844+
Finished in .048181 seconds
845+
1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)
846+
```
847+
752848

753849
# Negating a matcher
754850
Expectations provide a very convenient way to perform a check on a negated matcher.

0 commit comments

Comments
 (0)