Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c72bef0

Browse files
authored
Merge pull request #69 from utPLSQL/bugfix/reporter_has_output_check
Improve hasOutput check to a real PL/SQL type-check
2 parents 942f510 + 55c4d83 commit c72bef0

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ env:
2929
- UTPLSQL_VERSION="v3.0.4"
3030
- UTPLSQL_VERSION="v3.1.1"
3131
- UTPLSQL_VERSION="v3.1.2"
32+
- UTPLSQL_VERSION="v3.1.3"
3233
- UTPLSQL_VERSION="develop"
3334
UTPLSQL_FILE="utPLSQL"
3435

src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.utplsql.api.outputBuffer;
22

33
import oracle.jdbc.OracleConnection;
4+
import oracle.jdbc.OracleTypes;
45
import org.utplsql.api.Version;
56
import org.utplsql.api.exception.InvalidVersionException;
67
import org.utplsql.api.reporter.Reporter;
78

9+
import java.sql.CallableStatement;
810
import java.sql.Connection;
9-
import java.sql.PreparedStatement;
10-
import java.sql.ResultSet;
1111
import java.sql.SQLException;
1212

1313
public class OutputBufferProvider {
@@ -42,26 +42,28 @@ public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Re
4242

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

45-
String sql = "select is_output_reporter " +
46-
" from table(ut_runner.get_reporters_list)" +
47-
" where ? = substr(reporter_object_name, length(reporter_object_name)-?+1)";
48-
try ( PreparedStatement stmt = oraConn.prepareStatement(sql)) {
45+
String sql =
46+
"declare " +
47+
" l_result int;" +
48+
"begin " +
49+
" begin " +
50+
" execute immediate '" +
51+
" begin " +
52+
" :x := case ' || dbms_assert.simple_sql_name( ? ) || '() is of (ut_output_reporter_base) when true then 1 else 0 end;" +
53+
" end;'" +
54+
" using out l_result;" +
55+
" end;" +
56+
" ? := l_result;" +
57+
"end;";
58+
59+
try ( CallableStatement stmt = oraConn.prepareCall(sql)) {
4960
stmt.setQueryTimeout(3);
5061
stmt.setString(1, reporter.getTypeName());
51-
stmt.setInt(2, reporter.getTypeName().length());
52-
53-
try ( ResultSet rs = stmt.executeQuery() ) {
54-
if ( rs.next() ) {
55-
String isReporterResult = rs.getString(1);
62+
stmt.registerOutParameter(2, OracleTypes.INTEGER);
5663

57-
if ( isReporterResult == null )
58-
throw new IllegalArgumentException("The given type " + reporter.getTypeName() + " is not a valid Reporter!");
59-
else
60-
return isReporterResult.equalsIgnoreCase("Y");
61-
}
62-
else
63-
throw new SQLException("Could not check Reporter validity");
64-
}
64+
stmt.execute();
65+
int result = stmt.getInt(2);
66+
return result == 1;
6567
}
6668
}
6769

0 commit comments

Comments
 (0)