Skip to content

Commit ac2555b

Browse files
committed
Merge branch 'develop'
# Conflicts: # src/main/java/org/mariadb/jdbc/client/column/UnsignedIntColumn.java # src/main/java/org/mariadb/jdbc/client/column/UnsignedSmallIntColumn.java # src/main/java/org/mariadb/jdbc/client/column/UnsignedTinyIntColumn.java
2 parents 06b8ca8 + 22f8126 commit ac2555b

30 files changed

+586
-120
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import: mariadb-corporation/connector-test-machine:common-build.yml@master
1919
jobs:
2020
include:
2121
- stage: Language
22-
env: srv=mariadb v=11.6-rc packet=40 PROFILE=java8
22+
env: srv=mariadb v=11.6 packet=40 PROFILE=java8
2323
jdk: openjdk8
2424
name: "CS 11.6 - openjdk 8"
2525
- stage: Language

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<artifactId>mariadb-java-client</artifactId>
88
<packaging>jar</packaging>
99
<name>mariadb-java-client</name>
10-
<version>3.5.2</version>
10+
<version>3.5.3-SNAPSHOT</version>
1111
<description>JDBC driver for MariaDB and MySQL</description>
1212
<url>https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/</url>
1313

src/main/java/org/mariadb/jdbc/CallableParameterMetaData.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ public int getParameterType(int index) throws SQLException {
147147
case "BIT":
148148
return Types.BIT;
149149
case "TINYINT":
150+
if ("TINYINT(1)".equals(rs.getString("DTD_IDENTIFIER").toUpperCase(Locale.ROOT))) {
151+
return Types.BOOLEAN;
152+
}
150153
return Types.TINYINT;
151154
case "SMALLINT":
152155
case "YEAR":
@@ -211,6 +214,9 @@ public int getParameterType(int index) throws SQLException {
211214
@Override
212215
public String getParameterTypeName(int index) throws SQLException {
213216
setIndex(index);
217+
if ("TINYINT(1)".equals(rs.getString("DTD_IDENTIFIER").toUpperCase(Locale.ROOT))) {
218+
return "BOOLEAN";
219+
}
214220
return rs.getString("DATA_TYPE").toUpperCase(Locale.ROOT);
215221
}
216222

@@ -233,6 +239,9 @@ public String getParameterClassName(int index) throws SQLException {
233239
case "BIT":
234240
return BitSet.class.getName();
235241
case "TINYINT":
242+
if ("TINYINT(1)".equals(rs.getString("DTD_IDENTIFIER").toUpperCase(Locale.ROOT))) {
243+
return boolean.class.getName();
244+
}
236245
return byte.class.getName();
237246
case "SMALLINT":
238247
case "YEAR":

src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ protected boolean executeInternalPreparedBatch() throws SQLException {
130130
|| (!clientParser.isInsert() && conf.useBulkStmts()))
131131
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
132132
|| autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS));
133-
if (canUseBulk && batchParameters.size() > 1 && !clientParser.isMultiQuery()) {
133+
if (canUseBulk
134+
&& batchParameters.size() > 1
135+
&& !clientParser.isMultiQuery()
136+
&& batchParameters.get(0).size() > 0) {
134137
executeBatchBulk(escapeTimeout(sql));
135138
return true;
136139
} else {

src/main/java/org/mariadb/jdbc/Configuration.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public class Configuration {
109109
private boolean useLocalSessionState;
110110
private boolean returnMultiValuesGeneratedIds;
111111
private boolean jdbcCompliantTruncation;
112-
private boolean permitRedirect;
112+
private boolean oldModeNoPrecisionTimestamp;
113+
private Boolean permitRedirect;
113114
private TransactionIsolation transactionIsolation;
114115
private int defaultFetchSize;
115116
private int maxQuerySizeToLog;
@@ -384,7 +385,9 @@ private void initializeDatabaseConfig(Builder builder) {
384385
builder.returnMultiValuesGeneratedIds != null && builder.returnMultiValuesGeneratedIds;
385386
this.jdbcCompliantTruncation =
386387
builder.jdbcCompliantTruncation == null || builder.jdbcCompliantTruncation;
387-
this.permitRedirect = builder.permitRedirect == null || builder.permitRedirect;
388+
this.oldModeNoPrecisionTimestamp =
389+
builder.oldModeNoPrecisionTimestamp != null && builder.oldModeNoPrecisionTimestamp;
390+
this.permitRedirect = builder.permitRedirect;
388391
this.pinGlobalTxToPhysicalConnection =
389392
builder.pinGlobalTxToPhysicalConnection != null && builder.pinGlobalTxToPhysicalConnection;
390393
this.permitNoResults = builder.permitNoResults == null || builder.permitNoResults;
@@ -554,6 +557,7 @@ public Builder toBuilder() {
554557
.useLocalSessionState(this.useLocalSessionState)
555558
.returnMultiValuesGeneratedIds(this.returnMultiValuesGeneratedIds)
556559
.jdbcCompliantTruncation(this.jdbcCompliantTruncation)
560+
.oldModeNoPrecisionTimestamp(this.oldModeNoPrecisionTimestamp)
557561
.permitRedirect(this.permitRedirect)
558562
.pinGlobalTxToPhysicalConnection(this.pinGlobalTxToPhysicalConnection)
559563
.permitNoResults(this.permitNoResults)
@@ -1954,12 +1958,22 @@ public boolean jdbcCompliantTruncation() {
19541958
return jdbcCompliantTruncation;
19551959
}
19561960

1961+
/**
1962+
* Force Timestamp string representation compatible to 2.7 version Timestamp string representation
1963+
* will then correspond to Timestamp.toString() in place of taking field precision
1964+
*
1965+
* @return force 2.7 timestamp to string behavior
1966+
*/
1967+
public boolean oldModeNoPrecisionTimestamp() {
1968+
return oldModeNoPrecisionTimestamp;
1969+
}
1970+
19571971
/**
19581972
* must client redirect when required
19591973
*
19601974
* @return must client redirect when required
19611975
*/
1962-
public boolean permitRedirect() {
1976+
public Boolean permitRedirect() {
19631977
return permitRedirect;
19641978
}
19651979

@@ -2301,6 +2315,7 @@ public static final class Builder implements Cloneable {
23012315
private Boolean useLocalSessionState;
23022316
private Boolean returnMultiValuesGeneratedIds;
23032317
private Boolean jdbcCompliantTruncation;
2318+
private Boolean oldModeNoPrecisionTimestamp;
23042319
private Boolean permitRedirect;
23052320
private Boolean pinGlobalTxToPhysicalConnection;
23062321
private Boolean permitNoResults;
@@ -3235,6 +3250,18 @@ public Builder jdbcCompliantTruncation(Boolean jdbcCompliantTruncation) {
32353250
return this;
32363251
}
32373252

3253+
/**
3254+
* Force Timestamp string representation compatible 2.7 version Timestamp string representation
3255+
* will then correspond to Timestamp.toString() in place of taking field precision
3256+
*
3257+
* @param oldModeNoPrecisionTimestamp force 2.7 timestamp to string behavior
3258+
* @return this {@link Builder}
3259+
*/
3260+
public Builder oldModeNoPrecisionTimestamp(Boolean oldModeNoPrecisionTimestamp) {
3261+
this.oldModeNoPrecisionTimestamp = oldModeNoPrecisionTimestamp;
3262+
return this;
3263+
}
3264+
32383265
/**
32393266
* indicate if connector must redirect connection when receiving server redirect information
32403267
*

src/main/java/org/mariadb/jdbc/Connection.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,20 @@ public CallableStatement prepareCall(String sql) throws SQLException {
192192

193193
@Override
194194
public String nativeSQL(String sql) throws SQLException {
195+
checkNotClosed();
195196
return NativeSql.parse(sql, client.getContext());
196197
}
197198

198199
@Override
199-
public boolean getAutoCommit() {
200+
public boolean getAutoCommit() throws SQLException {
201+
checkNotClosed();
200202
return (client.getContext().getServerStatus() & ServerStatus.AUTOCOMMIT) > 0;
201203
}
202204

203205
@Override
204206
@SuppressWarnings("try")
205207
public void setAutoCommit(boolean autoCommit) throws SQLException {
208+
checkNotClosed();
206209
if (autoCommit == getAutoCommit()) {
207210
return;
208211
}
@@ -216,6 +219,7 @@ public void setAutoCommit(boolean autoCommit) throws SQLException {
216219
@Override
217220
@SuppressWarnings("try")
218221
public void commit() throws SQLException {
222+
checkNotClosed();
219223
try (ClosableLock ignore = lock.closeableLock()) {
220224
if (forceTransactionEnd
221225
|| (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
@@ -227,6 +231,7 @@ public void commit() throws SQLException {
227231
@Override
228232
@SuppressWarnings("try")
229233
public void rollback() throws SQLException {
234+
checkNotClosed();
230235
try (ClosableLock ignore = lock.closeableLock()) {
231236
if (forceTransactionEnd
232237
|| (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
@@ -302,6 +307,7 @@ public boolean isReadOnly() {
302307
@Override
303308
@SuppressWarnings("try")
304309
public void setReadOnly(boolean readOnly) throws SQLException {
310+
checkNotClosed();
305311
try (ClosableLock ignore = lock.closeableLock()) {
306312
if (this.readOnly != readOnly) {
307313
client.setReadOnly(readOnly);
@@ -334,6 +340,7 @@ public void setSchema(String schema) throws SQLException {
334340
}
335341

336342
private String getDatabase() throws SQLException {
343+
checkNotClosed();
337344
if (client.getContext().hasClientCapability(Capabilities.CLIENT_SESSION_TRACK)) {
338345
return client.getContext().getDatabase();
339346
}
@@ -348,6 +355,7 @@ private String getDatabase() throws SQLException {
348355

349356
@SuppressWarnings("try")
350357
private void setDatabase(String database) throws SQLException {
358+
checkNotClosed();
351359
// null catalog means keep current.
352360
// there is no possibility to set no database when one is selected
353361
if (database == null
@@ -364,6 +372,7 @@ private void setDatabase(String database) throws SQLException {
364372

365373
@Override
366374
public int getTransactionIsolation() throws SQLException {
375+
checkNotClosed();
367376
boolean useContextState =
368377
conf.useLocalSessionState()
369378
|| (client.getContext().hasClientCapability(Capabilities.CLIENT_SESSION_TRACK)
@@ -409,6 +418,7 @@ public int getTransactionIsolation() throws SQLException {
409418
@Override
410419
@SuppressWarnings("try")
411420
public void setTransactionIsolation(int level) throws SQLException {
421+
checkNotClosed();
412422
boolean useContextState =
413423
conf.useLocalSessionState()
414424
|| (client.getContext().hasClientCapability(Capabilities.CLIENT_SESSION_TRACK)
@@ -477,7 +487,8 @@ public SQLWarning getWarnings() throws SQLException {
477487
}
478488

479489
@Override
480-
public void clearWarnings() {
490+
public void clearWarnings() throws SQLException {
491+
checkNotClosed();
481492
client.getContext().setWarning(0);
482493
}
483494

@@ -735,6 +746,7 @@ public Array createArrayOf(String typeName, Object[] elements) throws SQLExcepti
735746
}
736747

737748
public Array createArrayOf(String typeName, Object elements) throws SQLException {
749+
checkNotClosed();
738750
if (typeName == null) throw exceptionFactory.notSupported("typeName is not mandatory");
739751
if (elements == null) return null;
740752

@@ -834,6 +846,7 @@ public Client getClient() {
834846
* @throws SQLException if resetting operation failed
835847
*/
836848
public void reset() throws SQLException {
849+
checkNotClosed();
837850
// COM_RESET_CONNECTION exist since mysql 5.7.3 and mariadb 10.2.4
838851
// but not possible to use it with mysql waiting for https://bugs.mysql.com/bug.php?id=97633
839852
// correction.

src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected boolean executeInternalPreparedBatch() throws SQLException {
177177
|| (!clientParser.isInsert() && conf.useBulkStmts()))
178178
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
179179
|| autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS));
180-
if (canUseBulk && batchParameters.size() > 1) {
180+
if (canUseBulk && batchParameters.size() > 1 && batchParameters.get(0).size() > 0) {
181181
executeBatchBulk(cmd);
182182
return true;
183183
} else {

src/main/java/org/mariadb/jdbc/Statement.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,10 @@ public int getResultSetHoldability() {
12761276
* @return true if this <code>Statement</code> object is closed; false if it is still open
12771277
*/
12781278
@Override
1279-
public boolean isClosed() {
1279+
public boolean isClosed() throws SQLException {
1280+
if (!closed && this.con.isClosed()) {
1281+
this.close();
1282+
}
12801283
return closed;
12811284
}
12821285

0 commit comments

Comments
 (0)