-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ | |
| */ | ||
| public final class DBHelper { | ||
|
|
||
| public static final String UTPLSQL_VERSION = "3.0.3"; | ||
|
|
||
| private DBHelper() {} | ||
|
|
||
| /** | ||
|
|
@@ -52,4 +54,80 @@ public static String getCurrentSchema(Connection conn) throws SQLException { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Check the utPLSQL version compatibility. | ||
| * @param conn the connection | ||
| * @return true if the requested utPLSQL version is compatible with the one installed on database | ||
| * @throws SQLException any database error | ||
| */ | ||
| public static boolean versionCompatibilityCheck(Connection conn, String requested, String current) | ||
| throws SQLException { | ||
| CallableStatement callableStatement = null; | ||
| try { | ||
| callableStatement = conn.prepareCall("BEGIN ? := ut_runner.version_compatibility_check(?, ?); END;"); | ||
| callableStatement.registerOutParameter(1, Types.SMALLINT); | ||
| callableStatement.setString(2, requested); | ||
|
|
||
| if (current == null) | ||
| callableStatement.setNull(3, Types.VARCHAR); | ||
| else | ||
| callableStatement.setString(3, current); | ||
|
|
||
| callableStatement.executeUpdate(); | ||
| return callableStatement.getInt(1) == 1; | ||
| } catch (SQLException e) { | ||
| if (e.getErrorCode() == 6550) | ||
| return false; | ||
| else | ||
| throw e; | ||
| } finally { | ||
| if (callableStatement != null) | ||
| callableStatement.close(); | ||
| } | ||
| } | ||
|
|
||
| public static boolean versionCompatibilityCheck(Connection conn, String requested) | ||
| throws SQLException { | ||
| return versionCompatibilityCheck(conn, requested, null); | ||
| } | ||
|
|
||
| public static boolean versionCompatibilityCheck(Connection conn) | ||
| throws SQLException { | ||
| 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;")) { | ||
|
||
| 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."); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package org.utplsql.api; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.utplsql.api.rules.DatabaseRule; | ||
|
|
||
| import java.sql.SQLException; | ||
|
|
||
| public class DBHelperTest { | ||
|
|
||
| @Rule | ||
| public final DatabaseRule db = new DatabaseRule(); | ||
|
|
||
| @Test | ||
| public void compatibleVersion() { | ||
| try { | ||
| boolean isCompatible = DBHelper.versionCompatibilityCheck(db.newConnection(), "3.0.0", "3.0.0"); | ||
| Assert.assertTrue(isCompatible); | ||
| } catch (SQLException e) { | ||
| e.printStackTrace(); | ||
| Assert.fail(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void incompatibleVersion() { | ||
| try { | ||
| boolean isCompatible = DBHelper.versionCompatibilityCheck(db.newConnection(), "3.1.0", "3.0.0"); | ||
| Assert.assertFalse(isCompatible); | ||
| } catch (SQLException e) { | ||
| e.printStackTrace(); | ||
| Assert.fail(); | ||
| } | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be called: UTPLSQL_COMPATIBILITY_VERSION