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

Skip to content

Commit 8c6602c

Browse files
author
Jacek Gębal
committed
Fixing issue with newer JDBC driver compatibility
Oracle JDBC 23.x no longer supports { ? = call ?.method() } escape syntax for object method calls — it emits ":2.method()" which PL/SQL rejects on a bind variable.
1 parent 2d9128c commit 8c6602c

2 files changed

Lines changed: 12 additions & 23 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.utplsql.api.outputBuffer;
22

33
import oracle.jdbc.OracleCallableStatement;
4-
import oracle.jdbc.OracleConnection;
54
import oracle.jdbc.OracleTypes;
65
import org.utplsql.api.reporter.Reporter;
76

@@ -28,10 +27,12 @@ class DefaultOutputBuffer extends AbstractOutputBuffer {
2827

2928
@Override
3029
protected CallableStatement getLinesCursorStatement(Connection conn) throws SQLException {
31-
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
32-
OracleCallableStatement cstmt = (OracleCallableStatement) oraConn.prepareCall("{? = call ?.get_lines_cursor() }");
30+
Reporter reporter = getReporter();
31+
String plsql = "DECLARE l_rep " + reporter.getTypeName() + "; "
32+
+ "BEGIN l_rep := :2; :1 := l_rep.get_lines_cursor(); END;";
33+
OracleCallableStatement cstmt = (OracleCallableStatement) conn.prepareCall(plsql);
3334
cstmt.registerOutParameter(1, OracleTypes.CURSOR);
34-
cstmt.setORAData(2, getReporter());
35+
cstmt.setORAData(2, reporter);
3536
return cstmt;
3637
}
3738
}

src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector310.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
package org.utplsql.api.reporter.inspect;
22

3-
import oracle.jdbc.OracleCallableStatement;
4-
import oracle.jdbc.OracleConnection;
5-
import oracle.jdbc.OracleType;
6-
import org.utplsql.api.compatibility.CompatibilityProxy;
7-
import org.utplsql.api.reporter.Reporter;
83
import org.utplsql.api.reporter.ReporterFactory;
94

10-
import java.sql.Connection;
11-
import java.sql.PreparedStatement;
12-
import java.sql.ResultSet;
13-
import java.sql.SQLException;
5+
import java.sql.*;
146
import java.util.*;
157

168
/**
@@ -48,7 +40,7 @@ private ReporterInfo getReporterInfo(String reporterNameWithOwner) throws SQLExc
4840
String reporterName = reporterNameWithOwner.substring(reporterNameWithOwner.indexOf(".") + 1).toUpperCase();
4941

5042
ReporterInfo.Type type = ReporterInfo.Type.SQL;
51-
String description = getDescription(reporterName);
43+
String description = getDescription(reporterNameWithOwner);
5244

5345
if (registeredReporterFactoryMethods.containsKey(reporterName)) {
5446
type = ReporterInfo.Type.SQL_WITH_JAVA;
@@ -58,16 +50,12 @@ private ReporterInfo getReporterInfo(String reporterNameWithOwner) throws SQLExc
5850
return new ReporterInfo(reporterName, type, description);
5951
}
6052

61-
private String getDescription(String reporterName) throws SQLException {
62-
CompatibilityProxy compatibilityProxy = new CompatibilityProxy(connection);
63-
Reporter reporter = reporterFactory.createReporter(reporterName).init(connection, compatibilityProxy, reporterFactory);
64-
OracleConnection oraCon = connection.unwrap(OracleConnection.class);
65-
66-
try (OracleCallableStatement stmt = (OracleCallableStatement) oraCon.prepareCall("{ ? = call ?.get_description() }")) {
67-
stmt.registerOutParameter(1, OracleType.VARCHAR2);
68-
stmt.setORAData(2, reporter);
53+
private String getDescription(String reporterNameWithOwner) throws SQLException {
54+
String plsql = "DECLARE l_obj " + reporterNameWithOwner + " := " + reporterNameWithOwner + "(); "
55+
+ "BEGIN :1 := l_obj.get_description(); END;";
56+
try (CallableStatement stmt = connection.prepareCall(plsql)) {
57+
stmt.registerOutParameter(1, Types.VARCHAR);
6958
stmt.execute();
70-
7159
return stmt.getString(1);
7260
}
7361
}

0 commit comments

Comments
 (0)