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

Skip to content
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,34 @@ 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 reporterName = reporter.getTypeName();
if ( !reporterName.matches("^[a-zA-Z0-9_]+$"))
throw new IllegalArgumentException(String.format("Reporter-Name %s is not valid", reporterName));

String sql =
"declare " +
" l_result int;" +
"begin " +
" begin " +
" execute immediate '" +
" begin " +
" :x := case ' || ? || '() is of (ut_output_reporter_base) when true then 1 else 0 end;" +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would keep dbms_assert.valid_sql_name call.
It's a build in function that checks object name valid and that it is visible to user.
It is far safer than regex check.
You can still have both

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See the failed attempts. It's problematic on 11g as it seems.
I'll give it one last try.

" 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());
stmt.setString(1, reporterName);
stmt.registerOutParameter(2, OracleTypes.INTEGER);

try ( ResultSet rs = stmt.executeQuery() ) {
if ( rs.next() ) {
String isReporterResult = rs.getString(1);
stmt.execute();
int result = stmt.getInt(2);

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");
}
System.out.println("Output-check for " + reporterName + ": " + result);
return result == 1;
}
}

Expand Down