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
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 969811645..6932d6834 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
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/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/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/MariaDbConnection.java b/src/main/java/org/mariadb/jdbc/MariaDbConnection.java
index dc77425f1..828909c2e 100644
--- a/src/main/java/org/mariadb/jdbc/MariaDbConnection.java
+++ b/src/main/java/org/mariadb/jdbc/MariaDbConnection.java
@@ -405,19 +405,21 @@ public PreparedStatement internalPrepareStatement(final String sql, final int re
checkConnection();
boolean canUsePrepareStatement = false;
- if (options.rewriteBatchedStatements) {
- //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) {
+
+ if (sql != null) {
String cleanSql = sql.toUpperCase().trim();
- canUsePrepareStatement = (cleanSql.contains("SELECT")
- || cleanSql.contains("CALL")
- || cleanSql.contains("UPDATE")
- || cleanSql.contains("INSERT")
- || cleanSql.contains("DELETE")
- || cleanSql.contains("REPLACE")
- || cleanSql.contains("DO"));
+ 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/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..6257faa37 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
@@ -739,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;
@@ -842,6 +849,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 +912,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/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/failover/AbstractMastersListener.java b/src/main/java/org/mariadb/jdbc/internal/failover/AbstractMastersListener.java
index b012f30e5..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,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/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/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/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 1107b97ba..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
@@ -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();
@@ -119,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/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java b/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java
index 7e3b1f006..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() {
@@ -866,7 +870,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)) {
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..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
@@ -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 {
@@ -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);
@@ -2917,16 +2916,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;
@@ -3471,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/main/java/org/mariadb/jdbc/internal/util/DefaultOptions.java b/src/main/java/org/mariadb/jdbc/internal/util/DefaultOptions.java
index 05ff7c4b3..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"),
@@ -588,6 +587,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/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/main/java/org/mariadb/jdbc/internal/util/constant/Version.java b/src/main/java/org/mariadb/jdbc/internal/util/constant/Version.java
index 584d4f0bd..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.1-RC";
+ 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 = 1;
- public static final String qualifier = "RC";
+ public static final int patchVersion = 2;
+ public static final String qualifier = "";
}
\ No newline at end of file
diff --git a/src/test/java/org/mariadb/jdbc/BaseTest.java b/src/test/java/org/mariadb/jdbc/BaseTest.java
index 56d436aaf..6f06c2485 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.
@@ -24,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;
@@ -52,17 +54,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) {
@@ -148,12 +151,42 @@ 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();
+ 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();
@@ -163,10 +196,10 @@ 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 : "");
+ + (parameters != null ? "&" + parameters : "");
}
/**
@@ -299,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 {
@@ -332,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);
}
@@ -352,11 +393,12 @@ protected Connection setConnection(String parameters) throws SQLException {
return openConnection(connUri + parameters, null);
}
+
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 : "");
+ + (parameters != null ? "&" + parameters : "");
return openConnection(connUri + additionnallParameters, null);
}
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/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/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/DatatypeCompatibilityTest.java b/src/test/java/org/mariadb/jdbc/DatatypeCompatibilityTest.java
index 13dcd456d..8f2274faa 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,11 @@ 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");
+
+ 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
@@ -155,4 +163,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
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 (?,?,?,?)");
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/DriverTest.java b/src/test/java/org/mariadb/jdbc/DriverTest.java
index 1a4b61685..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");
@@ -1125,17 +1122,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/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");
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/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/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 {
diff --git a/src/test/java/org/mariadb/jdbc/PooledConnectionTest.java b/src/test/java/org/mariadb/jdbc/PooledConnectionTest.java
index d75b1509a..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);
@@ -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();
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");
diff --git a/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java b/src/test/java/org/mariadb/jdbc/ServerPrepareStatementTest.java
index ec7e2ce8d..81d5637ea 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(sharedOptions().useServerPrepStmts);
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,9 +823,11 @@ public void run() {
@Test
public void testPrepareStatementCache() throws Throwable {
+ Assume.assumeTrue(sharedOptions().useServerPrepStmts);
+
//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++) {
diff --git a/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java b/src/test/java/org/mariadb/jdbc/TimezoneDaylightSavingTimeTest.java
index fa248511d..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)");
+
}
}
@@ -158,6 +160,7 @@ public void testTimeStamp() throws SQLException {
@Test
public void testTimeStampUtc() throws SQLException {
+
TimeZone.setDefault(parisTimeZone);
Connection connection = null;
try {
@@ -281,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());
@@ -389,8 +394,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 +506,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 +576,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);
}
diff --git a/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java b/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java
index d8fac81a0..da44579f7 100644
--- a/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java
+++ b/src/test/java/org/mariadb/jdbc/failover/OldFailoverTest.java
@@ -16,9 +16,10 @@ 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 : "");
+ + (parameters != null ? "&" + parameters : "");
try {
//the first host doesn't exist, so with the random host selection, verifying that we connect to the good