Skip to content

Improve hasOutput check to a real PL/SQL type-check #69

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 10 commits into from
Jan 16, 2019
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ env:
- UTPLSQL_VERSION="v3.0.4"
- UTPLSQL_VERSION="v3.1.1"
- UTPLSQL_VERSION="v3.1.2"
- UTPLSQL_VERSION="v3.1.3"
- UTPLSQL_VERSION="develop"
UTPLSQL_FILE="utPLSQL"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.utplsql.api.outputBuffer;

import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleTypes;
import org.utplsql.api.Version;
import org.utplsql.api.exception.InvalidVersionException;
import org.utplsql.api.reporter.Reporter;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class OutputBufferProvider {
Expand Down Expand Up @@ -42,26 +42,28 @@ public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Re

private static boolean hasOutput( Reporter reporter, OracleConnection oraConn ) throws SQLException {

String sql = "select is_output_reporter " +
" from table(ut_runner.get_reporters_list)" +
" where ? = substr(reporter_object_name, length(reporter_object_name)-?+1)";
try ( PreparedStatement stmt = oraConn.prepareStatement(sql)) {
String sql =
"declare " +
" l_result int;" +
"begin " +
" begin " +
" execute immediate '" +
" begin " +
" :x := case ' || dbms_assert.simple_sql_name( ? ) || '() is of (ut_output_reporter_base) when true then 1 else 0 end;" +
" end;'" +
" using out l_result;" +
" end;" +
" ? := l_result;" +
"end;";

try ( CallableStatement stmt = oraConn.prepareCall(sql)) {
stmt.setQueryTimeout(3);
stmt.setString(1, reporter.getTypeName());
stmt.setInt(2, reporter.getTypeName().length());

try ( ResultSet rs = stmt.executeQuery() ) {
if ( rs.next() ) {
String isReporterResult = rs.getString(1);
stmt.registerOutParameter(2, OracleTypes.INTEGER);

if ( isReporterResult == null )
throw new IllegalArgumentException("The given type " + reporter.getTypeName() + " is not a valid Reporter!");
else
return isReporterResult.equalsIgnoreCase("Y");
}
else
throw new SQLException("Could not check Reporter validity");
}
stmt.execute();
int result = stmt.getInt(2);
return result == 1;
}
}

Expand Down