Skip to content

Commit 0d8501b

Browse files
committed
Enable output_buffer before calling ut_runner.run
1 parent 5d725d5 commit 0d8501b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/main/java/org/utplsql/api/DBHelper.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,38 @@ public static boolean versionCompatibilityCheck(Connection conn)
9696
return versionCompatibilityCheck(conn, UTPLSQL_VERSION);
9797
}
9898

99+
/**
100+
* Enables the dbms_output buffer.
101+
* @param conn the connection
102+
* @param bufferLen the buffer length
103+
*/
104+
public static void enableDBMSOutput(Connection conn, int bufferLen) {
105+
try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.enable(?); END;")) {
106+
call.setInt(1, bufferLen);
107+
call.execute();
108+
} catch (SQLException e) {
109+
System.out.println("Failed to enable dbms_output.");
110+
}
111+
}
112+
113+
/**
114+
* Enables the dbms_output buffer.
115+
* @param conn the connection
116+
*/
117+
public static void enableDBMSOutput(Connection conn) {
118+
enableDBMSOutput(conn, Integer.MAX_VALUE);
119+
}
120+
121+
/**
122+
* Disables the dbms_output buffer.
123+
* @param conn the connection
124+
*/
125+
public static void disableDBMSOutput(Connection conn) {
126+
try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.disable(); END;")) {
127+
call.execute();
128+
} catch (SQLException e) {
129+
System.out.println("Failed to disable dbms_output.");
130+
}
131+
}
132+
99133
}

src/main/java/org/utplsql/api/TestRunner.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
103103
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
104104
CallableStatement callableStatement = null;
105105
try {
106+
DBHelper.enableDBMSOutput(conn);
107+
106108
callableStatement = conn.prepareCall(
107109
"BEGIN " +
108110
"ut_runner.run(" +
@@ -172,8 +174,11 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
172174
throw e;
173175
}
174176
} finally {
175-
if (callableStatement != null)
177+
if (callableStatement != null) {
176178
callableStatement.close();
179+
}
180+
181+
DBHelper.disableDBMSOutput(conn);
177182
}
178183
}
179184

0 commit comments

Comments
 (0)