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

Skip to content

Commit 4642f3c

Browse files
committed
Fixed send_clob, added additional unit tests.
1 parent 6834866 commit 4642f3c

4 files changed

Lines changed: 53 additions & 3 deletions

File tree

source/core/types/ut_output_dbms_output.tpb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ create or replace type body ut_output_dbms_output as
1818
end;
1919

2020
overriding member procedure send_clob(self in out nocopy ut_output_dbms_output, a_text clob) is
21+
v_buffer ut_varchar2_list;
2122
begin
22-
for i in (select column_value as text from table(ut_utils.clob_to_table(a_text)) ) loop
23-
dbms_output.put_line(i.text);
23+
v_buffer := ut_utils.clob_to_table(a_text);
24+
for i in 1 .. v_buffer.count loop
25+
dbms_output.put_line(v_buffer(i));
2426
end loop;
2527
end;
2628

tests/RunAll.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ create table ut$test_table (val varchar2(1));
170170
@@lib/RunTest.sql ut_output_dbms_output/ut_output_dbms_output.get_clob_lines.ReturnsSentLines.sql
171171
@@lib/RunTest.sql ut_output_dbms_output/ut_output_dbms_output.get_lines.RetunrsNoRowsWhenNoDataInBuffer.sql
172172
@@lib/RunTest.sql ut_output_dbms_output/ut_output_dbms_output.get_lines.ReturnsSentLines.sql
173+
@@lib/RunTest.sql ut_output_dbms_output/ut_output_dbms_output.send_clob.SendsAClobIntoPipe.sql
173174
--Global cleanup
174175
drop package ut_example_tests;
175176
drop procedure check_annotation_parsing;

tests/ut_output_dbms_output/ut_output_dbms_output.get_clob_lines.ReturnsSentLines.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare
44
l_output ut_output_dbms_output := ut_output_dbms_output();
55
l_expected clob;
66
begin
7-
l_expected := lpad('a',32000,'a');
7+
l_expected := lpad('a',32767,'a');
88
--Act - open the pipe
99
l_output.send_clob(l_expected);
1010
l_output.send_clob(l_expected);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
PROMPT ut_output_dbms_output.send_clob Sends a clob Into Pipe in a separate session and recieves it back cut into 4000 char pieces
2+
3+
declare
4+
l_message_lenght integer := 98765;
5+
l_output ut_output_dbms_output := ut_output_dbms_output();
6+
l_text_lenght integer;
7+
l_chunk_lenght integer;
8+
begin
9+
--Arrange - send clob to dbms_output
10+
declare
11+
l_expected_length integer := l_message_lenght;
12+
l_max_varchar2_len integer := 32767;
13+
l_loops integer := floor(l_expected_length / l_max_varchar2_len);
14+
l_string varchar2(32767);
15+
l_output ut_output_dbms_output := ut_output_dbms_output();
16+
l_lob clob;
17+
begin
18+
dbms_lob.createtemporary(l_lob, true);
19+
for i in 1 .. l_loops loop
20+
l_string := lpad('a', l_max_varchar2_len, 'a');
21+
dbms_lob.writeappend( l_lob, length(l_string), l_string );
22+
end loop;
23+
if l_loops*l_max_varchar2_len < l_expected_length then
24+
l_string := lpad('a', mod(l_expected_length, l_max_varchar2_len), 'a');
25+
dbms_lob.writeappend( l_lob, length(l_string), l_string );
26+
end if;
27+
l_output.send_clob(l_lob);
28+
end;
29+
30+
31+
--Act - get clob as lines from dbms_output
32+
select sum(nvl(length(column_value),0)), max(length(column_value))
33+
into l_text_lenght, l_chunk_lenght
34+
from table( l_output.get_lines(NULL) );
35+
--Assert - check that the length of text recieved is same as lenght of text sent
36+
if l_text_lenght = l_message_lenght and l_chunk_lenght = 4000 then
37+
:test_result := ut_utils.tr_success;
38+
elsif not nvl(l_chunk_lenght,0) = 4000 then
39+
dbms_output.put_line('Expected chunk length of 4000 but got'||l_chunk_lenght);
40+
else
41+
dbms_output.put_line('Expected '||l_message_lenght||' characters, got '||l_text_lenght);
42+
end if;
43+
end;
44+
/
45+
46+
47+

0 commit comments

Comments
 (0)