Skip to content

Commit

Permalink
[misc] changing default option value useServerPrepStmts to false (use…
Browse files Browse the repository at this point in the history
… text protocol by default)
  • Loading branch information
rusher committed May 9, 2017
1 parent 1c27460 commit 8a31453
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -22,10 +22,11 @@ env:
- MARIA=10.2 PACKET=8M
- MARIA=10.2 PACKET=20M
- MARIA=10.2 PACKET=40M
- TYPE=PREPARE MARIA=10.1 PACKET=40M
- TYPE=MAXSCALE MAXSCALE_VERSION=2.0.2 MARIA=10.1 PACKET=40M
- TYPE=REWRITE MARIA=10.1 PACKET=40M
- TYPE=MULTI MARIA=10.1 PACKET=40M
- TYPE=BULK_CLIENT MARIA=10.1 PACKET=40M
- TYPE=BULK_SERVER MARIA=10.1 PACKET=40M
- TYPE=NO_BULK_CLIENT MARIA=10.1 PACKET=40M
- TYPE=NO_BULK_SERVER MARIA=10.1 PACKET=40M
- COMPRESSION=false MARIA=10.1 PACKET=40M
Expand Down
11 changes: 7 additions & 4 deletions .travis/script.sh
Expand Up @@ -10,17 +10,20 @@ case "$TYPE" in
"REWRITE" )
urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&rewriteBatchedStatements=true'
;;
"PREPARE" )
urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useServerPrepStmts=true'
;;
"MULTI" )
urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&allowMultiQueries=true'
;;
"BULK_CLIENT" )
urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=true&useServerPrepStmts=false'
"BULK_SERVER" )
urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=true&useServerPrepStmts=true'
;;
"NO_BULK_CLIENT" )
urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=false&useServerPrepStmts=false'
urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=false'
;;
"NO_BULK_SERVER" )
urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=false'
urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=false&useServerPrepStmts=true'
;;
"COMPRESSION" )
urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useCompression=true'
Expand Down
Expand Up @@ -188,10 +188,9 @@ protected boolean executeInternal(int fetchSize) throws SQLException {
//valid parameters
for (int i = 0; i < prepareResult.getParamCount(); i++) {
if (parameters[i] == null) {
logger.error("You need to set exactly " + prepareResult.getParamCount()
+ " parameters on the prepared statement");
throw ExceptionMapper.getSqlException("You need to set exactly " + prepareResult.getParamCount()
+ " parameters on the prepared statement");
logger.error("Parameter at position " + (i + 1) + " is not set");
ExceptionMapper.throwException(new SQLException("Parameter at position " + (i + 1) + " is not set", "07004"),
connection, this);
}
}

Expand Down
Expand Up @@ -296,9 +296,9 @@ public enum DefaultOptions {
/**
* useServerPrepStmts must prepared statements be prepared on server side, or just faked on client side.
* if rewriteBatchedStatements is set to true, this options will be set to false.
* default to true.
* default to false.
*/
USESERVERPREPSTMTS("useServerPrepStmts", Boolean.TRUE, "1.3.0"),
USESERVERPREPSTMTS("useServerPrepStmts", Boolean.FALSE, "1.3.0"),

/**
* File path of the trustStore file (similar to java System property "javax.net.ssl.trustStore").
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/org/mariadb/jdbc/ErrorMessageTest.java
Expand Up @@ -62,8 +62,9 @@ public void testSmallBulkErrorMessage() throws SQLException {
executeBatchWithException(connection);
fail("Must Have thrown error");
} catch (SQLException sqle) {
assertTrue(sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values (?, ?)"));
String query = "INSERT INTO testErrorMessage(test, test2) values ("
+ (sharedUsePrepare() ? "?, ?)" : "'more than 10 characters to provoc error', 10)");
assertTrue(sqle.getCause().getCause().getMessage().contains(query));
}
}

Expand Down Expand Up @@ -109,8 +110,9 @@ public void testBigBulkErrorMessage() throws SQLException {
executeBigBatchWithException(connection);
fail("Must Have thrown error");
} catch (SQLException sqle) {
assertTrue(sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values (?, ?)"));
String query = "INSERT INTO testErrorMessage(test, test2) values ("
+ (sharedUsePrepare() ? "?, ?)" : "'more than 10 characters to provoc error', 200)");
assertTrue(sqle.getCause().getCause().getMessage().contains(query));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/mariadb/jdbc/PreparedStatementTest.java
Expand Up @@ -297,7 +297,7 @@ private void testRewriteMultiPacket(boolean notRewritable) throws SQLException {
}
int[] results = pstmt.executeBatch();
assertEquals(2, results.length);
if (notRewritable && !sharedIsRewrite()) {
if (notRewritable) {
for (int result : results) assertEquals(1, result);
} else {
for (int result : results) assertEquals(Statement.SUCCESS_NO_INFO, result);
Expand Down
88 changes: 88 additions & 0 deletions src/test/java/org/mariadb/jdbc/RePrepareTest.java
@@ -0,0 +1,88 @@
package org.mariadb.jdbc;

import org.junit.Test;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import static org.junit.Assert.*;

public class RePrepareTest extends BaseTest {

@Test
public void rePrepareTestSelectError() throws SQLException {
createTable("rePrepareTestSelectError", "test int");
try (Statement stmt = sharedConnection.createStatement()) {
stmt.execute("INSERT INTO rePrepareTestSelectError(test) VALUES (1)");
try (PreparedStatement preparedStatement = sharedConnection.prepareStatement("SELECT * FROM rePrepareTestSelectError where test = ?")) {
preparedStatement.setInt(1, 1);
ResultSet rs = preparedStatement.executeQuery();
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertFalse(rs.next());
stmt.execute("ALTER TABLE rePrepareTestSelectError" +
" CHANGE COLUMN `test` `test` VARCHAR(50) NULL DEFAULT NULL FIRST," +
"ADD COLUMN `test2` VARCHAR(50) NULL DEFAULT NULL AFTER `test`;");
ResultSet rs2 = preparedStatement.executeQuery();
preparedStatement.setInt(1, 1);
assertTrue(rs2.next());
assertEquals("1", rs2.getString(1));
assertFalse(rs2.next());
}
}
}

@Test
public void rePrepareTestInsertError() throws SQLException {
createTable("rePrepareTestInsertError", "test int");
try (Statement stmt = sharedConnection.createStatement()) {
try (PreparedStatement preparedStatement = sharedConnection.prepareStatement("INSERT INTO rePrepareTestInsertError(test) values (?)")) {

preparedStatement.setInt(1, 1);
preparedStatement.execute();

stmt.execute("ALTER TABLE rePrepareTestInsertError" +
" CHANGE COLUMN `test` `test` VARCHAR(50) NULL DEFAULT NULL FIRST;");

preparedStatement.setInt(1, 2);
preparedStatement.execute();

stmt.execute("ALTER TABLE rePrepareTestInsertError" +
" CHANGE COLUMN `test` `test` VARCHAR(100) NULL DEFAULT NULL FIRST," +
"ADD COLUMN `test2` VARCHAR(50) NULL DEFAULT NULL AFTER `test`;");

stmt.execute("flush tables with read lock");
stmt.execute("unlock tables");
preparedStatement.setInt(1, 3);
preparedStatement.execute();
}
}
}


@Test
public void cannotRePrepare() throws SQLException {
createTable("cannotRePrepare", "test int");
try (Statement stmt = sharedConnection.createStatement()) {
try (PreparedStatement preparedStatement = sharedConnection.prepareStatement("INSERT INTO cannotRePrepare(test) values (?)")) {

preparedStatement.setInt(1, 1);
preparedStatement.execute();

stmt.execute("ALTER TABLE cannotRePrepare" +
" CHANGE COLUMN `test` `otherName` VARCHAR(50) NULL DEFAULT NULL FIRST;");

preparedStatement.setInt(1, 2);
try {
preparedStatement.execute();
fail();
} catch (SQLException sqle) {
assertTrue(sqle.getMessage().contains("Unknown column 'test' in 'field list'"));
}

}
}
}
}

0 comments on commit 8a31453

Please sign in to comment.