Skip to content

Commit

Permalink
[CONJ-1192] add a technical option for 3.3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jul 15, 2024
1 parent 5e2c3af commit 903ff6f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.sql.*;
import java.util.*;
import org.mariadb.jdbc.client.ColumnDecoder;
import org.mariadb.jdbc.client.result.CompleteResult;
import org.mariadb.jdbc.client.result.Result;
import org.mariadb.jdbc.client.util.ClosableLock;
import org.mariadb.jdbc.export.ExceptionFactory;
Expand Down Expand Up @@ -257,6 +259,13 @@ public ResultSet executeQuery() throws SQLException {
if (currResult instanceof Result) {
return (Result) currResult;
}
if (Boolean.parseBoolean(
con.getContext().getConf().nonMappedOptions().getProperty("permitNoResults", "false"))) {
// for compatibility with pre 3.4.0 version
return new CompleteResult(
new ColumnDecoder[0], new byte[0][], con.getContext(), resultSetType);
}

throw new SQLException(
"PrepareStatement.executeQuery() command does NOT return a result-set as expected. Either"
+ " use PrepareStatement.execute(), PrepareStatement.executeUpdate(), or correct"
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.sql.*;
import java.util.*;
import java.util.regex.Pattern;
import org.mariadb.jdbc.client.ColumnDecoder;
import org.mariadb.jdbc.client.Completion;
import org.mariadb.jdbc.client.result.CompleteResult;
import org.mariadb.jdbc.client.result.Result;
import org.mariadb.jdbc.client.util.ClosableLock;
import org.mariadb.jdbc.client.util.Parameters;
Expand Down Expand Up @@ -382,6 +384,13 @@ public ResultSet executeQuery() throws SQLException {
if ((currResult instanceof Result)) {
return (Result) currResult;
}
if (Boolean.parseBoolean(
con.getContext().getConf().nonMappedOptions().getProperty("permitNoResults", "false"))) {
// for compatibility with pre 3.4.0 version
return new CompleteResult(
new ColumnDecoder[0], new byte[0][], con.getContext(), resultSetType);
}

throw new SQLException(
"PrepareStatement.executeQuery() command does NOT return a result-set as expected. Either"
+ " use PrepareStatement.execute(), PrepareStatement.executeUpdate(), or correct"
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/mariadb/jdbc/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.mariadb.jdbc.client.ColumnDecoder;
import org.mariadb.jdbc.client.Completion;
import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.result.CompleteResult;
Expand Down Expand Up @@ -168,6 +169,12 @@ public ResultSet executeQuery(String sql) throws SQLException {
if (currResult instanceof Result) {
return (Result) currResult;
}
if (Boolean.parseBoolean(
con.getContext().getConf().nonMappedOptions().getProperty("permitNoResults", "false"))) {
// for compatibility with pre 3.4.0 version
return new CompleteResult(
new ColumnDecoder[0], new byte[0][], con.getContext(), resultSetType);
}
throw new SQLException(
"Statement.executeQuery() command does NOT return a result-set as expected. Either use"
+ " Statement.execute(), Statement.executeUpdate(), or correct command");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private CompleteResult(ColumnDecoder[] metadataList, CompleteResult prev) {
* @param context connection context
* @param resultSetType result set type
*/
private CompleteResult(
public CompleteResult(
ColumnDecoder[] metadataList, byte[][] data, Context context, int resultSetType) {
super(metadataList, data, context, resultSetType);
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/mariadb/jdbc/integration/ProcedureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public void settingParameterBeforeOutRegistration() throws SQLException {
cstmt.setLong(1, 44L);
cstmt.execute();
assertEquals(88, cstmt.getLong(1));
ResultSet rs = cstmt.executeQuery();
assertFalse(rs.next());
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/org/mariadb/jdbc/integration/StatementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public void ensureJdbcErrorWhenNoResultset() throws SQLException {
+ " command");
ps.execute();
}
try (Connection con = createCon("&permitNoResults=true")) {
try (PreparedStatement ps = con.prepareStatement("DO ?", Statement.RETURN_GENERATED_KEYS)) {
ps.setInt(1, 1);
ps.execute();
ResultSet rs = ps.executeQuery();
assertFalse(rs.next());
ps.execute();
}
}
try (PreparedStatement ps =
sharedConnBinary.prepareStatement("DO ?", Statement.RETURN_GENERATED_KEYS)) {
ps.setInt(1, 1);
Expand All @@ -105,6 +114,14 @@ public void ensureJdbcErrorWhenNoResultset() throws SQLException {
+ " command");
ps.execute();
}
try (Connection con = createCon("permitNoResults=true&useServerPrepStmts=true")) {
try (PreparedStatement ps = con.prepareStatement("DO ?", Statement.RETURN_GENERATED_KEYS)) {
ps.setInt(1, 1);
ps.execute();
ResultSet rs = ps.executeQuery();
assertFalse(rs.next());
}
}
}

@Test
Expand Down

0 comments on commit 903ff6f

Please sign in to comment.