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

Skip to content

Commit 2bf6506

Browse files
committed
tmp
1 parent d8c75f2 commit 2bf6506

5 files changed

Lines changed: 107 additions & 1 deletion

File tree

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ create or replace type body ut_data_value_refcursor as
3939
self.self_type := $$plsql_unit;
4040
self.data_set_guid := sys_guid();
4141
self.data_type := 'refcursor';
42-
42+
self.columns_info := ut_refcursor_descriptor.get_columns_info(a_value);
4343
if a_value is not null then
4444
if a_value%isopen then
4545
self.row_count := 0;

source/expectations/data_values/ut_data_value_refcursor.tps

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ create or replace type ut_data_value_refcursor under ut_data_value(
3535
*/
3636
data_set_guid raw(16),
3737

38+
/**
39+
* Holds information about column names and column data-types
40+
*/
41+
columns_info ut_key_value_pairs,
42+
3843
constructor function ut_data_value_refcursor(self in out nocopy ut_data_value_refcursor, a_value sys_refcursor) return self as result,
3944
member procedure init(self in out nocopy ut_data_value_refcursor, a_value sys_refcursor),
4045
overriding member function is_null return boolean,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
create or replace package body ut_refcursor_descriptor is
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
type t_type_name_map is table of varchar2(100) index by binary_integer;
20+
g_type_name_map t_type_name_map;
21+
22+
function get_column_type(a_desc_rec dbms_sql.desc_rec3) return varchar2 is
23+
l_result varchar2(500) := 'unknown datatype';
24+
begin
25+
if g_type_name_map.exists(a_desc_rec.col_type) then
26+
l_result := g_type_name_map(a_desc_rec.col_type);
27+
elsif a_desc_rec.col_schema_name is not null and a_desc_rec.col_type_name is not null then
28+
l_result := a_desc_rec.col_schema_name||'.'||a_desc_rec.col_type_name;
29+
end if;
30+
return l_result;
31+
end;
32+
33+
function get_columns_info(l_columns_tab dbms_sql.desc_tab3, l_columns_count integer) return ut_key_value_pairs is
34+
l_result ut_key_value_pairs := ut_key_value_pairs();
35+
begin
36+
for i in 1 .. l_columns_count loop
37+
l_result.extend;
38+
l_result(l_result.last) := ut_key_value_pair(l_columns_tab(i).col_name, get_column_type(l_columns_tab(i)));
39+
end loop;
40+
return l_result;
41+
end;
42+
43+
function get_columns_info(a_cursor in out nocopy sys_refcursor) return ut_key_value_pairs is
44+
l_cursor_number integer;
45+
l_columns_count pls_integer;
46+
l_columns_desc dbms_sql.desc_tab3;
47+
begin
48+
if a_cursor is null or not a_cursor%isopen then
49+
return ut_key_value_pairs();
50+
end if;
51+
l_cursor_number := dbms_sql.to_cursor_number( a_cursor );
52+
dbms_sql.describe_columns3( l_cursor_number, l_columns_count, l_columns_desc );
53+
a_cursor := dbms_sql.to_refcursor( l_cursor_number );
54+
return get_columns_info( l_columns_desc, l_columns_count);
55+
end;
56+
57+
begin
58+
g_type_name_map( dbms_sql.binary_bouble_type ) := 'BINARY_DOUBLE';
59+
g_type_name_map( dbms_sql.bfile_type ) := 'BFILE';
60+
g_type_name_map( dbms_sql.binary_float_type ) := 'BINARY_FLOAT';
61+
g_type_name_map( dbms_sql.blob_type ) := 'BLOB';
62+
g_type_name_map( dbms_sql.long_raw_type ) := 'LONG RAW';
63+
g_type_name_map( dbms_sql.char_type ) := 'CHAR';
64+
g_type_name_map( dbms_sql.clob_type ) := 'CLOB';
65+
g_type_name_map( dbms_sql.long_type ) := 'LONG';
66+
g_type_name_map( dbms_sql.date_type ) := 'DATE';
67+
g_type_name_map( dbms_sql.interval_day_to_second_type ) := 'INTERVAL DAY TO SECOND';
68+
g_type_name_map( dbms_sql.interval_year_to_month_type ) := 'INTERVAL YEAR TO MONTH';
69+
g_type_name_map( dbms_sql.raw_type ) := 'RAW';
70+
g_type_name_map( dbms_sql.timestamp_type ) := 'TIMESTAMP';
71+
g_type_name_map( dbms_sql.timestamp_with_tz_type ) := 'TIMESTAMP WITH TIME ZONE';
72+
g_type_name_map( dbms_sql.timestamp_with_local_tz_type ) := 'TIMESTAMP WITH LOCAL TIME ZONE';
73+
g_type_name_map( dbms_sql.varchar2_type ) := 'VARCHAR2';
74+
g_type_name_map( dbms_sql.number_type ) := 'NUMBER';
75+
g_type_name_map( dbms_sql.rowid_type ) := 'ROWID';
76+
g_type_name_map( dbms_sql.urowid_type ) := 'UROWID';
77+
end;
78+
/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
create or replace package ut_refcursor_descriptor is
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
function get_columns_info(a_cursor in out nocopy sys_refcursor) return ut_key_value_pairs;
19+
20+
end;
21+
/

test/core/expectations/compound_data/test_expectations_cursor.pks

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,7 @@ create or replace package test_expectations_cursor is
166166
--%test(Adds a warning when using depreciated syntax to_( equal( a_expected sys_refcursor, a_exclude ut_varchar2_list )) )
167167
procedure deprec_equal_excl_list;
168168

169+
--%test(Reports column name differences if found)
170+
169171
end;
170172
/

0 commit comments

Comments
 (0)