|
1 | 1 | package org.utplsql.api.outputBuffer;
|
2 | 2 |
|
3 | 3 | import oracle.jdbc.OracleConnection;
|
| 4 | +import oracle.jdbc.OracleTypes; |
4 | 5 | import org.utplsql.api.Version;
|
5 | 6 | import org.utplsql.api.exception.InvalidVersionException;
|
6 | 7 | import org.utplsql.api.reporter.Reporter;
|
7 | 8 |
|
| 9 | +import java.sql.CallableStatement; |
8 | 10 | import java.sql.Connection;
|
9 |
| -import java.sql.PreparedStatement; |
10 |
| -import java.sql.ResultSet; |
11 | 11 | import java.sql.SQLException;
|
12 | 12 |
|
13 | 13 | public class OutputBufferProvider {
|
@@ -42,26 +42,28 @@ public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Re
|
42 | 42 |
|
43 | 43 | private static boolean hasOutput( Reporter reporter, OracleConnection oraConn ) throws SQLException {
|
44 | 44 |
|
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)) { |
49 | 60 | stmt.setQueryTimeout(3);
|
50 | 61 | 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); |
56 | 63 |
|
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; |
65 | 67 | }
|
66 | 68 | }
|
67 | 69 |
|
|
0 commit comments