Skip to content

Commit a43e3ff

Browse files
authored
Merge pull request #348 from jgebal/bugfix/dbms_lob_append_multibyte
Bugfix/dbms lob append multibyte
2 parents cb4fa1b + bcb928e commit a43e3ff

File tree

8 files changed

+77
-38
lines changed

8 files changed

+77
-38
lines changed

source/core/types/ut_executable.tpb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,12 @@ create or replace type body ut_executable is
8484
loop
8585
dbms_output.get_line(line => l_line, status => l_status);
8686
exit when l_status = 1;
87-
88-
if l_line is not null then
89-
dbms_lob.writeappend(lob_loc => self.serveroutput,
90-
amount => length(l_line),
91-
buffer => l_line);
92-
end if;
93-
94-
dbms_lob.writeappend(lob_loc => self.serveroutput,
95-
amount => 1,
96-
buffer => chr(10));
87+
88+
if l_line is not null then
89+
ut_utils.append_to_clob(self.serveroutput, l_line);
90+
end if;
91+
92+
dbms_lob.writeappend(self.serveroutput,1,chr(10));
9793
end loop;
9894
end save_dbms_output;
9995
begin

source/core/ut_utils.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ create or replace package body ut_utils is
324324
if a_src_clob is null then
325325
dbms_lob.createtemporary(a_src_clob, true);
326326
end if;
327-
dbms_lob.writeappend(a_src_clob, length(a_new_data), a_new_data);
327+
dbms_lob.writeappend(a_src_clob, dbms_lob.getlength(a_new_data), a_new_data);
328328
end if;
329329
end;
330330

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ create or replace type body ut_data_value_refcursor as
129129
for i in 1 .. l_results.count loop
130130
dbms_lob.append(l_result,l_results(i));
131131
if i < l_results.count then
132-
dbms_lob.writeappend(l_result,1,chr(10));
132+
ut_utils.append_to_clob(l_result,chr(10));
133133
end if;
134134
end loop;
135135

source/reporters/ut_coverage_report_html_helper.pkb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ create or replace package body ut_coverage_report_html_helper is
113113
'<span class="green"><b>'||a_coverage_unit.covered_lines||'</b> lines covered</span> and ' ||
114114
'<span class="red"><b>'||a_coverage_unit.uncovered_lines||'</b> lines missed</span></div></div>' ||
115115
'<pre><ol>';
116-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
116+
ut_utils.append_to_clob(l_result, l_file_part);
117117

118118
for line_no in 1 .. a_source_code.count loop
119119
if not a_coverage_unit.lines.exists(line_no) then
@@ -130,11 +130,11 @@ create or replace package body ut_coverage_report_html_helper is
130130
l_file_part := l_file_part || '
131131
<code class="sql">' || (dbms_xmlgen.convert(a_source_code(line_no))) || '</code></li>';
132132
end if;
133-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
133+
ut_utils.append_to_clob(l_result, l_file_part);
134134
end loop;
135135

136136
l_file_part := '</ol></pre></div>';
137-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
137+
ut_utils.append_to_clob(l_result, l_file_part);
138138
return l_result;
139139
end;
140140
begin
@@ -176,7 +176,7 @@ create or replace package body ut_coverage_report_html_helper is
176176
'<tr>' ||
177177
'<th>File</th><th>% covered</th><th>Lines</th><th>Relevant Lines</th><th>Lines covered</th><th>Lines missed</th><th>Avg. Hits / Line</th>' ||
178178
'</tr></thead><tbody>';
179-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
179+
ut_utils.append_to_clob(l_result, l_file_part);
180180
l_unit := a_coverage.objects.first;
181181
loop
182182
exit when l_unit is null;
@@ -193,11 +193,11 @@ create or replace package body ut_coverage_report_html_helper is
193193
'<td>'||l_unit_coverage.uncovered_lines||'</td>' ||
194194
'<td>'||executions_per_line(l_unit_coverage.executions, l_unit_coverage.uncovered_lines + l_unit_coverage.covered_lines)||'</td>' ||
195195
'</tr>';
196-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
196+
ut_utils.append_to_clob(l_result, l_file_part);
197197
l_unit := a_coverage.objects.next(l_unit);
198198
end loop;
199199
l_file_part := '</tbody></table></div>';
200-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
200+
ut_utils.append_to_clob(l_result, l_file_part);
201201
return l_result;
202202
end;
203203

@@ -235,7 +235,7 @@ create or replace package body ut_coverage_report_html_helper is
235235
'<div class="timestamp">Generated <abbr class="timeago" title="'||l_time_str||'">'||l_time_str||'</abbr></div>' ||
236236
'<ul class="group_tabs"></ul>' ||
237237
'<div id="content">';
238-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
238+
ut_utils.append_to_clob(l_result, l_file_part);
239239

240240
dbms_lob.append(l_result, file_list('All files', a_coverage_data));
241241

@@ -245,7 +245,7 @@ create or replace package body ut_coverage_report_html_helper is
245245
'Generated by <a href="http://github.com/utPLSQL/utPLSQL">'||ut_utils.gc_version||'</a><br/>' ||
246246
'Based on <a href="http://github.com/colszowka/simplecov-html">simplecov-html</a> v0.10.0 '||l_using||'' ||
247247
'</div><div class="source_files">';
248-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
248+
ut_utils.append_to_clob(l_result, l_file_part);
249249

250250
l_unit := a_coverage_data.objects.first;
251251
loop
@@ -257,7 +257,7 @@ create or replace package body ut_coverage_report_html_helper is
257257
l_file_part := '</div></div></body></html>
258258
';
259259

260-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
260+
ut_utils.append_to_clob(l_result, l_file_part);
261261
return l_result;
262262
end;
263263

source/reporters/ut_coverage_sonar_reporter.tpb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ create or replace type body ut_coverage_sonar_reporter is
3838
if l_line_no is null then
3939
for i in 1 .. a_unit_coverage.total_lines loop
4040
l_file_part := '<lineToCover lineNumber="'||i||'" covered="false"/>'||chr(10);
41-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
41+
ut_utils.append_to_clob(l_result, l_file_part);
4242
end loop;
4343
else
4444
while l_line_no is not null loop
@@ -49,7 +49,7 @@ create or replace type body ut_coverage_sonar_reporter is
4949
else
5050
'<lineToCover lineNumber="'||l_line_no||'" covered="true"/>'||chr(10)
5151
end;
52-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
52+
ut_utils.append_to_clob(l_result, l_file_part);
5353
l_line_no := a_unit_coverage.lines.next(l_line_no);
5454
end loop;
5555
end if;
@@ -67,19 +67,19 @@ create or replace type body ut_coverage_sonar_reporter is
6767
begin
6868
dbms_lob.createtemporary(l_result,true);
6969

70-
dbms_lob.writeappend(l_result, length(c_coverage_header), c_coverage_header);
70+
ut_utils.append_to_clob(l_result, c_coverage_header);
7171
l_unit := a_coverage_data.objects.first;
7272
while l_unit is not null loop
7373
l_file_part := '<file path="'||l_unit||'">'||chr(10);
74-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
74+
ut_utils.append_to_clob(l_result, l_file_part);
7575

7676
dbms_lob.append(l_result,get_lines_xml(a_coverage_data.objects(l_unit)));
7777

78-
dbms_lob.writeappend(l_result, length(c_file_footer), c_file_footer);
78+
ut_utils.append_to_clob(l_result, c_file_footer);
7979

8080
l_unit := a_coverage_data.objects.next(l_unit);
8181
end loop;
82-
dbms_lob.writeappend(l_result, length(c_coverage_footer), c_coverage_footer);
82+
ut_utils.append_to_clob(l_result, c_coverage_footer);
8383
return l_result;
8484
end;
8585
begin

source/reporters/ut_coveralls_reporter.tpb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ create or replace type body ut_coveralls_reporter is
3636
c_null constant varchar2(4) := 'null';
3737
begin
3838
dbms_lob.createtemporary(l_result, true);
39-
dbms_lob.writeappend(l_result, length(c_coverage_header), c_coverage_header);
39+
ut_utils.append_to_clob(l_result, c_coverage_header);
4040

4141
l_last_line_no := a_unit_coverage.lines.last;
4242
if l_last_line_no is null then
4343
l_last_line_no := a_unit_coverage.total_lines - 1;
4444
for i in 1 .. l_last_line_no loop
45-
dbms_lob.writeappend(l_result, 2, '0,');
45+
ut_utils.append_to_clob(l_result, '0,');
4646
end loop;
47-
dbms_lob.writeappend(l_result, 1, '0');
47+
ut_utils.append_to_clob(l_result, '0');
4848
else
4949
for line_no in 1 .. l_last_line_no loop
5050
if a_unit_coverage.lines.exists(line_no) then
@@ -55,10 +55,10 @@ create or replace type body ut_coveralls_reporter is
5555
if line_no < l_last_line_no then
5656
l_file_part := l_file_part ||',';
5757
end if;
58-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
58+
ut_utils.append_to_clob(l_result, l_file_part);
5959
end loop;
6060
end if;
61-
dbms_lob.writeappend(l_result, 1, ']');
61+
ut_utils.append_to_clob(l_result, ']');
6262
return l_result;
6363
end;
6464

@@ -73,22 +73,22 @@ create or replace type body ut_coveralls_reporter is
7373
begin
7474
dbms_lob.createtemporary(l_result,true);
7575

76-
dbms_lob.writeappend(l_result, length(c_coverage_header), c_coverage_header);
76+
ut_utils.append_to_clob(l_result, c_coverage_header);
7777
l_unit := a_coverage_data.objects.first;
7878
while l_unit is not null loop
7979
l_file_part := '{ "name": "'||l_unit||'",'||chr(10);
80-
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
80+
ut_utils.append_to_clob(l_result, l_file_part);
8181

8282
dbms_lob.append(l_result,get_lines_json(a_coverage_data.objects(l_unit)));
8383

84-
dbms_lob.writeappend(l_result, 1, '}');
84+
ut_utils.append_to_clob(l_result, '}');
8585

8686
l_unit := a_coverage_data.objects.next(l_unit);
8787
if l_unit is not null then
88-
dbms_lob.writeappend(l_result, 2, ','||chr(10));
88+
ut_utils.append_to_clob(l_result, ','||chr(10));
8989
end if;
9090
end loop;
91-
dbms_lob.writeappend(l_result, length(c_coverage_footer), c_coverage_footer);
91+
ut_utils.append_to_clob(l_result, c_coverage_footer);
9292
return l_result;
9393
end;
9494
begin

tests/RunAll.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ create table ut$test_table (val varchar2(1));
3434
exec ut_coverage.coverage_start_develop();
3535
@@lib/mystats/mystats start
3636

37-
3837
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.IgnoreWrappedPackageAndDoesNotRaiseException.sql
3938
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseAnnotationMixedWithWrongBeforeProcedure.sql
4039
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseAnnotationNotBeforeProcedure.sql
@@ -228,6 +227,7 @@ exec ut_coverage.coverage_start_develop();
228227

229228
@@ut_utils/ut_utils.clob_to_table.sql
230229
@@ut_utils/ut_utils.table_to_clob.sql
230+
@@lib/RunTest.sql ut_utils/ut_utils.append_to_clob.worksWithMultiByteChars.sql
231231
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.RunsWithInvalidValues.sql
232232
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.RunsWithNullValue.sql
233233
@@lib/RunTest.sql ut_utils/ut_utils.test_result_to_char.Success.sql
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
column nls_lang noprint new_value v_nls_lang
2+
3+
select value as nls_lang from nls_session_parameters where parameter = 'NLS_DATE_LANGUAGE';
4+
5+
--Arrange
6+
alter session set nls_date_language=ENGLISH;
7+
create or replace package tst_chars as
8+
-- 2) Status of the process = ‘PE’ with no linked data
9+
end;
10+
/
11+
12+
alter session set nls_date_language=RUSSIAN;
13+
14+
--Act
15+
declare
16+
l_lines sys.dbms_preprocessor.source_lines_t;
17+
l_result clob;
18+
begin
19+
l_lines := sys.dbms_preprocessor.get_post_processed_source(
20+
object_type => 'PACKAGE',
21+
schema_name => user,
22+
object_name => 'TST_CHARS'
23+
);
24+
:test_result := ut_utils.tr_success;
25+
for i in 1..l_lines.count loop
26+
l_result := null;
27+
ut_utils.append_to_clob(l_result, l_lines(i));
28+
29+
--Assert
30+
:test_result := coalesce(:test_result, ut_utils.tr_success);
31+
if dbms_lob.getlength(l_result) != dbms_lob.getlength(l_lines(i)) then
32+
:test_result := ut_utils.tr_failure;
33+
dbms_output.put_line('Expected: "'||l_lines(i)||'"');
34+
dbms_output.put_line('Actual: "'||l_result||'"');
35+
end if;
36+
end loop;
37+
end;
38+
/
39+
40+
alter session set nls_date_language=&&v_nls_lang;
41+
42+
undef v_nls_lang;
43+
drop package tst_chars;

0 commit comments

Comments
 (0)