Skip to content

Commit

Permalink
[misc] correction for mysql 5.6, 5.7 (moreResult missing flag)
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Mar 30, 2016
1 parent c050427 commit 49e3e35
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,8 @@ public void getResult(ExecutionResult executionResult, int resultSetScrollType,
}

MariaSelectResultSet mariaSelectResultset = new MariaSelectResultSet(ci, executionResult.getStatement(), this, packetFetcher,
binaryProtocol, resultSetScrollType, executionResult.getFetchSize());
binaryProtocol, resultSetScrollType, executionResult.getFetchSize(), callableResult);
mariaSelectResultset.initFetch();
mariaSelectResultset.setCallableResult(callableResult);
if (!executionResult.isSelectPossible()) {
throw new QueryException("Select command are not permitted via executeBatch() command");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class MariaSelectResultSet implements ResultSet {
private Options options;
private boolean returnTableAlias;
private boolean isClosed;
public boolean callableResult = false;
public boolean callableResult;

/**
* Create Streaming resultset.
Expand All @@ -130,7 +130,7 @@ public class MariaSelectResultSet implements ResultSet {
*/
public MariaSelectResultSet(ColumnInformation[] columnInformation, Statement statement, Protocol protocol,
ReadPacketFetcher fetcher, boolean isBinaryEncoded,
int resultSetScrollType, int fetchSize) {
int resultSetScrollType, int fetchSize, boolean isCanHaveCallableResultset) {

this.statement = statement;
this.isClosed = false;
Expand Down Expand Up @@ -161,6 +161,7 @@ public MariaSelectResultSet(ColumnInformation[] columnInformation, Statement sta
this.resultSet = new ArrayList<>();
this.dataFetchTime = 0;
this.rowPointer = -1;
this.callableResult = isCanHaveCallableResultset;
}

/**
Expand Down Expand Up @@ -198,6 +199,7 @@ public MariaSelectResultSet(ColumnInformation[] columnInformation, List<byte[][]
this.resultSet = resultSet;
this.dataFetchTime = 0;
this.rowPointer = -1;
this.callableResult = false;
}

/**
Expand Down Expand Up @@ -398,9 +400,15 @@ public boolean readNextValue(List<byte[][]> values) throws IOException, QueryExc
if (protocol.getActiveStreamingResult() == this) {
protocol.setActiveStreamingResult(null);
}

Buffer buffer = packetFetcher.getReusableBuffer(remaining);
protocol.setHasWarnings(((buffer.buf[0] & 0xff) + ((buffer.buf[1] & 0xff) << 8)) > 0);
protocol.setMoreResults((((buffer.buf[2] & 0xff) + ((buffer.buf[3] & 0xff) << 8)) & ServerStatus.MORE_RESULTS_EXISTS) != 0,

//force the more packet value when this is a callable output result.
//There is always a OK packet after a callable output result, but mysql 5.6-7
//is sending a bad "more result" flag (without setting more packet to true)
//so force the value, since this will corrupt connection.
protocol.setMoreResults(callableResult || (((buffer.buf[2] & 0xff) + ((buffer.buf[3] & 0xff) << 8)) & ServerStatus.MORE_RESULTS_EXISTS) != 0,
isBinaryEncoded);
protocol = null;
packetFetcher = null;
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/mariadb/jdbc/CallableStatementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,6 @@ private void testSetter(CallableStatement callable) throws Throwable {
}
}



@Test
public void testCallableThrowException() throws Exception {
createTable("testCallableThrowException1", "value_1 BIGINT PRIMARY KEY", "ENGINE=InnoDB");
Expand Down
36 changes: 0 additions & 36 deletions src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static void initClass() throws SQLException {
"ROW_FORMAT=COMPRESSED ENGINE=INNODB");
createTable("streamtest2", "id int primary key not null, strm text");
createTable("testServerPrepareMeta", "id int not null primary key auto_increment, id2 int not null, id3 DEC(4,2), id4 BIGINT UNSIGNED ");
createTable("ServerPrepareStatementPrepareCache", "id int not null primary key auto_increment, test varchar(20)");
}

@Test
Expand Down Expand Up @@ -738,41 +737,6 @@ public void run() {
}
}

@Test
public void testCache() throws SQLException {
try (Connection connection = setConnection()) {
final String query = "INSERT INTO ServerPrepareStatementPrepareCache(test) VALUES (?)";
final long startTime = System.nanoTime();
PreparedStatement pstmt = connection.prepareStatement(query);
pstmt.setString(1, "test1");
pstmt.execute();
final long executionTime = System.nanoTime() - startTime;

final long startTimeSecond = System.nanoTime();
PreparedStatement pstmt2 = connection.prepareStatement(query);
pstmt2.setString(1, "test2");
pstmt2.execute();
final long executionTimeSecond = System.nanoTime() - startTimeSecond;

System.out.println("total time : " + (executionTimeSecond) + " first : " + executionTime);
Assert.assertTrue(executionTimeSecond < executionTime);

ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM ServerPrepareStatementPrepareCache");
if (resultSet.next()) {
Assert.assertEquals("test1", resultSet.getString(2));
if (resultSet.next()) {
Assert.assertEquals("test2", resultSet.getString(2));
} else {
Assert.fail("Must have a result");
}
} else {
Assert.fail("Must have a result");
}
}
}



@Test
public void testPrepareStatementCache() throws Throwable {
//tester le cache prepareStatement
Expand Down

0 comments on commit 49e3e35

Please sign in to comment.