Skip to content

Enable dbms_output before calling ut_runner.run #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable output_buffer before calling ut_runner.run
  • Loading branch information
viniciusam committed Oct 22, 2017
commit 0d8501b6ac915e8a03956c457952cc0ead47a847
34 changes: 34 additions & 0 deletions src/main/java/org/utplsql/api/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,38 @@ public static boolean versionCompatibilityCheck(Connection conn)
return versionCompatibilityCheck(conn, UTPLSQL_VERSION);
}

/**
* Enables the dbms_output buffer.
* @param conn the connection
* @param bufferLen the buffer length
*/
public static void enableDBMSOutput(Connection conn, int bufferLen) {
try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.enable(?); END;")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use NULL as max value of the buffer.
As per Oracle doc, ENABLE(NULL) makes the buffer size unlimited.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I will remove the one with the size parameter, I think we don't need that anyways...

call.setInt(1, bufferLen);
call.execute();
} catch (SQLException e) {
System.out.println("Failed to enable dbms_output.");
}
}

/**
* Enables the dbms_output buffer.
* @param conn the connection
*/
public static void enableDBMSOutput(Connection conn) {
enableDBMSOutput(conn, Integer.MAX_VALUE);
}

/**
* Disables the dbms_output buffer.
* @param conn the connection
*/
public static void disableDBMSOutput(Connection conn) {
try (CallableStatement call = conn.prepareCall("BEGIN dbms_output.disable(); END;")) {
call.execute();
} catch (SQLException e) {
System.out.println("Failed to disable dbms_output.");
}
}

}
7 changes: 6 additions & 1 deletion src/main/java/org/utplsql/api/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
CallableStatement callableStatement = null;
try {
DBHelper.enableDBMSOutput(conn);

callableStatement = conn.prepareCall(
"BEGIN " +
"ut_runner.run(" +
Expand Down Expand Up @@ -172,8 +174,11 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
throw e;
}
} finally {
if (callableStatement != null)
if (callableStatement != null) {
callableStatement.close();
}

DBHelper.disableDBMSOutput(conn);
}
}

Expand Down