From 9fe880c6ed7ec27b12ba2a1a110f8084c42d69a2 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Mon, 22 Aug 2016 11:59:23 +0200 Subject: [PATCH 01/18] [CONJ-333] ResultSet.getString() on a time column return NULL when value=00:00:00 when option useServerPrepStmts is set to true --- pom.xml | 2 +- .../resultset/MariaSelectResultSet.java | 19 +++- .../jdbc/internal/util/constant/Version.java | 6 +- .../jdbc/DatatypeCompatibilityTest.java | 104 ++++++++++++++++++ 4 files changed, 122 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 969811645..35e62396f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ mariadb-java-client jar mariadb-java-client - 1.5.1-RC + 1.5.2-SNAPSHOT JDBC driver for MariaDB and MySQL https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/ diff --git a/src/main/java/org/mariadb/jdbc/internal/queryresults/resultset/MariaSelectResultSet.java b/src/main/java/org/mariadb/jdbc/internal/queryresults/resultset/MariaSelectResultSet.java index ddee1f33d..9db272844 100644 --- a/src/main/java/org/mariadb/jdbc/internal/queryresults/resultset/MariaSelectResultSet.java +++ b/src/main/java/org/mariadb/jdbc/internal/queryresults/resultset/MariaSelectResultSet.java @@ -872,7 +872,7 @@ private String getString(byte[] rawBytes, ColumnInformation columnInfo, Calendar case FLOAT: return String.valueOf(getFloat(rawBytes, columnInfo)); case TIME: - return getTimeString(rawBytes); + return getTimeString(rawBytes, columnInfo); case DATE: if (isBinaryEncoded) { try { @@ -2917,16 +2917,25 @@ public void setReturnTableAlias(boolean returnTableAlias) { this.returnTableAlias = returnTableAlias; } - private String getTimeString(byte[] rawBytes) { - if (rawBytes == null || rawBytes.length == 0) { - return null; + private String getTimeString(byte[] rawBytes, ColumnInformation columnInfo) { + if (rawBytes == null) return null; + if (rawBytes.length == 0) { + // binary send 00:00:00 as 0. + if (columnInfo.getDecimals() == 0) { + return "00:00:00"; + } else { + String value = "00:00:00."; + int decimal = columnInfo.getDecimals(); + while (decimal-- > 0) value += "0"; + return value; + } } String rawValue = new String(rawBytes, StandardCharsets.UTF_8); if ("0000-00-00".equals(rawValue)) { return null; } if (!this.isBinaryEncoded) { - if (!options.useLegacyDatetimeCode && rawValue.indexOf(".") > 0) { + if (options.maximizeMysqlCompatibility && options.useLegacyDatetimeCode && rawValue.indexOf(".") > 0) { return rawValue.substring(0, rawValue.indexOf(".")); } return rawValue; diff --git a/src/main/java/org/mariadb/jdbc/internal/util/constant/Version.java b/src/main/java/org/mariadb/jdbc/internal/util/constant/Version.java index 584d4f0bd..c47759a87 100644 --- a/src/main/java/org/mariadb/jdbc/internal/util/constant/Version.java +++ b/src/main/java/org/mariadb/jdbc/internal/util/constant/Version.java @@ -51,10 +51,10 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS package org.mariadb.jdbc.internal.util.constant; public final class Version { - public static final String version = "1.5.1-RC"; + public static final String version = "1.5.2-SNAPSHOT"; public static final int majorVersion = 1; public static final int minorVersion = 5; - public static final int patchVersion = 1; - public static final String qualifier = "RC"; + public static final int patchVersion = 2; + public static final String qualifier = "SNAPSHOT"; } \ No newline at end of file diff --git a/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java b/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java index 13dcd456d..833a8ad78 100644 --- a/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java +++ b/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java @@ -1,5 +1,6 @@ package org.mariadb.jdbc; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -11,6 +12,8 @@ import static org.junit.Assert.*; public class DatatypeCompatibilityTest extends BaseTest { + private static final String sql = "SELECT id, time_test FROM time_test;"; + /** * Initialization. * @throws SQLException exception @@ -56,6 +59,8 @@ public static void initClass() throws SQLException { ); createTable("ytab", "y year"); createTable("maxcharlength", "maxcharlength char(1)", "character set utf8"); + createTable("time_test", "ID int unsigned NOT NULL, time_test time(6), PRIMARY KEY (ID)", "engine=InnoDB"); + sharedConnection.createStatement().execute("insert into time_test(id, time_test) values(1, '00:00:00'), (2, '00:00:00.123'), (3, null);"); } @Test @@ -155,4 +160,103 @@ public void timeAsTimestamp() throws Exception { assertEquals(testTime, time); } + /** + * Check Time getTime() answer using Statement. + * + * @param connection connection + * @throws SQLException if any error occur + */ + public void testStatementGetTime(Connection connection) throws SQLException { + try (Statement statement = connection.createStatement()) { + try (ResultSet resultSet = statement.executeQuery(sql)) { + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("00:00:00", "" + resultSet.getTime(2)); + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("00:00:00", "" + resultSet.getTime(2)); + Assert.assertTrue(resultSet.next()); + Assert.assertNull(resultSet.getTime(2)); + Assert.assertFalse(resultSet.next()); + } + } + } + + /** + * Check Time getString() answer using Statement. + * + * @param connection connection + * @throws SQLException if any error occur + */ + public void testStatementGetString(Connection connection) throws SQLException { + try (Statement statement = connection.createStatement()) { + try (ResultSet resultSet = statement.executeQuery(sql)) { + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("00:00:00.000000", resultSet.getString(2)); + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("00:00:00.123000", resultSet.getString(2)); + Assert.assertTrue(resultSet.next()); + Assert.assertNull(resultSet.getString(2)); + Assert.assertFalse(resultSet.next()); + } + } + } + + /** + * Check Time getTime() answer using prepareStatement. + * + * @param connection connection + * @throws SQLException if any error occur + */ + public void testPreparedStatementGetTime(Connection connection) throws SQLException { + try (Statement statement = connection.createStatement()) { + try (ResultSet resultSet = statement.executeQuery(sql)) { + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("00:00:00", "" + resultSet.getTime(2)); + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("00:00:00", "" + resultSet.getTime(2)); + Assert.assertTrue(resultSet.next()); + Assert.assertNull(resultSet.getTime(2)); + Assert.assertFalse(resultSet.next()); + } + } + } + + /** + * Check Time getString() answer using prepareStatement. + * + * @param connection connection + * @throws SQLException if any error occur + */ + public void testPreparedStatementGetString(Connection connection) throws SQLException { + try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { + try (ResultSet resultSet = preparedStatement.executeQuery()) { + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("00:00:00.000000", resultSet.getString(2)); + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("00:00:00.123000", resultSet.getString(2)); + Assert.assertTrue(resultSet.next()); + Assert.assertNull(resultSet.getString(2)); + Assert.assertFalse(resultSet.next()); + } + } + } + + @Test + public void testTimePrepareStatement() throws SQLException { + try (Connection connection = setConnection("&useServerPrepStmts=true")) { + testStatementGetTime(connection); + testPreparedStatementGetTime(connection); + testStatementGetString(connection); + testPreparedStatementGetString(connection); + } + } + + @Test + public void testTimeNotPrepareStatement() throws SQLException { + try (Connection connection = setConnection("&useServerPrepStmts=false")) { + testStatementGetTime(connection); + testPreparedStatementGetTime(connection); + testStatementGetString(connection); + testPreparedStatementGetString(connection); + } + } } \ No newline at end of file From 2d50b01f67d02d9f2c56ab7d72b9239e2f560bdd Mon Sep 17 00:00:00 2001 From: kolzeq Date: Mon, 22 Aug 2016 12:20:47 +0200 Subject: [PATCH 02/18] [misc] correction to permit running Aurora CI --- src/test/java/org/mariadb/jdbc/BaseTest.java | 21 ++++++++++--------- .../jdbc/DatatypeCompatibilityTest.java | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/mariadb/jdbc/BaseTest.java b/src/test/java/org/mariadb/jdbc/BaseTest.java index 56d436aaf..d4cb878a9 100644 --- a/src/test/java/org/mariadb/jdbc/BaseTest.java +++ b/src/test/java/org/mariadb/jdbc/BaseTest.java @@ -52,17 +52,18 @@ protected void starting(Description description) { //execute another query to ensure connection is stable protected void finished(Description description) { - Random random = new Random(); - int randInt = random.nextInt(); - - try (PreparedStatement preparedStatement = sharedConnection.prepareStatement("SELECT " + randInt)) { - ResultSet rs = preparedStatement.executeQuery(); - Assert.assertTrue(rs.next()); - Assert.assertEquals(randInt, rs.getInt(1)); - } catch (Exception e) { - e.printStackTrace(); + if (testSingleHost) { + Random random = new Random(); + int randInt = random.nextInt(); + + try (PreparedStatement preparedStatement = sharedConnection.prepareStatement("SELECT " + randInt)) { + ResultSet rs = preparedStatement.executeQuery(); + Assert.assertTrue(rs.next()); + Assert.assertEquals(randInt, rs.getInt(1)); + } catch (Exception e) { + e.printStackTrace(); + } } - } protected void succeeded(Description description) { diff --git a/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java b/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java index 833a8ad78..4b4df25f0 100644 --- a/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java +++ b/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java @@ -60,7 +60,7 @@ public static void initClass() throws SQLException { createTable("ytab", "y year"); createTable("maxcharlength", "maxcharlength char(1)", "character set utf8"); createTable("time_test", "ID int unsigned NOT NULL, time_test time(6), PRIMARY KEY (ID)", "engine=InnoDB"); - sharedConnection.createStatement().execute("insert into time_test(id, time_test) values(1, '00:00:00'), (2, '00:00:00.123'), (3, null);"); + sharedConnection.createStatement().execute("insert into time_test(id, time_test) values(1, '00:00:00'), (2, '00:00:00.123'), (3, null)"); } @Test From 881fa447a8209cc5006e2f29dbd7c6f7f86e68d7 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Mon, 22 Aug 2016 12:29:08 +0200 Subject: [PATCH 03/18] [misc] correction to permit running Aurora CI second correction --- .../java/org/mariadb/jdbc/DatatypeCompatibilityTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java b/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java index 4b4df25f0..8f2274faa 100644 --- a/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java +++ b/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java @@ -60,7 +60,10 @@ public static void initClass() throws SQLException { createTable("ytab", "y year"); createTable("maxcharlength", "maxcharlength char(1)", "character set utf8"); createTable("time_test", "ID int unsigned NOT NULL, time_test time(6), PRIMARY KEY (ID)", "engine=InnoDB"); - sharedConnection.createStatement().execute("insert into time_test(id, time_test) values(1, '00:00:00'), (2, '00:00:00.123'), (3, null)"); + + if (testSingleHost) { + sharedConnection.createStatement().execute("insert into time_test(id, time_test) values(1, '00:00:00'), (2, '00:00:00.123'), (3, null)"); + } } @Test From 789d5590dae93534c75ae9026422af616642b10f Mon Sep 17 00:00:00 2001 From: kolzeq Date: Mon, 22 Aug 2016 12:34:51 +0200 Subject: [PATCH 04/18] [CONJ-332] enabledSslCipherSuites setting to permit new ciphers --- .../mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java b/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java index 7e3b1f006..f9645f9cf 100644 --- a/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java +++ b/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java @@ -866,7 +866,7 @@ protected void enabledSslProtocolSuites(SSLSocket sslSocket) throws QueryExcepti */ protected void enabledSslCipherSuites(SSLSocket sslSocket) throws QueryException { if (options.enabledSslCipherSuites != null) { - List possibleCiphers = Arrays.asList(sslSocket.getEnabledCipherSuites()); + List possibleCiphers = Arrays.asList(sslSocket.getSupportedCipherSuites()); String[] ciphers = options.enabledSslCipherSuites.split("[,;\\s]+"); for (String cipher : ciphers) { if (!possibleCiphers.contains(cipher)) { From 22e488b0fadbe8e05d081e774b43c31d5fbd19c7 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Mon, 22 Aug 2016 18:20:06 +0200 Subject: [PATCH 05/18] [misc] travis environment variable correction --- .travis.yml | 51 +++++++++++++++++++++--------------------- .travis/before_test.sh | 41 +++++++++------------------------ .travis/script.sh | 35 +++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 55 deletions(-) create mode 100644 .travis/script.sh diff --git a/.travis.yml b/.travis.yml index 0490d3049..eb6825209 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,33 +2,34 @@ sudo: required language: java before_install: - chmod +x .travis/before_test.sh + - chmod +x .travis/script.sh install: .travis/before_test.sh jdk: - oraclejdk8 - oraclejdk7 env: - - AURORA=true SINGLEHOST=false - - MARIA_VERSION=5.5 MAX_ALLOWED_PACKET=8M INNODB_LOG_FILE_SIZE=80M SINGLEHOST=true - - MARIA_VERSION=5.5 MAX_ALLOWED_PACKET=20M INNODB_LOG_FILE_SIZE=200M SINGLEHOST=true - - MARIA_VERSION=5.5 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - MARIA_VERSION=10.0 MAX_ALLOWED_PACKET=8M INNODB_LOG_FILE_SIZE=80M SINGLEHOST=true - - MARIA_VERSION=10.0 MAX_ALLOWED_PACKET=20M INNODB_LOG_FILE_SIZE=200M SINGLEHOST=true - - MARIA_VERSION=10.0 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - MARIA_VERSION=10.1 MAX_ALLOWED_PACKET=8M INNODB_LOG_FILE_SIZE=80M SINGLEHOST=true - - MARIA_VERSION=10.1 MAX_ALLOWED_PACKET=20M INNODB_LOG_FILE_SIZE=200M SINGLEHOST=true - - MARIA_VERSION=10.1 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - TYPE=REWRITE MARIA_VERSION=10.1 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - TYPE=MULTI MARIA_VERSION=10.1 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - TYPE=BULK_CLIENT MARIA_VERSION=10.1 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - TYPE=NO_BULK_CLIENT MARIA_VERSION=10.1 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - TYPE=NO_BULK_SERVER MARIA_VERSION=10.1 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - COMPRESSION=true MARIA_VERSION=10.1 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - TYPE=NO_BULK_SERVER MARIA_VERSION=10.2 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - COMPRESSION=true MARIA_VERSION=10.2 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - MYSQL_VERSION=5.7 MAX_ALLOWED_PACKET=8M INNODB_LOG_FILE_SIZE=80M SINGLEHOST=true - - MYSQL_VERSION=5.7 MAX_ALLOWED_PACKET=20M INNODB_LOG_FILE_SIZE=200M SINGLEHOST=true - - MYSQL_VERSION=5.7 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true - - MYSQL_VERSION=5.6 MAX_ALLOWED_PACKET=8M INNODB_LOG_FILE_SIZE=80M SINGLEHOST=true - - MYSQL_VERSION=5.6 MAX_ALLOWED_PACKET=20M INNODB_LOG_FILE_SIZE=200M SINGLEHOST=true - - MYSQL_VERSION=5.6 MAX_ALLOWED_PACKET=40M INNODB_LOG_FILE_SIZE=400M SINGLEHOST=true -script: mvn clean test $URLSTRING -DtestSingleHost=$SINGLEHOST $ADDITIONNAL_VARIABLES -DjobId=$TRAVIS_JOB_ID -DkeystorePath="/etc/mysql/client-keystore.p12" -DkeystorePassword="kspass" + - AURORA=true + - MARIA=5.5 PACKET=8M + - MARIA=5.5 PACKET=20M + - MARIA=5.5 PACKET=40M + - MARIA=10.0 PACKET=8M + - MARIA=10.0 PACKET=20M + - MARIA=10.0 PACKET=40M + - MARIA=10.1 PACKET=8M + - MARIA=10.1 PACKET=20M + - 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=NO_BULK_CLIENT MARIA=10.1 PACKET=40M + - TYPE=NO_BULK_SERVER MARIA=10.1 PACKET=40M + - COMPRESSION=false MARIA=10.1 PACKET=40M + - TYPE=NO_BULK_SERVER MARIA=10.2 PACKET=40M + - COMPRESSION=false MARIA=10.2 PACKET=40M + - MYSQL=5.7 PACKET=8M + - MYSQL=5.7 PACKET=20M + - MYSQL=5.7 PACKET=40M + - MYSQL=5.6 PACKET=8M + - MYSQL=5.6 PACKET=20M + - MYSQL=5.6 PACKET=40M +script: .travis/script.sh diff --git a/.travis/before_test.sh b/.travis/before_test.sh index 89e66ccd2..07aaaf876 100644 --- a/.travis/before_test.sh +++ b/.travis/before_test.sh @@ -11,59 +11,40 @@ remove_mysql(){ } remove_mysql -case "$TYPE" in - "REWRITE" ) - export URLSTRING=-DdbURL='jdbc:mariadb://localhost:3306/testj?user=root&rewriteBatchedStatements=true' - ;; - "MULTI" ) - export URLSTRING=-DdbURL='jdbc:mariadb://localhost:3306/testj?user=root&allowMultiQueries=true' - ;; - "BULK_CLIENT" ) - export URLSTRING=-DdbURL='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=true&useServerPrepStmts=false' - ;; - "NO_BULK_CLIENT" ) - export URLSTRING=-DdbURL='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=false&useServerPrepStmts=false' - ;; - "NO_BULK_SERVER" ) - export URLSTRING=-DdbURL='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=false' - ;; - "COMPRESSION" ) - export URLSTRING=-DdbURL='jdbc:mariadb://localhost:3306/testj?user=root&useCompression=true' - ;; -esac; - if [ -n "$AURORA" ] then # AURORA tests doesn't need an installation - echo "$MYSQL_VERSION" + echo "$MYSQL" else - if [ -n "$MYSQL_VERSION" ] + if [ -n "$MYSQL" ] then sudo tee /etc/apt/sources.list.d/mysql.list << END -deb http://repo.mysql.com/apt/ubuntu/ precise mysql-$MYSQL_VERSION -deb-src http://repo.mysql.com/apt/ubuntu/ precise mysql-$MYSQL_VERSION +deb http://repo.mysql.com/apt/ubuntu/ precise mysql-$MYSQL +deb-src http://repo.mysql.com/apt/ubuntu/ precise mysql-$MYSQL END sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5 sudo apt-get -qq update --force-yes sudo apt-get -qq install mysql-server --force-yes - dpkg -l|grep ^ii|grep mysql-server|grep ${MYSQL_VERSION/-dmr/} + dpkg -l|grep ^ii|grep mysql-server|grep ${MYSQL/-dmr/} else sudo apt-get -qq install python-software-properties sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db - sudo add-apt-repository "deb [arch=amd64,i386] http://nyc2.mirrors.digitalocean.com/mariadb/repo/${MARIA_VERSION}/ubuntu precise main" + sudo add-apt-repository "deb [arch=amd64,i386] http://nyc2.mirrors.digitalocean.com/mariadb/repo/${MARIA}/ubuntu precise main" sudo apt-get -qq update sudo apt-get -qq install mariadb-server fi + + INNODB_LOG_FILE_SIZE=$(echo $PACKET| cut -d'M' -f 1)0M sudo tee /etc/mysql/conf.d/map.cnf << END [mysqld] -max_allowed_packet=$MAX_ALLOWED_PACKET +max_allowed_packet=$PACKET innodb_log_file_size=$INNODB_LOG_FILE_SIZE END @@ -84,7 +65,7 @@ END sudo service mysql stop #Adding sleep time for clean shutdown - if [ "x$MYSQL_VERSION" != "x" ] + if [ "x$MYSQL" != "x" ] then sleep 2 fi @@ -92,7 +73,7 @@ END sudo service mysql start #Adding sleep time if mysql DB. If not SSL not totally initialized when launching tests - if [ "x$MYSQL_VERSION" != "x" ] + if [ "x$MYSQL" != "x" ] then sleep 20 fi diff --git a/.travis/script.sh b/.travis/script.sh new file mode 100644 index 000000000..0664526a4 --- /dev/null +++ b/.travis/script.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -x +set -e + +case "$TYPE" in + "REWRITE" ) + urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&rewriteBatchedStatements=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' + ;; + "NO_BULK_CLIENT" ) + urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=false&useServerPrepStmts=false' + ;; + "NO_BULK_SERVER" ) + urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useBatchMultiSend=false' + ;; + "COMPRESSION" ) + urlString=-DdbUrl='jdbc:mariadb://localhost:3306/testj?user=root&useCompression=true' + ;; +esac; + +if [ -n "$AURORA" ] +then + testSingleHost=false +else + testSingleHost=true +fi + + +mvn clean test $urlString -DtestSingleHost=$testSingleHost $ADDITIONNAL_VARIABLES -DjobId=$TRAVIS_JOB_ID -DkeystorePath="/etc/mysql/client-keystore.p12" -DkeystorePassword="kspass" \ No newline at end of file From c756d68354ea57766aed850279bd8590b119e5b7 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Mon, 22 Aug 2016 18:53:13 +0200 Subject: [PATCH 06/18] [misc] correction using "call" PrepareStatement queries when using useServerPrepStmts to false --- src/main/java/org/mariadb/jdbc/MariaDbConnection.java | 5 ++--- src/test/java/org/mariadb/jdbc/DriverTest.java | 8 ++++---- src/test/java/org/mariadb/jdbc/PreparedStatementTest.java | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/mariadb/jdbc/MariaDbConnection.java b/src/main/java/org/mariadb/jdbc/MariaDbConnection.java index dc77425f1..d7090ab84 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbConnection.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbConnection.java @@ -405,12 +405,11 @@ public PreparedStatement internalPrepareStatement(final String sql, final int re checkConnection(); boolean canUsePrepareStatement = false; - if (options.rewriteBatchedStatements) { + String cleanSql = sql.toUpperCase().trim(); + if (options.rewriteBatchedStatements || !options.useServerPrepStmts) { //in case of CALL statement, handling INOUT parameter is better with Prepare protocol - String cleanSql = sql.toUpperCase().trim(); canUsePrepareStatement = cleanSql.contains("CALL"); } else if (options.useServerPrepStmts && sql != null) { - String cleanSql = sql.toUpperCase().trim(); canUsePrepareStatement = (cleanSql.contains("SELECT") || cleanSql.contains("CALL") || cleanSql.contains("UPDATE") diff --git a/src/test/java/org/mariadb/jdbc/DriverTest.java b/src/test/java/org/mariadb/jdbc/DriverTest.java index 1a4b61685..545b42155 100644 --- a/src/test/java/org/mariadb/jdbc/DriverTest.java +++ b/src/test/java/org/mariadb/jdbc/DriverTest.java @@ -1125,17 +1125,17 @@ public void batchUpdateException() throws Exception { } catch (BatchUpdateException bue) { int[] updateCounts = bue.getUpdateCounts(); assertEquals(4, updateCounts.length); - if (sharedUsePrepare()) { - //prepare or allowMultiQueries options + if (sharedIsRewrite()) { assertEquals(1, updateCounts[0]); assertEquals(1, updateCounts[1]); assertEquals(Statement.EXECUTE_FAILED, updateCounts[2]); - assertEquals(1, updateCounts[3]); + assertEquals(Statement.EXECUTE_FAILED, updateCounts[3]); } else { + //prepare or allowMultiQueries options assertEquals(1, updateCounts[0]); assertEquals(1, updateCounts[1]); assertEquals(Statement.EXECUTE_FAILED, updateCounts[2]); - assertEquals(Statement.EXECUTE_FAILED, updateCounts[3]); + assertEquals(1, updateCounts[3]); } assertTrue(bue.getCause() instanceof SQLIntegrityConstraintViolationException); } diff --git a/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java b/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java index 48fec734e..4bed96459 100644 --- a/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java +++ b/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java @@ -56,7 +56,7 @@ public void insertSelect() throws Exception { "insert into test_insert_select ( field1) (select TMP.field1 from (select ? `field1` from dual) TMP)"); stmt.setString(1, "test"); stmt.executeUpdate(); - if (sharedOptions().useBatchMultiSend && !sharedIsRewrite()) fail("Must have fail"); + if (sharedOptions().useBatchMultiSend && sharedUsePrepare()) fail("Must have fail"); } catch (SQLException e) { if (!sharedOptions().useBatchMultiSend) { fail("Must have fallback to client preparedStatement"); From 65c815c4056b8e0be03574d0af15c19d42a4ce06 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Mon, 22 Aug 2016 20:59:23 +0200 Subject: [PATCH 07/18] [misc] correcting sqlstate test result --- src/test/java/org/mariadb/jdbc/PooledConnectionTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/mariadb/jdbc/PooledConnectionTest.java b/src/test/java/org/mariadb/jdbc/PooledConnectionTest.java index d75b1509a..172f03500 100644 --- a/src/test/java/org/mariadb/jdbc/PooledConnectionTest.java +++ b/src/test/java/org/mariadb/jdbc/PooledConnectionTest.java @@ -78,7 +78,8 @@ public void testPooledConnectionStatementError() throws Exception { Assert.assertTrue(e.getMessage().contains("Parameter at position 1 is not set") || e.getMessage().contains("Incorrect arguments to mysqld_stmt_execute")); } else { - Assert.assertEquals(listener.sqlException.getSQLState(), "07004"); + //HY000 if server >= 10.2 ( send prepare and query in a row), 07004 otherwise + Assert.assertTrue("07004".equals(listener.sqlException.getSQLState()) || "HY000".equals(listener.sqlException.getSQLState())); } } ps.close(); From ff7b1db7927147a7bf87b00cc1ecee2f3850b267 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Tue, 23 Aug 2016 16:38:40 +0200 Subject: [PATCH 08/18] [CONJ-335] regression : Pool connection may fail to connect with good user --- src/main/java/org/mariadb/jdbc/UrlParser.java | 15 ++++++-------- .../mariadb/jdbc/internal/util/Options.java | 1 - .../java/org/mariadb/jdbc/ParserTest.java | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/mariadb/jdbc/UrlParser.java b/src/main/java/org/mariadb/jdbc/UrlParser.java index f91269d9e..1992a572f 100644 --- a/src/main/java/org/mariadb/jdbc/UrlParser.java +++ b/src/main/java/org/mariadb/jdbc/UrlParser.java @@ -207,7 +207,7 @@ private static void parseInternal(UrlParser urlParser, String url, Properties pr additionalParameters = null; } - urlParser = defineUrlParserParameters(urlParser, properties, hostAddressesString, additionalParameters); + defineUrlParserParameters(urlParser, properties, hostAddressesString, additionalParameters); setDefaultHostAddressType(urlParser); } catch (IllegalArgumentException i) { @@ -223,9 +223,8 @@ private static void parseInternal(UrlParser urlParser, String url, Properties pr * @param properties properties * @param hostAddressesString string that holds all the host addresses * @param additionalParameters string that holds all parameters defined for the connection - * @return UrlParser instance */ - private static UrlParser defineUrlParserParameters(UrlParser urlParser, Properties properties, String hostAddressesString, + private static void defineUrlParserParameters(UrlParser urlParser, Properties properties, String hostAddressesString, String additionalParameters) { if (additionalParameters != null) { @@ -239,23 +238,21 @@ private static UrlParser defineUrlParserParameters(UrlParser urlParser, Properti String options2 = (matcher.group(3) != null) ? matcher.group(3).substring(1) : ""; urlParser.database = (db1 != null) ? db1 : db2; - urlParser.options = (!options1.equals("")) - ? DefaultOptions.parse(urlParser.haMode, options1, properties) : DefaultOptions.parse(urlParser.haMode, options2, properties); + urlParser.options = DefaultOptions.parse(urlParser.haMode, (!options1.equals("")) ? options1 : options2, + properties, urlParser.options); } else { urlParser.database = null; - urlParser.options = DefaultOptions.parse(urlParser.haMode, "", properties); + urlParser.options = DefaultOptions.parse(urlParser.haMode, "", properties, urlParser.options); } } else { urlParser.database = null; - urlParser.options = DefaultOptions.parse(urlParser.haMode, "", properties); + urlParser.options = DefaultOptions.parse(urlParser.haMode, "", properties, urlParser.options); } LoggerFactory.init(urlParser.options.log || urlParser.options.profileSql || urlParser.options.slowQueryThresholdNanos != null); urlParser.addresses = HostAddress.parse(hostAddressesString, urlParser.haMode); - - return urlParser; } private static void setHaMode(UrlParser urlParser,String url, int separator) { diff --git a/src/main/java/org/mariadb/jdbc/internal/util/Options.java b/src/main/java/org/mariadb/jdbc/internal/util/Options.java index aa82ae4df..889b515fd 100644 --- a/src/main/java/org/mariadb/jdbc/internal/util/Options.java +++ b/src/main/java/org/mariadb/jdbc/internal/util/Options.java @@ -127,7 +127,6 @@ public String toString() { return "Options{" + "user='" + user + '\'' + ", assureReadOnly=" + assureReadOnly - + ", password='" + password + '\'' + ", trustServerCertificate=" + trustServerCertificate + ", serverSslCert='" + serverSslCert + '\'' + ", useFractionalSeconds=" + useFractionalSeconds diff --git a/src/test/java/org/mariadb/jdbc/ParserTest.java b/src/test/java/org/mariadb/jdbc/ParserTest.java index bd2c55f84..99d3dda5f 100644 --- a/src/test/java/org/mariadb/jdbc/ParserTest.java +++ b/src/test/java/org/mariadb/jdbc/ParserTest.java @@ -2,13 +2,16 @@ import org.junit.BeforeClass; import org.junit.Test; +import org.mariadb.jdbc.internal.util.DefaultOptions; import org.mariadb.jdbc.internal.util.Options; +import org.mariadb.jdbc.internal.util.constant.HaMode; import java.lang.reflect.Field; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; import java.util.Properties; import static org.junit.Assert.*; @@ -24,6 +27,23 @@ public static void initClass() throws SQLException { createTable("table2", "id2 int auto_increment primary key"); } + @Test + public void poolVerification() throws Exception { + ArrayList hostAddresses = new ArrayList<>(); + hostAddresses.add(new HostAddress(hostname, port)); + UrlParser urlParser = new UrlParser(database, hostAddresses, DefaultOptions.defaultValues(HaMode.NONE), HaMode.NONE); + urlParser.setUsername("USER"); + urlParser.setPassword("PWD"); + urlParser.parseUrl("jdbc:mariadb://localhost:3306/db"); + assertEquals("USER", urlParser.getUsername()); + assertEquals("PWD", urlParser.getPassword()); + + MariaDbDataSource datasource = new MariaDbDataSource(); + datasource.setUser("USER"); + datasource.setPassword("PWD"); + datasource.setUrl("jdbc:mariadb://localhost:3306/db"); + } + @Test public void addProperties() throws Exception { From 18fac0608b6b100b0811729b146194743b1b7a53 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Tue, 23 Aug 2016 17:41:21 +0200 Subject: [PATCH 09/18] [CONJ-299] PreparedStatement.setObject(Type.BIT, "1") should register as true --- .../jdbc/AbstractMariaDbPrepareStatement.java | 3 +- .../java/org/mariadb/jdbc/DatatypeTest.java | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/mariadb/jdbc/AbstractMariaDbPrepareStatement.java b/src/main/java/org/mariadb/jdbc/AbstractMariaDbPrepareStatement.java index 78f135148..8bd95df55 100644 --- a/src/main/java/org/mariadb/jdbc/AbstractMariaDbPrepareStatement.java +++ b/src/main/java/org/mariadb/jdbc/AbstractMariaDbPrepareStatement.java @@ -866,7 +866,8 @@ private void setInternalObject(final int parameterIndex, final Object obj, final try { switch (targetSqlType) { case Types.BIT: - setBoolean(parameterIndex, Boolean.valueOf(str)); + case Types.BOOLEAN: + setBoolean(parameterIndex, !("false".equalsIgnoreCase(str) || "0".equals(str))); break; case Types.TINYINT: setByte(parameterIndex, Byte.parseByte(str)); diff --git a/src/test/java/org/mariadb/jdbc/DatatypeTest.java b/src/test/java/org/mariadb/jdbc/DatatypeTest.java index b0c953f38..006ee9a88 100644 --- a/src/test/java/org/mariadb/jdbc/DatatypeTest.java +++ b/src/test/java/org/mariadb/jdbc/DatatypeTest.java @@ -42,6 +42,8 @@ public static void initClass() throws SQLException { createTable("blabla", "valsue varchar(20)"); createTable("TestBigIntType", "t1 bigint(20), t2 bigint(20), t3 bigint(20), t4 bigint(20)"); createTable("time_period", "ID int unsigned NOT NULL, START time NOT NULL, END time NOT NULL, PRIMARY KEY (ID)"); + createTable("bitBoolTest", "d1 BOOLEAN, d2 BIT"); + } @@ -371,6 +373,66 @@ public void testBadParamlist() throws SQLException { ps.execute(); } + /** + * CONJ-299 - PreparedStatement.setObject(Type.BIT, "1") should register as true. + */ + + @Test + public void setBitBoolObjectTest() throws SQLException, IOException, ClassNotFoundException { + PreparedStatement ps = sharedConnection.prepareStatement("insert into bitBoolTest values (?,?)"); + ps.setObject(1, 0); + ps.setObject(2, 0); + ps.addBatch(); + + ps.setObject(1, 1); + ps.setObject(2, 1); + ps.addBatch(); + + ps.setObject(1, "0", Types.BOOLEAN); + ps.setObject(2, "0", Types.BIT); + ps.addBatch(); + + ps.setObject(1, "1", Types.BOOLEAN); + ps.setObject(2, "1", Types.BIT); + ps.addBatch(); + + ps.setObject(1, "true", Types.BOOLEAN); + ps.setObject(2, "true", Types.BIT); + ps.addBatch(); + + ps.setObject(1, "truee", Types.BOOLEAN); + ps.setObject(2, "truee", Types.BIT); + ps.addBatch(); + + ps.setObject(1, "false", Types.BOOLEAN); + ps.setObject(2, "false", Types.BIT); + ps.addBatch(); + + ps.executeBatch(); + + try (ResultSet rs = sharedConnection.createStatement().executeQuery("select * from bitBoolTest")) { + assertValue(rs, false); + assertValue(rs, true); + assertValue(rs, false); + assertValue(rs, true); + assertValue(rs, true); + assertValue(rs, true); + assertValue(rs, false); + assertFalse(rs.next()); + } + } + + private void assertValue(ResultSet rs, boolean bool) throws SQLException { + assertTrue(rs.next()); + if (bool) { + assertTrue(rs.getBoolean(1)); + assertTrue(rs.getBoolean(2)); + } else { + assertFalse(rs.getBoolean(1)); + assertFalse(rs.getBoolean(2)); + } + } + @Test public void setObjectTest() throws SQLException, IOException, ClassNotFoundException { PreparedStatement ps = sharedConnection.prepareStatement("insert into objecttest values (?,?,?,?)"); From d370cac711728c27b25ddbe6dd988ec326ca9366 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Wed, 24 Aug 2016 11:23:13 +0200 Subject: [PATCH 10/18] [CONJ-293] permit pipe without hostname (url string like "jdbc:mariadb:///db?pipe=namepipe") as documented --- .../org/mariadb/jdbc/MariaDbConnection.java | 27 ++++---- .../protocol/AbstractConnectProtocol.java | 14 ++-- .../jdbc/internal/util/DefaultOptions.java | 12 ++++ src/test/java/org/mariadb/jdbc/BaseTest.java | 14 ++-- .../java/org/mariadb/jdbc/ConnectionTest.java | 2 +- .../java/org/mariadb/jdbc/DataSourceTest.java | 30 ++++----- .../java/org/mariadb/jdbc/DriverTest.java | 9 +-- .../java/org/mariadb/jdbc/FetchSizeTest.java | 64 ------------------- .../mariadb/jdbc/PooledConnectionTest.java | 6 +- .../jdbc/failover/OldFailoverTest.java | 3 +- 10 files changed, 67 insertions(+), 114 deletions(-) diff --git a/src/main/java/org/mariadb/jdbc/MariaDbConnection.java b/src/main/java/org/mariadb/jdbc/MariaDbConnection.java index d7090ab84..828909c2e 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbConnection.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbConnection.java @@ -405,18 +405,21 @@ public PreparedStatement internalPrepareStatement(final String sql, final int re checkConnection(); boolean canUsePrepareStatement = false; - String cleanSql = sql.toUpperCase().trim(); - if (options.rewriteBatchedStatements || !options.useServerPrepStmts) { - //in case of CALL statement, handling INOUT parameter is better with Prepare protocol - canUsePrepareStatement = cleanSql.contains("CALL"); - } else if (options.useServerPrepStmts && sql != null) { - canUsePrepareStatement = (cleanSql.contains("SELECT") - || cleanSql.contains("CALL") - || cleanSql.contains("UPDATE") - || cleanSql.contains("INSERT") - || cleanSql.contains("DELETE") - || cleanSql.contains("REPLACE") - || cleanSql.contains("DO")); + + if (sql != null) { + String cleanSql = sql.toUpperCase().trim(); + if (!options.useServerPrepStmts) { + //in case of CALL statement, handling INOUT parameter is better with Prepare protocol + canUsePrepareStatement = cleanSql.contains("CALL"); + } else if (options.useServerPrepStmts) { + canUsePrepareStatement = (cleanSql.contains("SELECT") + || cleanSql.contains("CALL") + || cleanSql.contains("UPDATE") + || cleanSql.contains("INSERT") + || cleanSql.contains("DELETE") + || cleanSql.contains("REPLACE") + || cleanSql.contains("DO")); + } } if (canUsePrepareStatement) { diff --git a/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java b/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java index f9645f9cf..0a154cd9d 100644 --- a/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java +++ b/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java @@ -322,7 +322,11 @@ public void connect() throws QueryException { close(); } try { - connect(currentHost.host, currentHost.port); + if (currentHost != null) { + connect(currentHost.host, currentHost.port); + } else { + connect(null, 3306); + } return; } catch (IOException e) { throw new QueryException("Could not connect to " + currentHost + "." + e.getMessage(), -1, @@ -349,7 +353,7 @@ private void connect(String host, int port) throws QueryException, IOException { } if (!socket.isConnected()) { - InetSocketAddress sockAddr = new InetSocketAddress(host, port); + InetSocketAddress sockAddr = urlParser.getOptions().pipe == null ? new InetSocketAddress(host, port) : null; if (options.connectTimeout != null) { socket.connect(sockAddr, options.connectTimeout); } else { @@ -701,7 +705,7 @@ public UrlParser getUrlParser() { * @return is master flag */ public boolean isMasterConnection() { - return ParameterConstant.TYPE_MASTER.equals(currentHost.type); + return currentHost == null ? true : ParameterConstant.TYPE_MASTER.equals(currentHost.type); } public boolean mustBeMasterConnection() { @@ -785,7 +789,7 @@ public void setHostAddress(HostAddress host) { } public String getHost() { - return currentHost.host; + return (currentHost == null) ? null : currentHost.host; } public FailoverProxy getProxy() { @@ -797,7 +801,7 @@ public void setProxy(FailoverProxy proxy) { } public int getPort() { - return currentHost.port; + return (currentHost == null) ? 3306 : currentHost.port; } public String getDatabase() { diff --git a/src/main/java/org/mariadb/jdbc/internal/util/DefaultOptions.java b/src/main/java/org/mariadb/jdbc/internal/util/DefaultOptions.java index 05ff7c4b3..aca7dc009 100644 --- a/src/main/java/org/mariadb/jdbc/internal/util/DefaultOptions.java +++ b/src/main/java/org/mariadb/jdbc/internal/util/DefaultOptions.java @@ -588,6 +588,18 @@ private static Options parse(HaMode haMode, Properties properties, Options optio //only for jws, so never thrown throw new IllegalArgumentException("Security too restrictive : " + s.getMessage()); } + + //not compatible options + + //disable use server prepare id using client rewrite + if (options.rewriteBatchedStatements) { + options.useServerPrepStmts = false; + options.cachePrepStmts = false; + } + //pipe cannot use read and write socket simultaneously + if (options.pipe != null) options.useBatchMultiSend = false; + + return options; } diff --git a/src/test/java/org/mariadb/jdbc/BaseTest.java b/src/test/java/org/mariadb/jdbc/BaseTest.java index d4cb878a9..de4510cac 100644 --- a/src/test/java/org/mariadb/jdbc/BaseTest.java +++ b/src/test/java/org/mariadb/jdbc/BaseTest.java @@ -149,9 +149,13 @@ public static void beforeClassBaseTest() throws SQLException { testSingleHost = Boolean.parseBoolean(System.getProperty("testSingleHost", "true")); if (testSingleHost) { urlParser = UrlParser.parse(url); - - hostname = urlParser.getHostAddresses().get(0).host; - port = urlParser.getHostAddresses().get(0).port; + if (urlParser.getHostAddresses().size() > 0) { + hostname = urlParser.getHostAddresses().get(0).host; + port = urlParser.getHostAddresses().get(0).port; + } else { + hostname = null; + port = 3306; + } database = urlParser.getDatabase(); username = urlParser.getUsername(); password = urlParser.getPassword(); @@ -164,7 +168,7 @@ public static void beforeClassBaseTest() throws SQLException { private static void setUri() { - connU = "jdbc:mysql://" + hostname + ":" + port + "/" + database; + connU = "jdbc:mysql://" + ((hostname == null) ? "localhost" : hostname) + ":" + port + "/" + database; connUri = connU + "?user=" + username + (password != null && !"".equals(password) ? "&password=" + password : "") + (parameters != null ? parameters : ""); @@ -354,7 +358,7 @@ protected Connection setConnection(String parameters) throws SQLException { } protected Connection setConnection(String additionnallParameters, String database) throws SQLException { - String connU = "jdbc:mysql://" + hostname + ":" + port + "/" + database; + String connU = "jdbc:mysql://" + ((hostname == null) ? "localhost" : hostname) + ":" + port + "/" + database; String connUri = connU + "?user=" + username + (password != null && !"".equals(password) ? "&password=" + password : "") + (parameters != null ? parameters : ""); diff --git a/src/test/java/org/mariadb/jdbc/ConnectionTest.java b/src/test/java/org/mariadb/jdbc/ConnectionTest.java index aa6f6b377..6991cefce 100644 --- a/src/test/java/org/mariadb/jdbc/ConnectionTest.java +++ b/src/test/java/org/mariadb/jdbc/ConnectionTest.java @@ -33,7 +33,7 @@ public static void initClass() throws SQLException { @Test public void testAccessDeniedErrorCode() throws SQLException { try { - DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/" + database + "?user=foo"); + DriverManager.getConnection("jdbc:mysql://" + ((hostname != null) ? hostname : "localhost") + ":" + port + "/" + database + "?user=foo"); Assert.fail(); } catch (SQLException e) { if (1524 == e.getErrorCode()) { diff --git a/src/test/java/org/mariadb/jdbc/DataSourceTest.java b/src/test/java/org/mariadb/jdbc/DataSourceTest.java index ef40e2862..0e72eb566 100644 --- a/src/test/java/org/mariadb/jdbc/DataSourceTest.java +++ b/src/test/java/org/mariadb/jdbc/DataSourceTest.java @@ -27,7 +27,7 @@ public static void beforeClassDataSourceTest() { @Test public void testDataSource() throws SQLException { - MariaDbDataSource ds = new MariaDbDataSource(hostname, port, database); + MariaDbDataSource ds = new MariaDbDataSource(hostname == null ? "localhost" : hostname, port, database); Connection connection = ds.getConnection(username, password); try { assertEquals(connection.isValid(0), true); @@ -38,7 +38,7 @@ public void testDataSource() throws SQLException { @Test public void testDataSource2() throws SQLException { - MariaDbDataSource ds = new MariaDbDataSource(hostname, port, database); + MariaDbDataSource ds = new MariaDbDataSource(hostname == null ? "localhost" : hostname, port, database); Connection connection = ds.getConnection(username, password); try { assertEquals(connection.isValid(0), true); @@ -52,7 +52,7 @@ public void testDataSourceEmpty() throws SQLException { MariaDbDataSource ds = new MariaDbDataSource(); ds.setDatabaseName(database); ds.setPort(port); - ds.setServerName(hostname); + ds.setServerName(hostname == null ? "localhost" : hostname); Connection connection = ds.getConnection(username, password); try { assertEquals(connection.isValid(0), true); @@ -68,7 +68,7 @@ public void testDataSourceEmpty() throws SQLException { */ @Test public void setDatabaseNameTest() throws SQLException { - MariaDbDataSource ds = new MariaDbDataSource(hostname, port, database); + MariaDbDataSource ds = new MariaDbDataSource(hostname == null ? "localhost" : hostname, port, database); Connection connection = ds.getConnection(username, password); connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS test2"); ds.setDatabaseName("test2"); @@ -87,7 +87,7 @@ public void setDatabaseNameTest() throws SQLException { @Test public void setServerNameTest() throws SQLException { Assume.assumeTrue(connectToIP != null); - MariaDbDataSource ds = new MariaDbDataSource(hostname, port, database); + MariaDbDataSource ds = new MariaDbDataSource(hostname == null ? "localhost" : hostname, port, database); Connection connection = ds.getConnection(username, password); ds.setServerName(connectToIP); connection = ds.getConnection(username, password); @@ -103,7 +103,7 @@ public void setServerNameTest() throws SQLException { public void setPortTest() throws SQLException { - MariaDbDataSource ds = new MariaDbDataSource(hostname, port, database); + MariaDbDataSource ds = new MariaDbDataSource(hostname == null ? "localhost" : hostname, port, database); Connection connection2 = ds.getConnection(username, password); //delete blacklist, because can failover on 3306 is filled assureBlackList(connection2); @@ -127,25 +127,21 @@ public void setPortTest() throws SQLException { */ @Test public void setPropertiesTest() throws SQLException { - MariaDbDataSource ds = new MariaDbDataSource(hostname, port, database); + MariaDbDataSource ds = new MariaDbDataSource(hostname == null ? "localhost" : hostname, port, database); ds.setProperties("sessionVariables=sql_mode='PIPES_AS_CONCAT'"); - Connection connection = null; - try { - connection = ds.getConnection(username, password); + try (Connection connection = ds.getConnection(username, password)) { ResultSet rs = connection.createStatement().executeQuery("SELECT @@sql_mode"); if (rs.next()) { assertEquals("PIPES_AS_CONCAT", rs.getString(1)); ds.setUrl(connUri + "&sessionVariables=sql_mode='ALLOW_INVALID_DATES'"); - connection = ds.getConnection(); - rs = connection.createStatement().executeQuery("SELECT @@sql_mode"); - assertTrue(rs.next()); - assertEquals("ALLOW_INVALID_DATES", rs.getString(1)); - connection.close(); + try (Connection connection2 = ds.getConnection()) { + rs = connection2.createStatement().executeQuery("SELECT @@sql_mode"); + assertTrue(rs.next()); + assertEquals("ALLOW_INVALID_DATES", rs.getString(1)); + } } else { fail(); } - } finally { - connection.close(); } } diff --git a/src/test/java/org/mariadb/jdbc/DriverTest.java b/src/test/java/org/mariadb/jdbc/DriverTest.java index 545b42155..2e3b60d8b 100644 --- a/src/test/java/org/mariadb/jdbc/DriverTest.java +++ b/src/test/java/org/mariadb/jdbc/DriverTest.java @@ -392,12 +392,11 @@ public void testPreparedWithNull() throws SQLException { @Test public void connectFailover() throws SQLException { + Assume.assumeTrue(hostname != null); String hosts = hostname + ":" + port + "," + hostname + ":" + (port + 1); String url = "jdbc:mysql://" + hosts + "/" + database + "?user=" + username; url += (password != null && !"".equals(password) ? "&password=" + password : ""); - Connection connection = null; - try { - connection = openNewConnection(url); + try (Connection connection = openNewConnection(url)) { MariaDbConnection my = (MariaDbConnection) connection; assertTrue(my.getPort() == port); ResultSet rs = connection.createStatement().executeQuery("select 1"); @@ -406,8 +405,6 @@ public void connectFailover() throws SQLException { } else { fail(); } - } finally { - connection.close(); } } @@ -1098,7 +1095,7 @@ public void namedPipeWithoutHost() throws Exception { String namedPipeName = rs.getString(2); //skip test if no namedPipeName was obtained because then we do not use a socket connection Assume.assumeTrue(namedPipeName != null); - try (Connection connection = DriverManager.getConnection("jdbc:mariadb://localhost/testj?user=" + try (Connection connection = DriverManager.getConnection("jdbc:mariadb:///testj?user=" + username + "&pipe=" + namedPipeName)) { Statement stmt = connection.createStatement(); rs = stmt.executeQuery("SELECT 1"); diff --git a/src/test/java/org/mariadb/jdbc/FetchSizeTest.java b/src/test/java/org/mariadb/jdbc/FetchSizeTest.java index 6e3f26840..f53a72e21 100644 --- a/src/test/java/org/mariadb/jdbc/FetchSizeTest.java +++ b/src/test/java/org/mariadb/jdbc/FetchSizeTest.java @@ -100,70 +100,6 @@ public void fetchSizeErrorWhileFetchTest() throws SQLException { } } - @Test - public void fetchSizeSpeedTest() throws SQLException { - prepare100record("fetchSizeTest2"); - - Statement stmt = sharedConnection.createStatement(); - - //test limit - final long start = System.nanoTime(); - ResultSet resultSet = stmt.executeQuery("SELECT test FROM fetchSizeTest2 LIMIT 2"); - assertTrue(resultSet.next()); - assertEquals("0", resultSet.getString(1)); - assertTrue(resultSet.next()); - assertEquals("1", resultSet.getString(1)); - long resultTimeLimit2 = System.nanoTime() - start; - - stmt.setFetchSize(0); - //execute another query, so skipping result are not on next query - stmt.executeQuery("SELECT 1"); - long resultTimeLimit2WithSkip = System.nanoTime() - start; - System.out.println(resultTimeLimit2WithSkip + " / " + resultTimeLimit2); - - //test setMaxRows(2) - final long start2 = System.nanoTime(); - stmt.setMaxRows(2); - test2firstResult(stmt); - long resultTimeFetchMaxRow = System.nanoTime() - start2; - stmt.setMaxRows(0); - stmt.executeQuery("SELECT 1"); - long resultTimeFetchMaxRowWithSkip = System.nanoTime() - start2; - System.out.println(resultTimeFetchMaxRowWithSkip + " / " + resultTimeFetchMaxRow); - - //test fetch size 2 - stmt.setFetchSize(2); - final long start3 = System.nanoTime(); - test2firstResult(stmt); - long resultTimeFetch2 = System.nanoTime() - start3; - stmt.setFetchSize(0); - stmt.executeQuery("SELECT 1"); - long resultTimeFetch2WithSkip = System.nanoTime() - start3; - System.out.println(resultTimeFetch2WithSkip + " / " + resultTimeFetch2); - - //test fetch all - final long start4 = System.nanoTime(); - test2firstResult(stmt); - long resultTimeFetchAll = System.nanoTime() - start4; - stmt.executeQuery("SELECT 1"); - long resultTimeFetchAllWithSkip = System.nanoTime() - start4; - System.out.println(resultTimeFetchAllWithSkip + " / " + resultTimeFetchAll); - - //normally this is right, but since server is caching rows, that may not be always the case. -// assertTrue(resultTimeFetchMaxRowWithSkip > resultTimeLimit2WithSkip); -// assertTrue(resultTimeFetch2WithSkip > resultTimeFetchMaxRowWithSkip); -// assertTrue(resultTimeFetchAllWithSkip > resultTimeFetch2WithSkip); - - } - - private void test2firstResult(Statement statement) throws SQLException { - ResultSet resultSet = statement.executeQuery("SELECT test FROM fetchSizeTest2"); - assertTrue(resultSet.next()); - assertEquals("0", resultSet.getString(1)); - assertTrue(resultSet.next()); - assertEquals("1", resultSet.getString(1)); - - } private void prepare100record(String tableName) throws SQLException { PreparedStatement pstmt = sharedConnection.prepareStatement("INSERT INTO " + tableName + " (test) values (?)"); diff --git a/src/test/java/org/mariadb/jdbc/PooledConnectionTest.java b/src/test/java/org/mariadb/jdbc/PooledConnectionTest.java index 172f03500..86d0d042d 100644 --- a/src/test/java/org/mariadb/jdbc/PooledConnectionTest.java +++ b/src/test/java/org/mariadb/jdbc/PooledConnectionTest.java @@ -12,7 +12,7 @@ public class PooledConnectionTest extends BaseTest { @Test public void testPooledConnectionClosed() throws Exception { - ConnectionPoolDataSource ds = new MariaDbDataSource(hostname, port, database); + ConnectionPoolDataSource ds = new MariaDbDataSource(hostname != null ? hostname : "localhost", port, database); PooledConnection pc = ds.getPooledConnection(username, password); Connection connection = pc.getConnection(); MyEventListener listener = new MyEventListener(); @@ -36,7 +36,7 @@ public void testPooledConnectionClosed() throws Exception { @Test public void testPooledConnectionException() throws Exception { - ConnectionPoolDataSource ds = new MariaDbDataSource(hostname, port, database); + ConnectionPoolDataSource ds = new MariaDbDataSource(hostname != null ? hostname : "localhost", port, database); PooledConnection pc = ds.getPooledConnection(username, password); MyEventListener listener = new MyEventListener(); pc.addConnectionEventListener(listener); @@ -63,7 +63,7 @@ public void testPooledConnectionException() throws Exception { @Test public void testPooledConnectionStatementError() throws Exception { - ConnectionPoolDataSource ds = new MariaDbDataSource(hostname, port, database); + ConnectionPoolDataSource ds = new MariaDbDataSource(hostname != null ? hostname : "localhost", port, database); PooledConnection pc = ds.getPooledConnection(username, password); MyEventListener listener = new MyEventListener(); pc.addStatementEventListener(listener); diff --git a/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java b/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java index d8fac81a0..bda2d0c94 100644 --- a/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java +++ b/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java @@ -16,7 +16,8 @@ public class OldFailoverTest extends BaseTest { */ @Test public void isOldConfigurationValid() throws Exception { - String falseUrl = "jdbc:mysql://localhost:1111," + hostname + ":" + port + "/" + database + "?user=" + username + String falseUrl = "jdbc:mysql://localhost:1111," + ((hostname == null) ? "localhost" : hostname) + ":" + + port + "/" + database + "?user=" + username + (password != null && !"".equals(password) ? "&password=" + password : "") + (parameters != null ? parameters : ""); From d63d931c4dfe853a443af4b00245399f5dc940fc Mon Sep 17 00:00:00 2001 From: kolzeq Date: Tue, 30 Aug 2016 17:14:06 +0200 Subject: [PATCH 11/18] [misc] log error if enable --- .../jdbc/MariaDbClientPreparedStatement.java | 10 ++++++ .../jdbc/MariaDbServerPreparedStatement.java | 6 ++++ .../org/mariadb/jdbc/MariaDbStatement.java | 8 +++++ .../dao/parameters/ReaderParameter.java | 2 +- .../jdbc/internal/util/DefaultOptions.java | 1 - src/test/java/org/mariadb/jdbc/BaseTest.java | 32 +++++++++++++++++-- .../jdbc/failover/OldFailoverTest.java | 2 +- 7 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/mariadb/jdbc/MariaDbClientPreparedStatement.java b/src/main/java/org/mariadb/jdbc/MariaDbClientPreparedStatement.java index 00c110a8f..8630cc44d 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbClientPreparedStatement.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbClientPreparedStatement.java @@ -49,6 +49,8 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS OF SUCH DAMAGE. */ +import org.mariadb.jdbc.internal.logging.Logger; +import org.mariadb.jdbc.internal.logging.LoggerFactory; import org.mariadb.jdbc.internal.packet.dao.parameters.ParameterHolder; import org.mariadb.jdbc.internal.queryresults.*; import org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet; @@ -62,6 +64,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS public class MariaDbClientPreparedStatement extends AbstractMariaDbPrepareStatement implements Cloneable { + private static Logger logger = LoggerFactory.getLogger(MariaDbClientPreparedStatement.class); private String sqlQuery; private ClientPrepareResult prepareResult; private ParameterHolder[] parameters; @@ -206,6 +209,8 @@ protected boolean executeInternal() 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"); } @@ -251,6 +256,8 @@ public void addBatch() throws SQLException { for (int i = 0; i < holder.length; i++) { holder[i] = parameters[i]; if (holder[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"); } @@ -411,6 +418,9 @@ protected void setParameter(final int parameterIndex, final ParameterHolder hold if (parameterIndex >= 1 && parameterIndex < prepareResult.getParamCount() + 1) { parameters[parameterIndex - 1] = holder; } else { + logger.error("Could not set parameter at position " + parameterIndex + + " (values vas " + holder.toString() + ")"); + throw ExceptionMapper.getSqlException("Could not set parameter at position " + parameterIndex + " (values vas " + holder.toString() + ")"); } diff --git a/src/main/java/org/mariadb/jdbc/MariaDbServerPreparedStatement.java b/src/main/java/org/mariadb/jdbc/MariaDbServerPreparedStatement.java index 83a363fff..9c6c6c3e1 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbServerPreparedStatement.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbServerPreparedStatement.java @@ -48,6 +48,8 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS OF SUCH DAMAGE. */ +import org.mariadb.jdbc.internal.logging.Logger; +import org.mariadb.jdbc.internal.logging.LoggerFactory; import org.mariadb.jdbc.internal.packet.dao.parameters.ParameterHolder; import org.mariadb.jdbc.internal.queryresults.ExecutionResult; import org.mariadb.jdbc.internal.queryresults.MultiFixedIntExecutionResult; @@ -62,6 +64,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS import java.util.*; public class MariaDbServerPreparedStatement extends AbstractMariaDbPrepareStatement implements Cloneable { + private static Logger logger = LoggerFactory.getLogger(MariaDbServerPreparedStatement.class); String sql; ServerPrepareResult serverPrepareResult = null; @@ -125,6 +128,7 @@ private void prepare(String sql) throws SQLException { } catch (Exception ee) { //eat exception. } + logger.error("error preparing query", e); ExceptionMapper.throwException(e, connection, this); } } @@ -323,6 +327,7 @@ protected void validParameters() throws SQLException { if (serverPrepareResult != null) { for (int i = 0; i < parameterCount; i++) { if (currentParameterHolder.get(i) == null) { + logger.error("Parameter at position " + (i + 1) + " is not set"); ExceptionMapper.throwException(new QueryException("Parameter at position " + (i + 1) + " is not set", -1, "07004"), connection, this); } @@ -332,6 +337,7 @@ protected void validParameters() throws SQLException { for (int i = 0; i < parameterCount; i++) { if (!currentParameterHolder.containsKey(i)) { parameterCount = -1; + logger.error("Parameter at position " + (i + 1) + " is not set"); ExceptionMapper.throwException(new QueryException("Parameter at position " + (i + 1) + " is not set", -1, "07004"), connection, this); } diff --git a/src/main/java/org/mariadb/jdbc/MariaDbStatement.java b/src/main/java/org/mariadb/jdbc/MariaDbStatement.java index e4b896fe3..bbe6e9974 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbStatement.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbStatement.java @@ -49,6 +49,8 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS package org.mariadb.jdbc; +import org.mariadb.jdbc.internal.logging.Logger; +import org.mariadb.jdbc.internal.logging.LoggerFactory; import org.mariadb.jdbc.internal.protocol.Protocol; import org.mariadb.jdbc.internal.queryresults.*; import org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet; @@ -68,6 +70,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS public class MariaDbStatement implements Statement, Cloneable { + private static Logger logger = LoggerFactory.getLogger(MariaDbStatement.class); //timeout scheduler private static final ScheduledExecutorService timeoutScheduler = SchedulerServiceProviderHolder.getTimeoutScheduler(); @@ -218,6 +221,8 @@ protected void executeQueryEpilog(QueryException queryException) throws SQLExcep close(); } + logger.error("error executing query", queryException); + ExceptionMapper.throwException(queryException, connection, this); } @@ -649,6 +654,7 @@ public void cancel() throws SQLException { } protocol.cancelCurrentQuery(); } catch (QueryException e) { + logger.error("error cancelling query", e); ExceptionMapper.throwException(e, connection, this); } catch (IOException e) { // connection gone, query is definitely canceled @@ -842,6 +848,7 @@ protected void skipMoreResults() throws SQLException { warningsCleared = false; connection.reenableWarnings(); } catch (QueryException e) { + logger.debug("error skipMoreResults", e); ExceptionMapper.throwException(e, connection, this); } } @@ -904,6 +911,7 @@ public boolean getMoreResults(final int current) throws SQLException { return false; } } catch (QueryException queryException) { + logger.debug("error retrieving more results ", queryException); ExceptionMapper.throwException(queryException, connection, this); return false; } finally { diff --git a/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/ReaderParameter.java b/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/ReaderParameter.java index 5edc38815..6006a06ff 100644 --- a/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/ReaderParameter.java +++ b/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/ReaderParameter.java @@ -149,7 +149,7 @@ public String toString() { } byte[] bytes = baos.toByteArray(); if (bytes.length < 1024) { - return ""; + return ""; } else { // cut overlong strings. return ""; diff --git a/src/main/java/org/mariadb/jdbc/internal/util/DefaultOptions.java b/src/main/java/org/mariadb/jdbc/internal/util/DefaultOptions.java index aca7dc009..b0bf14c80 100644 --- a/src/main/java/org/mariadb/jdbc/internal/util/DefaultOptions.java +++ b/src/main/java/org/mariadb/jdbc/internal/util/DefaultOptions.java @@ -376,7 +376,6 @@ public enum DefaultOptions { * Enable log information. require Slf4j version > 1.4 dependency. * log informations : * - info : query log - * - * default to false. */ LOGGING("log", Boolean.FALSE, "1.5.0"), diff --git a/src/test/java/org/mariadb/jdbc/BaseTest.java b/src/test/java/org/mariadb/jdbc/BaseTest.java index de4510cac..18b559889 100644 --- a/src/test/java/org/mariadb/jdbc/BaseTest.java +++ b/src/test/java/org/mariadb/jdbc/BaseTest.java @@ -16,6 +16,8 @@ import java.net.UnknownHostException; import java.sql.*; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Base util class. @@ -159,6 +161,32 @@ public static void beforeClassBaseTest() throws SQLException { database = urlParser.getDatabase(); username = urlParser.getUsername(); password = urlParser.getPassword(); + int separator = url.indexOf("//"); + String urlSecondPart = url.substring(separator + 2); + int dbIndex = urlSecondPart.indexOf("/"); + int paramIndex = urlSecondPart.indexOf("?"); + + String additionalParameters; + if ((dbIndex < paramIndex && dbIndex < 0) || (dbIndex > paramIndex && paramIndex > -1)) { + additionalParameters = urlSecondPart.substring(paramIndex); + } else if ((dbIndex < paramIndex && dbIndex > -1) || (dbIndex > paramIndex && paramIndex < 0)) { + additionalParameters = urlSecondPart.substring(dbIndex); + } else { + additionalParameters = null; + } + if (additionalParameters != null) { + String regex = "(\\/[^\\?]*)(\\?.+)*|(\\?[^\\/]*)(\\/.+)*"; + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(additionalParameters); + if (matcher.find()) { + String options1 = (matcher.group(2) != null) ? matcher.group(2).substring(1) : ""; + String options2 = (matcher.group(3) != null) ? matcher.group(3).substring(1) : ""; + parameters = (!options1.equals("")) ? options1 : options2; + } + } else { + parameters = null; + } + setUri(); @@ -171,7 +199,7 @@ private static void setUri() { connU = "jdbc:mysql://" + ((hostname == null) ? "localhost" : hostname) + ":" + port + "/" + database; connUri = connU + "?user=" + username + (password != null && !"".equals(password) ? "&password=" + password : "") - + (parameters != null ? parameters : ""); + + (parameters != null ? "&" + parameters : ""); } /** @@ -361,7 +389,7 @@ protected Connection setConnection(String additionnallParameters, String databas String connU = "jdbc:mysql://" + ((hostname == null) ? "localhost" : hostname) + ":" + port + "/" + database; String connUri = connU + "?user=" + username + (password != null && !"".equals(password) ? "&password=" + password : "") - + (parameters != null ? parameters : ""); + + (parameters != null ? "&" + parameters : ""); return openConnection(connUri + additionnallParameters, null); } diff --git a/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java b/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java index bda2d0c94..da44579f7 100644 --- a/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java +++ b/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java @@ -19,7 +19,7 @@ public void isOldConfigurationValid() throws Exception { String falseUrl = "jdbc:mysql://localhost:1111," + ((hostname == null) ? "localhost" : hostname) + ":" + port + "/" + database + "?user=" + username + (password != null && !"".equals(password) ? "&password=" + password : "") - + (parameters != null ? parameters : ""); + + (parameters != null ? "&" + parameters : ""); try { //the first host doesn't exist, so with the random host selection, verifying that we connect to the good From a9c7b52f94ae2749a806fe283829fdb5c7f5203f Mon Sep 17 00:00:00 2001 From: kolzeq Date: Tue, 30 Aug 2016 17:59:59 +0200 Subject: [PATCH 12/18] [misc] remove logs from tests + test correction when activate logs --- src/test/java/org/mariadb/jdbc/BaseTest.java | 5 +++-- .../java/org/mariadb/jdbc/ServerPrepareStatementTest.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/mariadb/jdbc/BaseTest.java b/src/test/java/org/mariadb/jdbc/BaseTest.java index 18b559889..3935fba68 100644 --- a/src/test/java/org/mariadb/jdbc/BaseTest.java +++ b/src/test/java/org/mariadb/jdbc/BaseTest.java @@ -26,7 +26,7 @@ */ @Ignore public class BaseTest { - protected static final String mDefUrl = "jdbc:mysql://localhost:3306/testj?user=root&profileSql=true"; + protected static final String mDefUrl = "jdbc:mysql://localhost:3306/testj?user=root"; protected static String connU; protected static String connUri; protected static String hostname; @@ -332,7 +332,8 @@ protected Protocol getProtocolFromConnection(Connection conn) throws Throwable { Method getProtocol = MariaDbConnection.class.getDeclaredMethod("getProtocol", new Class[0]); getProtocol.setAccessible(true); - return (Protocol) getProtocol.invoke(conn); + Object obj = getProtocol.invoke(conn); + return (Protocol) obj; } protected void setHostname(String hostname) throws SQLException { diff --git a/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java b/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java index ec7e2ce8d..05c55bf8d 100644 --- a/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java +++ b/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java @@ -820,7 +820,7 @@ public void run() { public void testPrepareStatementCache() throws Throwable { //tester le cache prepareStatement try (Connection connection = setConnection()) { - MasterProtocol protocol = (MasterProtocol) getProtocolFromConnection(connection); + Protocol protocol = getProtocolFromConnection(connection); createTable("test_cache_table1", "id1 int auto_increment primary key, text1 varchar(20), text2 varchar(20)"); PreparedStatement[] map = new PreparedStatement[280]; for (int i = 0; i < 280; i++) { From 5c3a3103d6dd9b6c111a4d11e2048d8f2e51bb9f Mon Sep 17 00:00:00 2001 From: kolzeq Date: Tue, 30 Aug 2016 21:46:03 +0200 Subject: [PATCH 13/18] [misc] correction UTF-8 conversion last character + calendar default instance when using text protocol --- src/main/java/org/mariadb/jdbc/MariaDbStatement.java | 3 ++- .../internal/failover/AbstractMastersListener.java | 4 ++++ .../jdbc/internal/failover/FailoverProxy.java | 1 - .../packet/dao/parameters/StringParameter.java | 6 +++--- .../packet/dao/parameters/TimestampParameter.java | 5 ++++- .../queryresults/resultset/MariaSelectResultSet.java | 12 ++++-------- .../jdbc/internal/stream/PacketOutputStream.java | 2 +- src/test/java/org/mariadb/jdbc/BufferTest.java | 2 +- .../java/org/mariadb/jdbc/DataTypeUnsignedTest.java | 2 +- src/test/java/org/mariadb/jdbc/DateTest.java | 1 + src/test/java/org/mariadb/jdbc/MultiTest.java | 2 +- .../org/mariadb/jdbc/ServerPrepareStatementTest.java | 8 +++++++- .../mariadb/jdbc/TimezoneDaylightSavingTimeTest.java | 7 ++++--- .../java/org/mariadb/jdbc/TruncateExceptionTest.java | 12 +++++++----- src/test/java/org/mariadb/jdbc/UnicodeTest.java | 2 +- 15 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/mariadb/jdbc/MariaDbStatement.java b/src/main/java/org/mariadb/jdbc/MariaDbStatement.java index bbe6e9974..6257faa37 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbStatement.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbStatement.java @@ -745,7 +745,8 @@ public ResultSet getGeneratedKeys() throws SQLException { for (int i = 0; i < affectedRowslength; i++) { size += multiExecution.getAffectedRows()[i]; } - data = new long[size]; + + data = new long[(size < 0) ? 0 : size]; for (int affectedRows = 0; affectedRows < affectedRowslength; affectedRows++) { for (int i = 0; i < multiExecution.getAffectedRows()[affectedRows]; i++) { data[i] = multiExecution.getInsertIds()[affectedRows] + i * autoIncrementIncrement; diff --git a/src/main/java/org/mariadb/jdbc/internal/failover/AbstractMastersListener.java b/src/main/java/org/mariadb/jdbc/internal/failover/AbstractMastersListener.java index b012f30e5..04da72259 100644 --- a/src/main/java/org/mariadb/jdbc/internal/failover/AbstractMastersListener.java +++ b/src/main/java/org/mariadb/jdbc/internal/failover/AbstractMastersListener.java @@ -279,6 +279,8 @@ public HandleErrorResult relaunchOperation(Method method, Object[] args) throws String query = ((String) args[2]).toUpperCase(); if (!query.equals("ALTER SYSTEM CRASH") && !query.startsWith("KILL")) { + logger.debug("relaunch query to new connection " + + ((currentProtocol != null) ? "server thread id " + currentProtocol.getServerThreadId() : "")); handleErrorResult.resultObject = method.invoke(currentProtocol, args); handleErrorResult.mustThrowError = false; } @@ -292,6 +294,8 @@ public HandleErrorResult relaunchOperation(Method method, Object[] args) throws ServerPrepareResult oldServerPrepareResult = (ServerPrepareResult) args[1]; ServerPrepareResult serverPrepareResult = currentProtocol.prepare(oldServerPrepareResult.getSql(), mustBeOnMaster); oldServerPrepareResult.failover(serverPrepareResult.getStatementId(), currentProtocol); + logger.debug("relaunch query to new connection " + + ((currentProtocol != null) ? "server thread id " + currentProtocol.getServerThreadId() : "")); handleErrorResult.resultObject = method.invoke(currentProtocol, args); handleErrorResult.mustThrowError = false; } catch (Exception e) { diff --git a/src/main/java/org/mariadb/jdbc/internal/failover/FailoverProxy.java b/src/main/java/org/mariadb/jdbc/internal/failover/FailoverProxy.java index b987e8582..6206b6f84 100644 --- a/src/main/java/org/mariadb/jdbc/internal/failover/FailoverProxy.java +++ b/src/main/java/org/mariadb/jdbc/internal/failover/FailoverProxy.java @@ -50,7 +50,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS package org.mariadb.jdbc.internal.failover; import org.mariadb.jdbc.HostAddress; -import org.mariadb.jdbc.internal.MariaDbType; import org.mariadb.jdbc.internal.logging.Logger; import org.mariadb.jdbc.internal.logging.LoggerFactory; import org.mariadb.jdbc.internal.protocol.Protocol; diff --git a/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/StringParameter.java b/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/StringParameter.java index 7059cd9a9..d83432db3 100644 --- a/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/StringParameter.java +++ b/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/StringParameter.java @@ -178,12 +178,12 @@ private void escapeUtf8() { //Handle fast conversion without testing kind of escape for each character if (noBackslashEscapes) { - while (position < charsLength && chars[charsOffset] < 0x80) { + while (charsOffset < charsLength && chars[charsOffset] < 0x80) { if (chars[charsOffset] == '\'') escapedArray[position++] = (byte) '\''; //add a single escape quote escapedArray[position++] = (byte) chars[charsOffset++]; } } else { - while (position < charsLength && chars[charsOffset] < 0x80) { + while (charsOffset < charsLength && chars[charsOffset] < 0x80) { if (chars[charsOffset] == '\'' || chars[charsOffset] == '\\' || chars[charsOffset] == '"' @@ -209,7 +209,7 @@ private void escapeUtf8() { //reserved for surrogate - see https://en.wikipedia.org/wiki/UTF-16 if (currChar >= 0xD800 && currChar < 0xDC00) { //is high surrogate - if (charsOffset + 1 >= charsLength) { + if (charsOffset + 1 > charsLength) { escapedArray[position++] = (byte)0x63; break; } diff --git a/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimestampParameter.java b/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimestampParameter.java index 1107b97ba..47bed111e 100644 --- a/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimestampParameter.java +++ b/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimestampParameter.java @@ -105,7 +105,10 @@ public void writeUnsafeTo(final PacketOutputStream os) { private byte[] dateToByte() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - if (calendar != null) { + + if (options.useLegacyDatetimeCode) { + sdf.setCalendar(Calendar.getInstance()); + } else if (calendar != null) { sdf.setCalendar(calendar); } return sdf.format(ts).getBytes(); diff --git a/src/main/java/org/mariadb/jdbc/internal/queryresults/resultset/MariaSelectResultSet.java b/src/main/java/org/mariadb/jdbc/internal/queryresults/resultset/MariaSelectResultSet.java index 9db272844..2de566684 100644 --- a/src/main/java/org/mariadb/jdbc/internal/queryresults/resultset/MariaSelectResultSet.java +++ b/src/main/java/org/mariadb/jdbc/internal/queryresults/resultset/MariaSelectResultSet.java @@ -1623,10 +1623,9 @@ private Timestamp getTimestamp(byte[] rawBytes, ColumnInformation columnInfo, Ca } int nanoseconds = extractNanos(rawValue); Timestamp timestamp; - Calendar calendar = cal; - if (options.useLegacyDatetimeCode) { - calendar = Calendar.getInstance(); - } + + Calendar calendar = options.useLegacyDatetimeCode ? Calendar.getInstance() : cal; + synchronized (calendar) { calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); @@ -3480,10 +3479,7 @@ private Timestamp binaryTimestamp(byte[] rawBytes, ColumnInformation columnInfo, } } - Calendar calendar = Calendar.getInstance(); - if (!options.useLegacyDatetimeCode) { - calendar = cal; - } + Calendar calendar = options.useLegacyDatetimeCode ? Calendar.getInstance() : cal; Timestamp tt; synchronized (calendar) { calendar.set(year, month - 1, day, hour, minutes, seconds); diff --git a/src/main/java/org/mariadb/jdbc/internal/stream/PacketOutputStream.java b/src/main/java/org/mariadb/jdbc/internal/stream/PacketOutputStream.java index 0e853c8c8..ea1484c3f 100644 --- a/src/main/java/org/mariadb/jdbc/internal/stream/PacketOutputStream.java +++ b/src/main/java/org/mariadb/jdbc/internal/stream/PacketOutputStream.java @@ -874,7 +874,7 @@ public void send(String sql, byte commandType) throws IOException, QueryExceptio //reserved for surrogate - see https://en.wikipedia.org/wiki/UTF-16 if (currChar >= 0xD800 && currChar < 0xDC00) { //is high surrogate - if (charsPosition + 1 >= charsLength) { + if (charsPosition + 1 > charsLength) { packetBuffer[position++] = (byte)0x63; break; } diff --git a/src/test/java/org/mariadb/jdbc/BufferTest.java b/src/test/java/org/mariadb/jdbc/BufferTest.java index 363ffea4a..883e6970e 100644 --- a/src/test/java/org/mariadb/jdbc/BufferTest.java +++ b/src/test/java/org/mariadb/jdbc/BufferTest.java @@ -33,7 +33,7 @@ public static void initClass() throws SQLException { array20m[i] = (char) (0x30 + (i % 10)); } array40m = new char[40000000]; - for (int i = 0; i < array8m.length; i++) { + for (int i = 0; i < array40m.length; i++) { array40m[i] = (char) (0x30 + (i % 10)); } } diff --git a/src/test/java/org/mariadb/jdbc/DataTypeUnsignedTest.java b/src/test/java/org/mariadb/jdbc/DataTypeUnsignedTest.java index eacf602ed..0ee08dc86 100644 --- a/src/test/java/org/mariadb/jdbc/DataTypeUnsignedTest.java +++ b/src/test/java/org/mariadb/jdbc/DataTypeUnsignedTest.java @@ -185,7 +185,7 @@ public void yearTest() throws SQLException { } try (ResultSet rs = DatatypeTest.getResultSet("select * from yearTest", true, connection)) { - yearTestResult(rs, true); + yearTestResult(rs, sharedOptions().useServerPrepStmts ? true : false); } } } diff --git a/src/test/java/org/mariadb/jdbc/DateTest.java b/src/test/java/org/mariadb/jdbc/DateTest.java index da8e2806e..8fd0f8bf7 100644 --- a/src/test/java/org/mariadb/jdbc/DateTest.java +++ b/src/test/java/org/mariadb/jdbc/DateTest.java @@ -52,6 +52,7 @@ public void dateTestWithoutLegacy() throws SQLException { * @throws SQLException exception */ public void dateTest(boolean useLegacy) throws SQLException { + Assume.assumeFalse(sharedIsRewrite()); Connection connection = null; try { connection = setConnection("&useLegacyDatetimeCode=" + useLegacy diff --git a/src/test/java/org/mariadb/jdbc/MultiTest.java b/src/test/java/org/mariadb/jdbc/MultiTest.java index 5c274665f..4501e1477 100644 --- a/src/test/java/org/mariadb/jdbc/MultiTest.java +++ b/src/test/java/org/mariadb/jdbc/MultiTest.java @@ -844,7 +844,7 @@ public void continueOnBatchError() throws SQLException { private void continueOnBatchError(boolean continueBatch, int waitedResult, int waitedResultComMulti, boolean server, boolean rewrite) throws SQLException { - try (Connection connection = setConnection( + try (Connection connection = setBlankConnection( "&useServerPrepStmts=" + server + "&useComMulti=" + server + "&continueBatchOnError=" + continueBatch diff --git a/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java b/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java index 05c55bf8d..de870f035 100644 --- a/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java +++ b/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java @@ -52,6 +52,7 @@ public void testServerPrepareMeta() throws Throwable { @Test public void serverExecutionTest() throws SQLException { + Assume.assumeTrue(sharedOptions().useServerPrepStmts); Connection connection = null; try { connection = setConnection(); @@ -78,6 +79,8 @@ public void serverExecutionTest() throws SQLException { @Test public void deferredPrepareTest() throws Throwable { Assume.assumeTrue(sharedBulkCapacity()); + Assume.assumeTrue(sharedOptions().useServerPrepStmts); + Connection connection = null; try { connection = setConnection(); @@ -135,6 +138,7 @@ public void serverCacheStatementTest() throws Throwable { @Test public void prepStmtCacheSizeTest() throws Throwable { + Assume.assumeTrue(!sharedIsRewrite()); Connection connection = null; try { connection = setConnection("&prepStmtCacheSize=10"); @@ -492,8 +496,8 @@ private void assertYear(ResultSet rs, int fieldNumber, int comparaison) throws S @Test public void checkReusability() throws Throwable { + Assume.assumeTrue(!sharedIsRewrite()); setConnection("&prepStmtCacheSize=10"); - ExecutorService exec = Executors.newFixedThreadPool(2); //check blacklist shared @@ -811,6 +815,7 @@ public void run() { protocol.prepareStatementCache().get(sql); } } catch (Throwable e) { + e.printStackTrace(); fail(); } } @@ -818,6 +823,7 @@ public void run() { @Test public void testPrepareStatementCache() throws Throwable { + Assume.assumeTrue(!sharedIsRewrite()); //tester le cache prepareStatement try (Connection connection = setConnection()) { Protocol protocol = getProtocolFromConnection(connection); diff --git a/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java b/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java index fa248511d..4b00e64ef 100644 --- a/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java +++ b/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java @@ -158,6 +158,7 @@ public void testTimeStamp() throws SQLException { @Test public void testTimeStampUtc() throws SQLException { + TimeZone.setDefault(parisTimeZone); Connection connection = null; try { @@ -389,8 +390,7 @@ public void testDayLight() throws SQLException { private void testDayLight(boolean legacy) throws SQLException { - - Assume.assumeTrue(hasSuperPrivilege("testDayLight")); + Assume.assumeTrue(hasSuperPrivilege("testDayLight") && !sharedIsRewrite()); TimeZone.setDefault(parisTimeZone); Connection connection = null; try { @@ -502,7 +502,7 @@ private void checkResult(boolean binaryProtocol, Connection connection) throws S @Test public void testDayLightnotUtC() throws SQLException { - Assume.assumeTrue(hasSuperPrivilege("testDayLight")); + Assume.assumeTrue(hasSuperPrivilege("testDayLight") && !sharedIsRewrite()); TimeZone.setDefault(canadaTimeZone); Connection connection = null; try { @@ -572,6 +572,7 @@ public void testDayLightnotUtC() throws SQLException { @Test public void testDayLightWithClientTimeZoneDifferent() throws SQLException { + Assume.assumeTrue(!sharedIsRewrite()); TimeZone.setDefault(parisTimeZone); Connection connection = null; try { diff --git a/src/test/java/org/mariadb/jdbc/TruncateExceptionTest.java b/src/test/java/org/mariadb/jdbc/TruncateExceptionTest.java index f814d9c31..643f55f23 100644 --- a/src/test/java/org/mariadb/jdbc/TruncateExceptionTest.java +++ b/src/test/java/org/mariadb/jdbc/TruncateExceptionTest.java @@ -6,9 +6,7 @@ import java.sql.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; public class TruncateExceptionTest extends BaseTest { /** @@ -82,8 +80,12 @@ public void queryTruncationFetch() throws SQLException { } //resultset must have been fetch ResultSet rs = pstmt.getGeneratedKeys(); - rs.next(); - System.out.println(rs.getInt(1)); + if (sharedIsRewrite()) { + assertFalse(rs.next()); + } else { + assertTrue(rs.next()); + System.out.println(rs.getInt(1)); + } } } } diff --git a/src/test/java/org/mariadb/jdbc/UnicodeTest.java b/src/test/java/org/mariadb/jdbc/UnicodeTest.java index b1c941534..3b7984750 100644 --- a/src/test/java/org/mariadb/jdbc/UnicodeTest.java +++ b/src/test/java/org/mariadb/jdbc/UnicodeTest.java @@ -77,7 +77,7 @@ public void unicodeTests() throws SQLException { } //test prepare text protocol - try (Connection connection = setConnection("&allowMultiQueries=true")) { + try (Connection connection = setConnection("&rewriteBatchedStatements=true")) { connection.createStatement().execute("SET NAMES utf8mb4"); checkSendAndRetrieve(connection, unicodeString); } From d406ff4390df69b17cecd6840afffb8ce4d82f76 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Tue, 30 Aug 2016 21:51:19 +0200 Subject: [PATCH 14/18] [misc] missing commit file --- src/test/java/org/mariadb/jdbc/BaseTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/org/mariadb/jdbc/BaseTest.java b/src/test/java/org/mariadb/jdbc/BaseTest.java index 3935fba68..ec59cc432 100644 --- a/src/test/java/org/mariadb/jdbc/BaseTest.java +++ b/src/test/java/org/mariadb/jdbc/BaseTest.java @@ -386,6 +386,14 @@ protected Connection setConnection(String parameters) throws SQLException { return openConnection(connUri + parameters, null); } + protected Connection setBlankConnection(String parameters) throws SQLException { + return openConnection(connU + + "?user=" + username + + (password != null && !"".equals(password) ? "&password=" + password : "") + + parameters, null); + } + + protected Connection setConnection(String additionnallParameters, String database) throws SQLException { String connU = "jdbc:mysql://" + ((hostname == null) ? "localhost" : hostname) + ":" + port + "/" + database; String connUri = connU + "?user=" + username From b5dbc8f8ed938e6371c2c4bed6a83a47447d4429 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Tue, 30 Aug 2016 23:05:19 +0200 Subject: [PATCH 15/18] [misc] missing commit file --- .../internal/packet/dao/parameters/TimeParameter.java | 2 +- .../packet/dao/parameters/TimestampParameter.java | 4 +--- .../mariadb/jdbc/TimezoneDaylightSavingTimeTest.java | 10 +++++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimeParameter.java b/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimeParameter.java index eb47f7b4a..f81723655 100644 --- a/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimeParameter.java +++ b/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimeParameter.java @@ -102,7 +102,7 @@ public void writeUnsafeTo(final PacketOutputStream os) { private byte[] dateToBytes() { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); - if (calendar != null) sdf.setCalendar(calendar); + sdf.setCalendar(Calendar.getInstance()); String dateString = sdf.format(time); if (time.getTime() < 0) { dateString = "-" + dateString; diff --git a/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimestampParameter.java b/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimestampParameter.java index 47bed111e..92dad1047 100644 --- a/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimestampParameter.java +++ b/src/main/java/org/mariadb/jdbc/internal/packet/dao/parameters/TimestampParameter.java @@ -122,9 +122,7 @@ public long getApproximateTextProtocolLength() throws IOException { * @param writeBuffer buffer to write */ public void writeBinary(final PacketOutputStream writeBuffer) { - if (options.useLegacyDatetimeCode) { - calendar = Calendar.getInstance(); - } + if (options.useLegacyDatetimeCode) calendar = Calendar.getInstance(); calendar.setTimeInMillis(ts.getTime()); writeBuffer.writeTimestampLength(calendar, ts, fractionalSeconds); } diff --git a/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java b/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java index 4b00e64ef..b6a041dee 100644 --- a/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java +++ b/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java @@ -79,6 +79,8 @@ public static void initClass() throws SQLException { utcDateFormatSimple.setTimeZone(utcTimeZone); createTable("timeZoneTime", "id int, tt TIME(6)"); createTable("daylightMysql", " tt DATE"); + createTable("ttimeTest", "id int not null primary key auto_increment, dd TIME(3), dd2 TIME(3)"); + } } @@ -282,10 +284,12 @@ public void testTimeUtc() throws SQLException { Time timeParis2 = Time.valueOf("01:45:23"); timeParis2.setTime(timeParis2.getTime() + 123); + PreparedStatement st1 = connection.prepareStatement("INSERT INTO ttimeTest (dd, dd2) values (?, ?)"); + st1.setTime(1, timeParis); + st1.setTime(2, timeParis2); + st1.execute(); - PreparedStatement st = connection.prepareStatement("SELECT ?, ?"); - st.setTime(1, timeParis); - st.setTime(2, timeParis2); + PreparedStatement st = connection.prepareStatement("SELECT dd, dd2 from ttimeTest"); ResultSet rs = st.executeQuery(); rs.next(); assertEquals(rs.getTime(1).getTime(), timeParis.getTime()); From 9752c36e0d9e4d50808c25ef10d2f436e29c8572 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Tue, 30 Aug 2016 23:28:06 +0200 Subject: [PATCH 16/18] [misc] correcting PREPARE cache test when not using useServerPrepStmts option --- .../java/org/mariadb/jdbc/ServerPrepareStatementTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java b/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java index de870f035..81d5637ea 100644 --- a/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java +++ b/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java @@ -138,7 +138,7 @@ public void serverCacheStatementTest() throws Throwable { @Test public void prepStmtCacheSizeTest() throws Throwable { - Assume.assumeTrue(!sharedIsRewrite()); + Assume.assumeTrue(sharedOptions().useServerPrepStmts); Connection connection = null; try { connection = setConnection("&prepStmtCacheSize=10"); @@ -823,7 +823,8 @@ public void run() { @Test public void testPrepareStatementCache() throws Throwable { - Assume.assumeTrue(!sharedIsRewrite()); + Assume.assumeTrue(sharedOptions().useServerPrepStmts); + //tester le cache prepareStatement try (Connection connection = setConnection()) { Protocol protocol = getProtocolFromConnection(connection); From 4c5a1432fe1db2a95543650ad2148a0a41aea943 Mon Sep 17 00:00:00 2001 From: kolzeq Date: Wed, 31 Aug 2016 00:29:01 +0200 Subject: [PATCH 17/18] [misc] checktyle correction --- .../failover/AbstractMastersListener.java | 8 +++---- src/test/java/org/mariadb/jdbc/BaseTest.java | 14 ++++++------ .../org/mariadb/jdbc/ErrorMessageTest.java | 22 +++++++------------ 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/mariadb/jdbc/internal/failover/AbstractMastersListener.java b/src/main/java/org/mariadb/jdbc/internal/failover/AbstractMastersListener.java index 04da72259..3fa84ecd0 100644 --- a/src/main/java/org/mariadb/jdbc/internal/failover/AbstractMastersListener.java +++ b/src/main/java/org/mariadb/jdbc/internal/failover/AbstractMastersListener.java @@ -279,8 +279,8 @@ public HandleErrorResult relaunchOperation(Method method, Object[] args) throws String query = ((String) args[2]).toUpperCase(); if (!query.equals("ALTER SYSTEM CRASH") && !query.startsWith("KILL")) { - logger.debug("relaunch query to new connection " + - ((currentProtocol != null) ? "server thread id " + currentProtocol.getServerThreadId() : "")); + logger.debug("relaunch query to new connection " + + ((currentProtocol != null) ? "server thread id " + currentProtocol.getServerThreadId() : "")); handleErrorResult.resultObject = method.invoke(currentProtocol, args); handleErrorResult.mustThrowError = false; } @@ -294,8 +294,8 @@ public HandleErrorResult relaunchOperation(Method method, Object[] args) throws ServerPrepareResult oldServerPrepareResult = (ServerPrepareResult) args[1]; ServerPrepareResult serverPrepareResult = currentProtocol.prepare(oldServerPrepareResult.getSql(), mustBeOnMaster); oldServerPrepareResult.failover(serverPrepareResult.getStatementId(), currentProtocol); - logger.debug("relaunch query to new connection " + - ((currentProtocol != null) ? "server thread id " + currentProtocol.getServerThreadId() : "")); + logger.debug("relaunch query to new connection " + + ((currentProtocol != null) ? "server thread id " + currentProtocol.getServerThreadId() : "")); handleErrorResult.resultObject = method.invoke(currentProtocol, args); handleErrorResult.mustThrowError = false; } catch (Exception e) { diff --git a/src/test/java/org/mariadb/jdbc/BaseTest.java b/src/test/java/org/mariadb/jdbc/BaseTest.java index ec59cc432..6f06c2485 100644 --- a/src/test/java/org/mariadb/jdbc/BaseTest.java +++ b/src/test/java/org/mariadb/jdbc/BaseTest.java @@ -366,6 +366,13 @@ protected void setPassword(String password) throws SQLException { setConnection(); } + protected Connection setBlankConnection(String parameters) throws SQLException { + return openConnection(connU + + "?user=" + username + + (password != null && !"".equals(password) ? "&password=" + password : "") + + parameters, null); + } + protected Connection setConnection() throws SQLException { return openConnection(connUri, null); } @@ -386,13 +393,6 @@ protected Connection setConnection(String parameters) throws SQLException { return openConnection(connUri + parameters, null); } - protected Connection setBlankConnection(String parameters) throws SQLException { - return openConnection(connU - + "?user=" + username - + (password != null && !"".equals(password) ? "&password=" + password : "") - + parameters, null); - } - protected Connection setConnection(String additionnallParameters, String database) throws SQLException { String connU = "jdbc:mysql://" + ((hostname == null) ? "localhost" : hostname) + ":" + port + "/" + database; diff --git a/src/test/java/org/mariadb/jdbc/ErrorMessageTest.java b/src/test/java/org/mariadb/jdbc/ErrorMessageTest.java index 8558270ac..c289026cd 100644 --- a/src/test/java/org/mariadb/jdbc/ErrorMessageTest.java +++ b/src/test/java/org/mariadb/jdbc/ErrorMessageTest.java @@ -24,7 +24,7 @@ public static void initClass() throws SQLException { @Test public void testSmallRewriteErrorMessage() throws SQLException { - try (Connection connection = setConnection("&rewriteBatchedStatements=true")) { + try (Connection connection = setBlankConnection("&rewriteBatchedStatements=true")) { executeBatchWithException(connection); fail("Must Have thrown error"); } catch (SQLException sqle) { @@ -36,8 +36,7 @@ public void testSmallRewriteErrorMessage() throws SQLException { @Test public void testSmallMultiBatchErrorMessage() throws SQLException { - Assume.assumeFalse(sharedIsRewrite()); - try (Connection connection = setConnection("&allowMultiQueries=true&useServerPrepStmts=false")) { + try (Connection connection = setBlankConnection("&allowMultiQueries=true&useServerPrepStmts=false")) { executeBatchWithException(connection); fail("Must Have thrown error"); } catch (SQLException sqle) { @@ -48,8 +47,7 @@ public void testSmallMultiBatchErrorMessage() throws SQLException { @Test public void testSmallPrepareErrorMessage() throws SQLException { - Assume.assumeTrue(sharedUsePrepare()); - try (Connection connection = setConnection("&useBatchMultiSend=false")) { + try (Connection connection = setBlankConnection("&useBatchMultiSend=false")) { executeBatchWithException(connection); fail("Must Have thrown error"); } catch (SQLException sqle) { @@ -60,8 +58,7 @@ public void testSmallPrepareErrorMessage() throws SQLException { @Test public void testSmallBulkErrorMessage() throws SQLException { - Assume.assumeTrue(sharedUsePrepare()); - Connection connection = setConnection("&useBatchMultiSend=true"); + Connection connection = setBlankConnection("&useBatchMultiSend=true"); try { executeBatchWithException(connection); fail("Must Have thrown error"); @@ -76,7 +73,7 @@ public void testSmallBulkErrorMessage() throws SQLException { @Test public void testBigRewriteErrorMessage() throws SQLException { - try (Connection connection = setConnection("&rewriteBatchedStatements=true")) { + try (Connection connection = setBlankConnection("&rewriteBatchedStatements=true")) { executeBigBatchWithException(connection); fail("Must Have thrown error"); } catch (SQLException sqle) { @@ -86,8 +83,7 @@ public void testBigRewriteErrorMessage() throws SQLException { @Test public void testBigMultiErrorMessage() throws SQLException { - Assume.assumeFalse(sharedIsRewrite()); - try (Connection connection = setConnection("&allowMultiQueries=true&useServerPrepStmts=false")) { + try (Connection connection = setBlankConnection("&allowMultiQueries=true&useServerPrepStmts=false")) { executeBigBatchWithException(connection); fail("Must Have thrown error"); } catch (SQLException sqle) { @@ -98,8 +94,7 @@ public void testBigMultiErrorMessage() throws SQLException { @Test public void testBigPrepareErrorMessage() throws SQLException { - Assume.assumeTrue(sharedUsePrepare()); - try (Connection connection = setConnection("&useBatchMultiSend=false")) { + try (Connection connection = setBlankConnection("&useBatchMultiSend=false")) { executeBigBatchWithException(connection); fail("Must Have thrown error"); } catch (SQLException sqle) { @@ -110,8 +105,7 @@ public void testBigPrepareErrorMessage() throws SQLException { @Test public void testBigBulkErrorMessage() throws SQLException { - Assume.assumeTrue(sharedUsePrepare()); - Connection connection = setConnection("&useBatchMultiSend=true"); + Connection connection = setBlankConnection("&useBatchMultiSend=true"); try { executeBigBatchWithException(connection); fail("Must Have thrown error"); From 79a21e520abc547df73510069621d341c01d6a6a Mon Sep 17 00:00:00 2001 From: kolzeq Date: Wed, 31 Aug 2016 01:41:49 +0200 Subject: [PATCH 18/18] Release version 1.5.2 --- README.md | 13 +------------ documentation/changelog.creole | 17 +++++++++++++++-- pom.xml | 2 +- .../jdbc/internal/util/constant/Version.java | 4 ++-- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 0b23da699..eb0cbd556 100644 --- a/README.md +++ b/README.md @@ -23,21 +23,10 @@ or maven : org.mariadb.jdbc mariadb-java-client - 1.4.6 + 1.5.2 ``` -Current release candidate : - -```script - - org.mariadb.jdbc - mariadb-java-client - 1.5.0-RC1 - -``` - - Development snapshot are available on sonatype nexus repository ```script diff --git a/documentation/changelog.creole b/documentation/changelog.creole index 6a72c2299..9d199cd4c 100644 --- a/documentation/changelog.creole +++ b/documentation/changelog.creole @@ -1,6 +1,7 @@ = Changelog -* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#151|1.5.1]] RC released on 15-08-2016 -* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#150|1.5.0]] RC released on 28-07-2016 +* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#151|1.5.2]] Released on 31 aug. 2016 +* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#151|1.5.1]] RC released on 15 aug. 2016 +* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#150|1.5.0]] RC released on 28 jul. 2016 * [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#146|1.4.6]] Released on 13 june 2016 * [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#146|1.4.5]] Released on 18 mai 2016 * [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#144|1.4.4]] Released on 04 mai 2016 @@ -10,6 +11,18 @@ * [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#140|1.4.0]] Released on 31 march 2016 --- +== 1.5.2 +Release version +* CONJ-331 : clearWarnings() now throw exception on closed connection +* CONJ-299 : PreparedStatement.setObject(Type.BIT, "1") registered as true. +* CONJ-293 : permit named pipe connection without host +* CONJ-333 : ResultSet.getString() of PreparedStatement return NULL When TIME column value=00:00:00 + +RC corrections +* CONJ-335 : Pool connection may fail to connect with good user +* CONJ-332 : option enabledSslCipherSuites rely on java supportedCipherSuites (replacing enabledCipherSuites) +* UTF-8 conversion correction + == 1.5.1 Release candidate version === Evolution diff --git a/pom.xml b/pom.xml index 35e62396f..6932d6834 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ mariadb-java-client jar mariadb-java-client - 1.5.2-SNAPSHOT + 1.5.2 JDBC driver for MariaDB and MySQL https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/ diff --git a/src/main/java/org/mariadb/jdbc/internal/util/constant/Version.java b/src/main/java/org/mariadb/jdbc/internal/util/constant/Version.java index c47759a87..178f94a94 100644 --- a/src/main/java/org/mariadb/jdbc/internal/util/constant/Version.java +++ b/src/main/java/org/mariadb/jdbc/internal/util/constant/Version.java @@ -51,10 +51,10 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS package org.mariadb.jdbc.internal.util.constant; public final class Version { - public static final String version = "1.5.2-SNAPSHOT"; + public static final String version = "1.5.2"; public static final int majorVersion = 1; public static final int minorVersion = 5; public static final int patchVersion = 2; - public static final String qualifier = "SNAPSHOT"; + public static final String qualifier = ""; } \ No newline at end of file