Skip to content

Commit e67059f

Browse files
committed
Added binary_double, tests for timestamp with time zone.
1 parent 067ace5 commit e67059f

File tree

2 files changed

+111
-18
lines changed

2 files changed

+111
-18
lines changed

method4_ot.tpb

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ CREATE OR REPLACE TYPE BODY method4_ot AS
110110
WHEN r_sql.description(i).col_type = 100
111111
THEN DBMS_TYPES.TYPECODE_BFLOAT
112112
--<>--
113+
WHEN r_sql.description(i).col_type = 101
114+
THEN DBMS_TYPES.TYPECODE_BDOUBLE
115+
--<>--
113116
WHEN r_sql.description(i).col_type = 180
114117
THEN DBMS_TYPES.TYPECODE_TIMESTAMP
115118
--<>--
@@ -260,6 +263,12 @@ CREATE OR REPLACE TYPE BODY method4_ot AS
260263
method4.r_sql.cursor, i, CAST(NULL AS BINARY_FLOAT)
261264
);
262265
--<>--
266+
WHEN DBMS_TYPES.TYPECODE_BDOUBLE
267+
THEN
268+
DBMS_SQL.DEFINE_COLUMN(
269+
method4.r_sql.cursor, i, CAST(NULL AS BINARY_DOUBLE)
270+
);
271+
--<>--
263272
WHEN DBMS_TYPES.TYPECODE_DATE
264273
THEN
265274
DBMS_SQL.DEFINE_COLUMN(
@@ -337,20 +346,22 @@ CREATE OR REPLACE TYPE BODY method4_ot AS
337346
) RETURN NUMBER IS
338347

339348
TYPE rt_fetch_attributes IS RECORD
340-
( v2_column VARCHAR2(32767)
341-
, num_column NUMBER
342-
, date_column DATE
343-
, clob_column CLOB
344-
, raw_column RAW(32767)
345-
, raw_error NUMBER
346-
, raw_length INTEGER
347-
, ids_column INTERVAL DAY TO SECOND
348-
, iym_column INTERVAL YEAR TO MONTH
349-
, ts_column TIMESTAMP
350-
, tstz_column TIMESTAMP WITH TIME ZONE
351-
, tsltz_column TIMESTAMP WITH LOCAL TIME ZONE
352-
, cvl_offset INTEGER := 0
353-
, cvl_length INTEGER
349+
( v2_column VARCHAR2(32767)
350+
, num_column NUMBER
351+
, bfloat_column BINARY_FLOAT
352+
, bdouble_column BINARY_DOUBLE
353+
, date_column DATE
354+
, clob_column CLOB
355+
, raw_column RAW(32767)
356+
, raw_error NUMBER
357+
, raw_length INTEGER
358+
, ids_column INTERVAL DAY TO SECOND
359+
, iym_column INTERVAL YEAR TO MONTH
360+
, ts_column TIMESTAMP(9)
361+
, tstz_column TIMESTAMP(9) WITH TIME ZONE
362+
, tsltz_column TIMESTAMP(9) WITH LOCAL TIME ZONE
363+
, cvl_offset INTEGER := 0
364+
, cvl_length INTEGER
354365
);
355366
r_fetch rt_fetch_attributes;
356367
r_meta method4.rt_anytype_metadata;
@@ -417,6 +428,20 @@ CREATE OR REPLACE TYPE BODY method4_ot AS
417428
);
418429
rws.SetNumber( r_fetch.num_column );
419430
--<>--
431+
WHEN DBMS_TYPES.TYPECODE_BFLOAT
432+
THEN
433+
DBMS_SQL.COLUMN_VALUE(
434+
method4.r_sql.cursor, i, r_fetch.bfloat_column
435+
);
436+
rws.SetBFloat( r_fetch.bfloat_column );
437+
--<>--
438+
WHEN DBMS_TYPES.TYPECODE_BDOUBLE
439+
THEN
440+
DBMS_SQL.COLUMN_VALUE(
441+
method4.r_sql.cursor, i, r_fetch.bdouble_column
442+
);
443+
rws.SetBDouble( r_fetch.bdouble_column );
444+
--<>--
420445
WHEN DBMS_TYPES.TYPECODE_DATE
421446
THEN
422447
DBMS_SQL.COLUMN_VALUE(

tests/method4_test.plsql

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,81 @@ begin
240240
assert_equals('BINARY_FLOAT 2.', '2.2', trim(to_char(actual2, '9.9')));
241241
end;
242242

243+
--BINARY_DOUBLE.
244+
declare
245+
actual1 binary_double;
246+
actual2 binary_double;
247+
begin
248+
execute immediate
249+
q'<
250+
select *
251+
from table(method4.run('select 1.1d, cast(2.2 as binary_double) from dual'))
252+
>'
253+
into actual1, actual2;
254+
255+
assert_equals('BINARY_DOUBLE 1.', '1.1', trim(to_char(actual1, '9.9')));
256+
assert_equals('BINARY_DOUBLE 2.', '2.2', trim(to_char(actual2, '9.9')));
257+
end;
258+
259+
--TIMESTAMP [(fractional_seconds_precision)]
260+
--Note that SYSTIMESTAMP is not always the same as TIMESTAMP and worth testing.
261+
declare
262+
actual1 timestamp(9);
263+
actual2 timestamp(9);
264+
actual3 timestamp(9);
265+
actual4 timestamp(9);
266+
actual5 timestamp(9);
267+
begin
268+
execute immediate
269+
q'<
270+
select *
271+
from table(method4.run('
272+
select
273+
timestamp ''2000-01-01 12:34:56'',
274+
to_timestamp(''2000-01-02 12:34:56'', ''YYYY-MM-DD HH24:MI:SS''),
275+
to_timestamp(''2000-01-01 12:00:00.123456789'', ''YYYY-MM-DD HH24:MI:SS.FF9''),
276+
cast(date ''2000-01-01'' as timestamp(3)),
277+
systimestamp
278+
from dual'))
279+
>'
280+
into actual1, actual2, actual3, actual4, actual5;
281+
282+
assert_equals('Timestamp 1.', '2000-01-01 12:34:56', to_char(actual1, 'YYYY-MM-DD HH24:MI:SS'));
283+
assert_equals('Timestamp 2.', '2000-01-02 12:34:56', to_char(actual2, 'YYYY-MM-DD HH24:MI:SS'));
284+
assert_equals('Timestamp 3.', '2000-01-01 12:00:00.123456789', to_char(actual3, 'YYYY-MM-DD HH24:MI:SS.FF9'));
285+
assert_equals('Timestamp 4.', '2000-01-01', to_char(actual1, 'YYYY-MM-DD'));
286+
assert_equals('Timestamp 5.', to_char(systimestamp, 'YYYY-MM-DD HH24'), to_char(actual5, 'YYYY-MM-DD HH24'));
287+
end;
288+
289+
--TIMESTAMP [(fractional_seconds_precision)] WITH TIME ZONE
290+
declare
291+
actual1 timestamp(9) with time zone;
292+
actual2 timestamp(9) with time zone;
293+
actual3 timestamp(9) with time zone;
294+
actual4 timestamp(9) with time zone;
295+
begin
296+
execute immediate
297+
q'<
298+
select *
299+
from table(method4.run('
300+
select
301+
timestamp ''2000-01-01 12:34:56 +01:00'',
302+
timestamp ''2000-01-02 12:34:56 US/Eastern'',
303+
cast(date ''2000-01-04'' as timestamp(9) with time zone),
304+
cast(null as timestamp(9) with time zone)
305+
from dual'))
306+
>'
307+
into actual1, actual2, actual3, actual4;
308+
309+
assert_equals('Timestamp with time zone 1.', '2000-01-01 12:34:56 +01:00', to_char(actual1, 'YYYY-MM-DD HH24:MI:SS TZH:TZM'));
310+
assert_equals('Timestamp with time zone 2.', '2000-01-02 12:34:56 US/EASTERN', to_char(actual2, 'YYYY-MM-DD HH24:MI:SS TZR'));
311+
assert_equals('Timestamp with time zone 3.', '2000-01-04 00:00:00', to_char(actual3, 'YYYY-MM-DD HH24:MI:SS'));
312+
assert_equals('Timestamp with time zone 4.', '', actual4);
313+
end;
314+
243315

244316
/*
245-
BINARY_DOUBLE
246-
TIMESTAMP [(fractional_seconds_precision)]
247-
TIMESTAMP [(fractional_seconds_precision)] WITH TIME ZONE
248317
TIMESTAMP [(fractional_seconds_precision)] WITH LOCAL TIME ZONE
249-
SYSTIMESTAMP (in case it's different than a regular timestamp)
250318
INTERVAL YEAR [(year_precision)] TO MONTH
251319
INTERVAL DAY [(day_precision)] TO SECOND [(fractional_seconds_precision)]
252320
RAW(size)

0 commit comments

Comments
 (0)