Skip to content

Commit 7ea55c8

Browse files
committed
fix dbms_output logging in case of exception
Bugfix for the following issue: dbms_output logging didn't work properly when the database call failed with exception: it was suppressed for the failing call and was displayed with the next (succesful) call. Fixed by moving dbms output logging to the "ensure" section.
1 parent 36b63dc commit 7ea55c8

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/plsql/procedure_call.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ def exec
2626

2727
@cursor.exec
2828

29-
dbms_output_log
30-
3129
if block_given?
3230
yield get_return_value
3331
nil
@@ -36,6 +34,7 @@ def exec
3634
end
3735
ensure
3836
@cursor.close if @cursor
37+
dbms_output_log
3938
end
4039

4140
private

spec/plsql/schema_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,13 @@ class TestModel < TestBaseModel
227227
before(:all) do
228228
plsql.connection = get_connection
229229
plsql.execute <<-SQL
230-
CREATE OR REPLACE PROCEDURE test_dbms_output(p_string VARCHAR2)
230+
CREATE OR REPLACE PROCEDURE test_dbms_output(p_string VARCHAR2, p_raise_error BOOLEAN := false)
231231
IS
232232
BEGIN
233233
DBMS_OUTPUT.PUT_LINE(p_string);
234+
IF p_raise_error THEN
235+
RAISE_APPLICATION_ERROR(-20000 - 12, 'Test Error');
236+
END IF;
234237
END;
235238
SQL
236239
plsql.execute <<-SQL
@@ -272,6 +275,11 @@ class TestModel < TestBaseModel
272275
expect(@buffer.string).to eq("DBMS_OUTPUT: test_dbms_output\n")
273276
end
274277

278+
it "should log output to specified stream in case of exception" do
279+
expect { plsql.test_dbms_output("test_dbms_output", true) }.to raise_error /Test Error/
280+
expect(@buffer.string).to eq("DBMS_OUTPUT: test_dbms_output\n")
281+
end
282+
275283
it "should not log output to stream when output is disabled" do
276284
plsql.test_dbms_output("enabled")
277285
plsql.dbms_output_stream = nil

0 commit comments

Comments
 (0)