diff --git a/.travis.yml b/.travis.yml index fd38483a8..3e10275cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ os: linux -dist: bionic +dist: jammy language: java services: - docker @@ -47,19 +47,30 @@ jobs: allow_failures: - env: srv=build - env: srv=xpand TEST_DB_OTHER="&initSql=SET NAMES UTF8" + - env: srv=mariadb-es local=1 + - env: srv=skysql + - env: srv=skysql-ha include: - stage: Minimal env: srv=mariadb v=10.6 packet=8 name: "CS 10.6" - - env: srv=mariadb-es v=10.6 - name: "ES 10.6" + - env: srv=mariadb-es + name: "ES latest" if: type = push AND fork = false - stage: Enterprise env: srv=mariadb-es v=10.4 + dist: bionic name: "ES 10.4" - env: srv=mariadb-es v=10.5 + dist: bionic name: "ES 10.5" + - env: srv=mariadb-es v=10.6 + name: "ES 10.6" + if: type = push AND fork = false + - env: srv=mariadb-es-test v=23.06 + name: "ES 23.06" + if: type = push AND fork = false - env: srv=maxscale name: "Maxscale" - env: srv=xpand TEST_DB_OTHER="&initSql=SET NAMES UTF8" @@ -74,18 +85,22 @@ jobs: os: windows language: shell name: "CS 10.6 - Windows" - - env: srv=mariadb v=10.3 local=1 - name: "CS 10.3" - env: srv=mariadb v=10.4 local=1 + dist: bionic name: "CS 10.4" - env: srv=mariadb v=10.5 local=1 + dist: bionic name: "CS 10.5" - - env: srv=mariadb v=10.7 local=1 - name: "CS 10.7" - - env: srv=mariadb v=10.8 local=1 - name: "CS 10.8" - env: srv=mariadb v=10.9 local=1 name: "CS 10.9" + - env: srv=mariadb v=10.10 local=1 + name: "CS 10.10" + - env: srv=mariadb v=10.11 local=1 + name: "CS 10.11" + - env: srv=mariadb v=11.0 local=1 + name: "CS 11.0" + - env: srv=mariadb v=11.1-rc local=1 + name: "CS 11.1" - env: srv=mariadb v=10.6 packet=40 jdk: openjdk17 name: "CS 10.6 - openjdk 17" diff --git a/CHANGELOG.md b/CHANGELOG.md index 92cb3d8a3..4938f7618 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,36 @@ # Change Log + +## [3.2.0](https://github.com/mariadb-corporation/mariadb-connector-j/tree/3.2.0) (Aug 2023) +[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-j/compare/3.1.4...3.2.0) + +##### Notable Changes +* CONJ-920 Java batched statements with optimistic locking failing. the option `useBulkStmts` is now disable by default, a new option `useBulkStmtsForInserts` is enable by default, permetting using bulk for INSERT commands only. This permits optimistic behavior working by default. +* CONJ-1084 When using maxscale 23.08.0+, and a maxscale node fails, connector will now priorize reconnection to the maxscale node having less connection, to ensure repartition after failover +* CONJ-1088 Implement `databaseTerm` option for mysql compatibility +* CONJ-1096 adding option `useLocalSessionState` to permit avoiding queries when application only use JDBC methods. + +##### Bugs Fixed +* CONJ-1075 LOAD DATA INFILE is broken on windows +* CONJ-1079 getGeneratedKeys after batch will not return all generated id's if first batch command return no generated id. +* CONJ-1080 maridb Java connector sslMode=verify-ca complaining unable to find trust certificate. +* CONJ-1082 Multiple session system variables parsing fails +* CONJ-1083 Using /*client prepare*/ prefix to force client side prepared statement +* CONJ-1091 can't make a connection when the Read Replica DB is in a hang state when SocketTimeout=0 set +* CONJ-1092 ensure respecting server collation +* CONJ-1094 Missing mariadb/mysql collation + + +## [3.0.11](https://github.com/mariadb-corporation/mariadb-connector-j/tree/3.0.11) (Aug 2023) +[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-j/compare/3.0.10...3.0.11) + +* CONJ-1089 correcting 3.0.10 incompatibility with in java 8 + +## [2.7.10](https://github.com/mariadb-corporation/mariadb-connector-j/tree/2.7.10) (Aug 2023) +[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-j/compare/2.7.9...2.7.10) + +* CONJ-1091 Ensure setting connectTimeout as timeout for socket timeout until connection is done. This permit to set a connectTimeout, while socketTimeout can still be set to 0 + ## [3.1.4](https://github.com/mariadb-corporation/mariadb-connector-j/tree/3.1.4) (Apr 2023) [Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-j/compare/3.1.3...3.1.4) diff --git a/pom.xml b/pom.xml index ffbaa99e5..116cc8b6a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ mariadb-java-client jar mariadb-java-client - 3.1.4 + 3.2.0 JDBC driver for MariaDB and MySQL https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/ diff --git a/src/benchmark/java/org/mariadb/jdbc/Common.java b/src/benchmark/java/org/mariadb/jdbc/Common.java index 83538ea0e..9d68aee58 100644 --- a/src/benchmark/java/org/mariadb/jdbc/Common.java +++ b/src/benchmark/java/org/mariadb/jdbc/Common.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/benchmark/java/org/mariadb/jdbc/Do_1.java b/src/benchmark/java/org/mariadb/jdbc/Do_1.java index 92d164931..7b23d008e 100644 --- a/src/benchmark/java/org/mariadb/jdbc/Do_1.java +++ b/src/benchmark/java/org/mariadb/jdbc/Do_1.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/benchmark/java/org/mariadb/jdbc/Do_1000_params.java b/src/benchmark/java/org/mariadb/jdbc/Do_1000_params.java index 6850bce04..0c6e157b6 100644 --- a/src/benchmark/java/org/mariadb/jdbc/Do_1000_params.java +++ b/src/benchmark/java/org/mariadb/jdbc/Do_1000_params.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/benchmark/java/org/mariadb/jdbc/Insert_batch.java b/src/benchmark/java/org/mariadb/jdbc/Insert_batch.java index b4ad7db76..7b9ebbcba 100644 --- a/src/benchmark/java/org/mariadb/jdbc/Insert_batch.java +++ b/src/benchmark/java/org/mariadb/jdbc/Insert_batch.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/benchmark/java/org/mariadb/jdbc/Select_1.java b/src/benchmark/java/org/mariadb/jdbc/Select_1.java index 2e3f94363..4a5a63815 100644 --- a/src/benchmark/java/org/mariadb/jdbc/Select_1.java +++ b/src/benchmark/java/org/mariadb/jdbc/Select_1.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/benchmark/java/org/mariadb/jdbc/Select_1000_Rows.java b/src/benchmark/java/org/mariadb/jdbc/Select_1000_Rows.java index 41babb4f1..a1848381c 100644 --- a/src/benchmark/java/org/mariadb/jdbc/Select_1000_Rows.java +++ b/src/benchmark/java/org/mariadb/jdbc/Select_1000_Rows.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/benchmark/java/org/mariadb/jdbc/Select_100_cols.java b/src/benchmark/java/org/mariadb/jdbc/Select_100_cols.java index 98baa2ea5..a4f5a03a8 100644 --- a/src/benchmark/java/org/mariadb/jdbc/Select_100_cols.java +++ b/src/benchmark/java/org/mariadb/jdbc/Select_100_cols.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/BaseCallableStatement.java b/src/main/java/org/mariadb/jdbc/BaseCallableStatement.java index 92d0e3d09..2a9516ae1 100644 --- a/src/main/java/org/mariadb/jdbc/BaseCallableStatement.java +++ b/src/main/java/org/mariadb/jdbc/BaseCallableStatement.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/BasePreparedStatement.java b/src/main/java/org/mariadb/jdbc/BasePreparedStatement.java index 7fbec194d..0d0ec46ea 100644 --- a/src/main/java/org/mariadb/jdbc/BasePreparedStatement.java +++ b/src/main/java/org/mariadb/jdbc/BasePreparedStatement.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; @@ -13,6 +13,7 @@ import java.sql.ParameterMetaData; import java.util.*; import java.util.concurrent.locks.ReentrantLock; +import java.util.regex.Pattern; import org.mariadb.jdbc.client.ColumnDecoder; import org.mariadb.jdbc.client.util.Parameters; import org.mariadb.jdbc.codec.*; @@ -24,6 +25,8 @@ /** Common methods for prepare statement, for client and server prepare statement. */ public abstract class BasePreparedStatement extends Statement implements PreparedStatement { + private static final Pattern INSERT_STATEMENT_PATTERN = + Pattern.compile("^(\\s*\\/\\*([^*]|\\*[^/])*\\*\\/)*\\s*(INSERT)", Pattern.CASE_INSENSITIVE); /** parameters */ protected Parameters parameters; @@ -37,6 +40,8 @@ public abstract class BasePreparedStatement extends Statement implements Prepare /** PREPARE command result */ protected Prepare prepareResult = null; + protected Boolean isCommandInsert = null; + /** * Constructor * @@ -91,6 +96,11 @@ public String toString() { return sb.toString(); } + protected void checkIfInsertCommand() { + if (isCommandInsert == null) + isCommandInsert = (sql == null) ? false : INSERT_STATEMENT_PATTERN.matcher(sql).find(); + } + /** * Set PREPARE result * diff --git a/src/main/java/org/mariadb/jdbc/CallableParameterMetaData.java b/src/main/java/org/mariadb/jdbc/CallableParameterMetaData.java index f9a0f0c4a..c46e41b44 100644 --- a/src/main/java/org/mariadb/jdbc/CallableParameterMetaData.java +++ b/src/main/java/org/mariadb/jdbc/CallableParameterMetaData.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java b/src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java index 683256a9a..ad8197a1e 100644 --- a/src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java +++ b/src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java @@ -1,16 +1,13 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; import static org.mariadb.jdbc.util.constants.Capabilities.*; import java.sql.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Locale; +import java.util.*; import java.util.concurrent.locks.ReentrantLock; import org.mariadb.jdbc.client.ColumnDecoder; import org.mariadb.jdbc.client.Completion; @@ -107,12 +104,16 @@ private void executeInternal() throws SQLException { } } - private void executeInternalPreparedBatch() throws SQLException { + private boolean executeInternalPreparedBatch() throws SQLException { checkNotClosed(); - if (autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS + checkIfInsertCommand(); + Configuration conf = con.getContext().getConf(); + if (((isCommandInsert && (conf.useBulkStmts() || conf.useBulkStmtsForInserts())) + || (!isCommandInsert && conf.useBulkStmts())) && batchParameters.size() > 1 - && con.getContext().hasClientCapability(STMT_BULK_OPERATIONS)) { + && autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS) { executeBatchBulk(); + return isCommandInsert; } else { boolean possibleLoadLocal = con.getContext().hasClientCapability(LOCAL_FILES); if (possibleLoadLocal) { @@ -128,6 +129,7 @@ private void executeInternalPreparedBatch() throws SQLException { executeBatchPipeline(); } } + return false; } /** @@ -463,8 +465,24 @@ public int[] executeBatch() throws SQLException { if (batchParameters == null || batchParameters.isEmpty()) return new int[0]; lock.lock(); try { - executeInternalPreparedBatch(); + boolean wasBulkInsert = executeInternalPreparedBatch(); + int[] updates = new int[batchParameters.size()]; + + // specific case for BULK INSERT + // return not Statement.SUCCESS_NO_INFO, but 1 + if (wasBulkInsert) { + int numberOfResult = 0; + for (int i = 0; i < results.size(); i++) { + numberOfResult += (int) ((OkPacket) results.get(i)).getAffectedRows(); + } + if (numberOfResult == updates.length) { + Arrays.fill(updates, 1); + currResult = results.remove(0); + return updates; + } + } + if (results.size() != batchParameters.size()) { for (int i = 0; i < batchParameters.size(); i++) { updates[i] = Statement.SUCCESS_NO_INFO; @@ -492,8 +510,23 @@ public long[] executeLargeBatch() throws SQLException { if (batchParameters == null || batchParameters.isEmpty()) return new long[0]; lock.lock(); try { - executeInternalPreparedBatch(); + boolean wasBulkInsert = executeInternalPreparedBatch(); long[] updates = new long[results.size()]; + + // specific case for BULK INSERT + // return not Statement.SUCCESS_NO_INFO, but 1 + if (wasBulkInsert) { + int numberOfResult = 0; + for (int i = 0; i < results.size(); i++) { + numberOfResult += (int) ((OkPacket) results.get(i)).getAffectedRows(); + } + if (numberOfResult == updates.length) { + Arrays.fill(updates, 1); + currResult = results.remove(0); + return updates; + } + } + for (int i = 0; i < results.size(); i++) { updates[i] = ((OkPacket) results.get(i)).getAffectedRows(); } diff --git a/src/main/java/org/mariadb/jdbc/Configuration.java b/src/main/java/org/mariadb/jdbc/Configuration.java index 8388b6cca..a43153168 100644 --- a/src/main/java/org/mariadb/jdbc/Configuration.java +++ b/src/main/java/org/mariadb/jdbc/Configuration.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; @@ -15,6 +15,7 @@ import org.mariadb.jdbc.plugin.Codec; import org.mariadb.jdbc.plugin.CredentialPlugin; import org.mariadb.jdbc.plugin.credential.CredentialPluginLoader; +import org.mariadb.jdbc.util.constants.CatalogTerm; import org.mariadb.jdbc.util.log.Logger; import org.mariadb.jdbc.util.log.Loggers; import org.mariadb.jdbc.util.options.OptionAliases; @@ -58,7 +59,6 @@ public class Configuration { private String database = null; private List addresses = null; private HaMode haMode = HaMode.NONE; - private String initialUrl = null; private Properties nonMappedOptions = null; @@ -66,7 +66,9 @@ public class Configuration { private String timezone = null; private Boolean autocommit = null; private boolean useMysqlMetadata = false; + private CatalogTerm useCatalogTerm = CatalogTerm.UseCatalog; private boolean createDatabaseIfNotExist = false; + private boolean useLocalSessionState = false; private TransactionIsolation transactionIsolation = null; private int defaultFetchSize = 0; private int maxQuerySizeToLog = 1024; @@ -97,7 +99,9 @@ public class Configuration { private String serverSslCert = null; private String keyStore = null; private String keyStorePassword = null; + private String keyPassword = null; private String keyStoreType = null; + private String trustStoreType = null; private String enabledSslCipherSuites = null; private String enabledSslProtocolSuites = null; @@ -106,7 +110,8 @@ public class Configuration { private boolean allowLocalInfile = true; private boolean useCompression = false; private boolean useAffectedRows = false; - private boolean useBulkStmts = true; + private boolean useBulkStmts = false; + private boolean useBulkStmtsForInserts = true; private boolean disablePipeline = false; // prepare private boolean cachePrepStmts = true; @@ -162,7 +167,9 @@ private Configuration( String timezone, Boolean autocommit, boolean useMysqlMetadata, + CatalogTerm useCatalogTerm, boolean createDatabaseIfNotExist, + boolean useLocalSessionState, TransactionIsolation transactionIsolation, int defaultFetchSize, int maxQuerySizeToLog, @@ -188,7 +195,9 @@ private Configuration( String serverSslCert, String keyStore, String keyStorePassword, + String keyPassword, String keyStoreType, + String trustStoreType, String enabledSslCipherSuites, String enabledSslProtocolSuites, boolean allowMultiQueries, @@ -196,6 +205,7 @@ private Configuration( boolean useCompression, boolean useAffectedRows, boolean useBulkStmts, + boolean useBulkStmtsForInserts, boolean disablePipeline, boolean cachePrepStmts, int prepStmtCacheSize, @@ -234,7 +244,9 @@ private Configuration( this.timezone = timezone; this.autocommit = autocommit; this.useMysqlMetadata = useMysqlMetadata; + this.useCatalogTerm = useCatalogTerm; this.createDatabaseIfNotExist = createDatabaseIfNotExist; + this.useLocalSessionState = useLocalSessionState; this.transactionIsolation = transactionIsolation; this.defaultFetchSize = defaultFetchSize; this.maxQuerySizeToLog = maxQuerySizeToLog; @@ -260,7 +272,9 @@ private Configuration( this.serverSslCert = serverSslCert; this.keyStore = keyStore; this.keyStorePassword = keyStorePassword; + this.keyPassword = keyPassword; this.keyStoreType = keyStoreType; + this.trustStoreType = trustStoreType; this.enabledSslCipherSuites = enabledSslCipherSuites; this.enabledSslProtocolSuites = enabledSslProtocolSuites; this.allowMultiQueries = allowMultiQueries; @@ -268,6 +282,7 @@ private Configuration( this.useCompression = useCompression; this.useAffectedRows = useAffectedRows; this.useBulkStmts = useBulkStmts; + this.useBulkStmtsForInserts = useBulkStmtsForInserts; this.disablePipeline = disablePipeline; this.cachePrepStmts = cachePrepStmts; this.prepStmtCacheSize = prepStmtCacheSize; @@ -338,10 +353,13 @@ private Configuration( Boolean useServerPrepStmts, String connectionAttributes, Boolean useBulkStmts, + Boolean useBulkStmtsForInserts, Boolean disablePipeline, Boolean autocommit, Boolean useMysqlMetadata, + String useCatalogTerm, Boolean createDatabaseIfNotExist, + Boolean useLocalSessionState, Boolean includeInnodbStatusInDeadlockExceptions, Boolean includeThreadDumpInDeadlockExceptions, String servicePrincipalName, @@ -364,7 +382,9 @@ private Configuration( String serverSslCert, String keyStore, String keyStorePassword, + String keyPassword, String keyStoreType, + String trustStoreType, Boolean useReadAheadInput, Boolean cachePrepStmts, Boolean transactionReplay, @@ -419,10 +439,24 @@ private Configuration( if (useServerPrepStmts != null) this.useServerPrepStmts = useServerPrepStmts; this.connectionAttributes = connectionAttributes; if (useBulkStmts != null) this.useBulkStmts = useBulkStmts; + if (useBulkStmtsForInserts != null) this.useBulkStmtsForInserts = useBulkStmtsForInserts; if (disablePipeline != null) this.disablePipeline = disablePipeline; if (autocommit != null) this.autocommit = autocommit; if (useMysqlMetadata != null) this.useMysqlMetadata = useMysqlMetadata; + if (useCatalogTerm != null) { + if (!"CATALOG".equalsIgnoreCase(useCatalogTerm) + && !"SCHEMA".equalsIgnoreCase(useCatalogTerm)) { + throw new IllegalArgumentException( + "useCatalogTerm can only have CATALOG/SCHEMA value, current set value is " + + useCatalogTerm); + } + this.useCatalogTerm = + "CATALOG".equalsIgnoreCase(useCatalogTerm) + ? CatalogTerm.UseCatalog + : CatalogTerm.UseSchema; + } if (createDatabaseIfNotExist != null) this.createDatabaseIfNotExist = createDatabaseIfNotExist; + if (useLocalSessionState != null) this.useLocalSessionState = useLocalSessionState; if (includeInnodbStatusInDeadlockExceptions != null) this.includeInnodbStatusInDeadlockExceptions = includeInnodbStatusInDeadlockExceptions; if (includeThreadDumpInDeadlockExceptions != null) @@ -460,7 +494,9 @@ private Configuration( if (serverSslCert != null) this.serverSslCert = serverSslCert; if (keyStore != null) this.keyStore = keyStore; if (keyStorePassword != null) this.keyStorePassword = keyStorePassword; + if (keyPassword != null) this.keyPassword = keyPassword; if (keyStoreType != null) this.keyStoreType = keyStoreType; + if (trustStoreType != null) this.trustStoreType = trustStoreType; // ************************************************************* // host primary check @@ -742,7 +778,9 @@ public Configuration clone(String username, String password) { this.timezone, this.autocommit, this.useMysqlMetadata, + this.useCatalogTerm, this.createDatabaseIfNotExist, + this.useLocalSessionState, this.transactionIsolation, this.defaultFetchSize, this.maxQuerySizeToLog, @@ -768,7 +806,9 @@ public Configuration clone(String username, String password) { this.serverSslCert, this.keyStore, this.keyStorePassword, + this.keyPassword, this.keyStoreType, + this.trustStoreType, this.enabledSslCipherSuites, this.enabledSslProtocolSuites, this.allowMultiQueries, @@ -776,6 +816,7 @@ public Configuration clone(String username, String password) { this.useCompression, this.useAffectedRows, this.useBulkStmts, + this.useBulkStmtsForInserts, this.disablePipeline, this.cachePrepStmts, this.prepStmtCacheSize, @@ -898,6 +939,15 @@ public String keyStorePassword() { return keyStorePassword; } + /** + * key store alias password + * + * @return key store alias password + */ + public String keyPassword() { + return keyPassword; + } + /** * key store type (to replace default javax.net.ssl.keyStoreType system property) * @@ -907,6 +957,15 @@ public String keyStoreType() { return keyStoreType; } + /** + * trust store type (to replace default javax.net.ssl.keyStoreType system property) + * + * @return trust store type + */ + public String trustStoreType() { + return trustStoreType; + } + /** * permitted ssl protocol list (comma separated) * @@ -1197,6 +1256,16 @@ public boolean useBulkStmts() { return useBulkStmts; } + /** + * Use server COM_STMT_BULK for batching inserts. if useBulkStmts is enabled, + * useBulkStmtsForInserts will be as well + * + * @return use server bulk command for inserts + */ + public boolean useBulkStmtsForInserts() { + return useBulkStmtsForInserts; + } + /** * Disable pipeline. * @@ -1224,6 +1293,15 @@ public boolean useMysqlMetadata() { return useMysqlMetadata; } + /** + * Indicating using Catalog or Schema + * + * @return Indicating using Catalog or Schema + */ + public CatalogTerm useCatalogTerm() { + return useCatalogTerm; + } + /** * create database if not exist * @@ -1233,6 +1311,17 @@ public boolean createDatabaseIfNotExist() { return createDatabaseIfNotExist; } + /** + * use local state to avoid unnecessary queries. This means application must use JDBC dedicated + * methods, like connection.setTransactionIsolation and never queries like "SET SESSION + * TRANSACTION ISOLATION LEVEL X" directly + * + * @return can use local state + */ + public boolean useLocalSessionState() { + return useLocalSessionState; + } + /** * On deadlock exception, must driver execute additional commands to show innodb status in error * description. @@ -1496,6 +1585,128 @@ public String toString() { return initialUrl; } + /** + * Permit to have string information on how string is parsed. example : + * Configuration.toConf("jdbc:mariadb://localhost/test") will return a String containing: + * Configuration: + * * resulting Url : jdbc:mariadb://localhost/test + * Unknown options : None + * + * Non default options : + * * database : test + * + * default options : + * * user : null + * ... + * + * + * @param url url string + * @return string describing the configuration parsed from url + * @throws SQLException if parsing fails + */ + public static String toConf(String url) throws SQLException { + Configuration conf = Configuration.parseInternal(url, new Properties()); + StringBuilder sb = new StringBuilder(); + StringBuilder sbUnknownOpts = new StringBuilder(); + + if (conf.nonMappedOptions.isEmpty()) { + sbUnknownOpts.append("None"); + } else { + for (Map.Entry entry : conf.nonMappedOptions.entrySet()) { + sbUnknownOpts.append("\n * ").append(entry.getKey()).append(" : ").append(entry.getValue()); + } + } + sb.append("Configuration:") + .append("\n * resulting Url : ") + .append(conf.initialUrl) + .append("\nUnknown options : ") + .append(sbUnknownOpts) + .append("\n") + .append("\nNon default options : "); + + Configuration defaultConf = Configuration.parse("jdbc:mariadb://localhost/"); + StringBuilder sbDefaultOpts = new StringBuilder(); + StringBuilder sbDifferentOpts = new StringBuilder(); + try { + List propertyToSkip = + Arrays.asList(new String[] {"initialUrl", "logger", "codecs", "$jacocoData"}); + Field[] fields = Configuration.class.getDeclaredFields(); + Arrays.sort(fields, Comparator.comparing(Field::getName)); + + for (Field field : fields) { + if (!propertyToSkip.contains(field.getName())) { + Object fieldValue = field.get(conf); + if (fieldValue == null) { + (Objects.equals(fieldValue, field.get(defaultConf)) ? sbDefaultOpts : sbDifferentOpts) + .append("\n * ") + .append(field.getName()) + .append(" : ") + .append(fieldValue); + } else { + if (field.getName().equals("haMode")) { + (Objects.equals(fieldValue, field.get(defaultConf)) ? sbDefaultOpts : sbDifferentOpts) + .append("\n * ") + .append(field.getName()) + .append(" : ") + .append(fieldValue); + continue; + } + switch (fieldValue.getClass().getSimpleName()) { + case "String": + case "Boolean": + case "HaMode": + case "TransactionIsolation": + case "Integer": + case "SslMode": + case "CatalogTerm": + (Objects.equals(fieldValue, field.get(defaultConf)) + ? sbDefaultOpts + : sbDifferentOpts) + .append("\n * ") + .append(field.getName()) + .append(" : ") + .append(fieldValue); + break; + case "ArrayList": + (Objects.equals(fieldValue.toString(), field.get(defaultConf).toString()) + ? sbDefaultOpts + : sbDifferentOpts) + .append("\n * ") + .append(field.getName()) + .append(" : ") + .append(fieldValue); + break; + case "Properties": + break; + default: + throw new IllegalArgumentException( + "field type not expected for fields " + field.getName()); + } + } + } + } + + String diff = sbDifferentOpts.toString(); + if (diff.isEmpty()) { + sb.append("None\n"); + } else { + sb.append(diff); + } + + sb.append("\n\ndefault options :"); + String same = sbDefaultOpts.toString(); + if (same.isEmpty()) { + sb.append("None\n"); + } else { + sb.append(same); + } + + } catch (IllegalArgumentException | IllegalAccessException e) { + throw new IllegalArgumentException("Wrong parsing", e); + } + return sb.toString(); + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -1674,7 +1885,9 @@ public static final class Builder implements Cloneable { private String timezone; private Boolean autocommit; private Boolean useMysqlMetadata; + private String useCatalogTerm; private Boolean createDatabaseIfNotExist; + private Boolean useLocalSessionState; private Integer defaultFetchSize; private Integer maxQuerySizeToLog; private Integer maxAllowedPacket; @@ -1704,7 +1917,9 @@ public static final class Builder implements Cloneable { private String serverSslCert; private String keyStore; private String keyStorePassword; + private String keyPassword; private String keyStoreType; + private String trustStoreType; private String enabledSslCipherSuites; private String enabledSslProtocolSuites; @@ -1714,6 +1929,7 @@ public static final class Builder implements Cloneable { private Boolean useCompression; private Boolean useAffectedRows; private Boolean useBulkStmts; + private Boolean useBulkStmtsForInserts; private Boolean disablePipeline; // prepare private Boolean cachePrepStmts; @@ -1802,6 +2018,17 @@ public Builder keyStorePassword(String keyStorePassword) { return this; } + /** + * Client keystore alias password + * + * @param keyPassword client store alias password + * @return this {@link Builder} + */ + public Builder keyPassword(String keyPassword) { + this.keyPassword = nullOrEmpty(keyPassword); + return this; + } + /** * Key store type * @@ -1813,6 +2040,17 @@ public Builder keyStoreType(String keyStoreType) { return this; } + /** + * trust store type + * + * @param trustStoreType trust store type + * @return this {@link Builder} + */ + public Builder trustStoreType(String trustStoreType) { + this.trustStoreType = nullOrEmpty(trustStoreType); + return this; + } + /** * User password * @@ -2289,6 +2527,18 @@ public Builder useBulkStmts(Boolean useBulkStmts) { return this; } + /** + * Use server dedicated bulk batch command for insert (if useBulkStmts is enabled, + * useBulkStmtsForInserts will be enabled as well) + * + * @param useBulkStmtsForInserts use server bulk batch command. + * @return this {@link Builder} + */ + public Builder useBulkStmtsForInserts(Boolean useBulkStmtsForInserts) { + this.useBulkStmtsForInserts = useBulkStmtsForInserts; + return this; + } + /** * Disable pipeline * @@ -2323,6 +2573,26 @@ public Builder useMysqlMetadata(Boolean useMysqlMetadata) { return this; } + /** + * "schema" and "database" are server synonymous. Connector historically get/set database using + * Connection.setCatalog()/getCatalog(), setSchema()/getSchema() being no-op This parameter + * indicate to change that behavior to use Schema in place of Catalog. Behavior will change + * + *
    + *
  • database change will be done with either Connection.setCatalog()/getCatalog() or + * Connection.setSchema()/getSchema() + *
  • DatabaseMetadata methods that use catalog or schema filtering + *
  • ResultsetMetadata database will be retrieved + *
+ * + * @param useCatalogTerm use CATALOG/SCHEMA + * @return this {@link Builder} + */ + public Builder useCatalogTerm(String useCatalogTerm) { + this.useCatalogTerm = useCatalogTerm; + return this; + } + /** * Create database if not exist. This is mainly for test, since does require an additional query * after connection @@ -2335,6 +2605,19 @@ public Builder createDatabaseIfNotExist(Boolean createDatabaseIfNotExist) { return this; } + /** + * indicate if connector can use local state to avoid unnecessary queries. This means + * application must use JDBC dedicated methods, like connection.setTransactionIsolation and + * never queries like "SET SESSION TRANSACTION ISOLATION LEVEL X" directly + * + * @param useLocalSessionState can driver rely on local state + * @return this {@link Builder} + */ + public Builder useLocalSessionState(Boolean useLocalSessionState) { + this.useLocalSessionState = useLocalSessionState; + return this; + } + /** * On dead-lock exception must add innodb status in exception error message. If enabled, an * additional command will be done to retrieve innodb status when dead-lock occurs. @@ -2644,10 +2927,13 @@ public Configuration build() throws SQLException { this.useServerPrepStmts, this.connectionAttributes, this.useBulkStmts, + this.useBulkStmtsForInserts, this.disablePipeline, this.autocommit, this.useMysqlMetadata, + this.useCatalogTerm, this.createDatabaseIfNotExist, + this.useLocalSessionState, this.includeInnodbStatusInDeadlockExceptions, this.includeThreadDumpInDeadlockExceptions, this.servicePrincipalName, @@ -2670,7 +2956,9 @@ public Configuration build() throws SQLException { this.serverSslCert, this.keyStore, this.keyStorePassword, + this.keyPassword, this.keyStoreType, + this.trustStoreType, this.useReadAheadInput, this.cachePrepStmts, this.transactionReplay, diff --git a/src/main/java/org/mariadb/jdbc/Connection.java b/src/main/java/org/mariadb/jdbc/Connection.java index 1cb268e2a..4e9db8b1b 100644 --- a/src/main/java/org/mariadb/jdbc/Connection.java +++ b/src/main/java/org/mariadb/jdbc/Connection.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; @@ -22,6 +22,7 @@ import org.mariadb.jdbc.message.client.ResetPacket; import org.mariadb.jdbc.util.NativeSql; import org.mariadb.jdbc.util.constants.Capabilities; +import org.mariadb.jdbc.util.constants.CatalogTerm; import org.mariadb.jdbc.util.constants.ConnectionState; import org.mariadb.jdbc.util.constants.ServerStatus; @@ -141,7 +142,7 @@ public PreparedStatement prepareInternal( boolean useBinary) throws SQLException { checkNotClosed(); - if (useBinary) { + if (useBinary && !sql.startsWith("/*client prepare*/")) { try { return new ServerPreparedStatement( NativeSql.parse(sql, client.getContext()), @@ -297,7 +298,27 @@ public void setReadOnly(boolean readOnly) throws SQLException { @Override public String getCatalog() throws SQLException { + if (conf.useCatalogTerm() == CatalogTerm.UseCatalog) return getDatabase(); + return "def"; + } + @Override + public void setCatalog(String catalog) throws SQLException { + if (conf.useCatalogTerm() == CatalogTerm.UseCatalog) setDatabase(catalog); + } + + @Override + public String getSchema() throws SQLException { + if (conf.useCatalogTerm() == CatalogTerm.UseSchema) return getDatabase(); + return null; + } + + @Override + public void setSchema(String schema) throws SQLException { + if (conf.useCatalogTerm() == CatalogTerm.UseSchema) setDatabase(schema); + } + + private String getDatabase() throws SQLException { if (client.getContext().hasClientCapability(Capabilities.CLIENT_SESSION_TRACK)) { return client.getContext().getDatabase(); } @@ -309,20 +330,19 @@ public String getCatalog() throws SQLException { return client.getContext().getDatabase(); } - @Override - public void setCatalog(String catalog) throws SQLException { + private void setDatabase(String database) throws SQLException { // null catalog means keep current. // there is no possibility to set no database when one is selected - if (catalog == null + if (database == null || (client.getContext().hasClientCapability(Capabilities.CLIENT_SESSION_TRACK) - && catalog.equals(client.getContext().getDatabase()))) { + && database.equals(client.getContext().getDatabase()))) { return; } lock.lock(); try { getContext().addStateFlag(ConnectionState.STATE_DATABASE); - client.execute(new ChangeDbPacket(catalog), true); - client.getContext().setDatabase(catalog); + client.execute(new ChangeDbPacket(database), true); + client.getContext().setDatabase(database); } finally { lock.unlock(); } @@ -330,15 +350,18 @@ public void setCatalog(String catalog) throws SQLException { @Override public int getTransactionIsolation() throws SQLException { + if (conf.useLocalSessionState() && client.getContext().getTransactionIsolationLevel() != null) { + return client.getContext().getTransactionIsolationLevel(); + } - String sql = "SELECT @@tx_isolation"; + String sql = "SELECT @@session.tx_isolation"; if (!client.getContext().getVersion().isMariaDBServer()) { if ((client.getContext().getVersion().getMajorVersion() >= 8 && client.getContext().getVersion().versionGreaterOrEqual(8, 0, 3)) || (client.getContext().getVersion().getMajorVersion() < 8 && client.getContext().getVersion().versionGreaterOrEqual(5, 7, 20))) { - sql = "SELECT @@transaction_isolation"; + sql = "SELECT @@session.transaction_isolation"; } } @@ -369,6 +392,12 @@ public int getTransactionIsolation() throws SQLException { @Override public void setTransactionIsolation(int level) throws SQLException { + if (conf.useLocalSessionState() + && client.getContext().getTransactionIsolationLevel() != null + && level == client.getContext().getTransactionIsolationLevel()) { + return; + } + String query = "SET SESSION TRANSACTION ISOLATION LEVEL"; switch (level) { case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED: @@ -710,18 +739,6 @@ public Struct createStruct(String typeName, Object[] attributes) throws SQLExcep throw exceptionFactory.notSupported("Struct type is not supported"); } - @Override - public String getSchema() { - // We support only catalog - return null; - } - - @Override - public void setSchema(String schema) { - // We support only catalog, and JDBC indicate "If the driver does not support schemas, it will - // silently ignore this request." - } - @Override public void abort(Executor executor) throws SQLException { if (poolConnection != null) { diff --git a/src/main/java/org/mariadb/jdbc/DatabaseMetaData.java b/src/main/java/org/mariadb/jdbc/DatabaseMetaData.java index 2d063d0b2..ef0b75733 100644 --- a/src/main/java/org/mariadb/jdbc/DatabaseMetaData.java +++ b/src/main/java/org/mariadb/jdbc/DatabaseMetaData.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; @@ -13,6 +13,7 @@ import org.mariadb.jdbc.client.result.CompleteResult; import org.mariadb.jdbc.client.result.Result; import org.mariadb.jdbc.util.VersionFactory; +import org.mariadb.jdbc.util.constants.CatalogTerm; import org.mariadb.jdbc.util.constants.ColumnFlags; import org.mariadb.jdbc.util.constants.ServerStatus; @@ -193,13 +194,13 @@ private int parseIdentifierList(char[] part, int startPos, List list * * @param tableDef table definition * @param tableName table name - * @param catalog catalog + * @param database database * @param connection connection * @return resultset resultset * @throws ParseException exception */ private ResultSet getImportedKeys( - String tableDef, String tableName, String catalog, org.mariadb.jdbc.Connection connection) + String tableDef, String tableName, String database, org.mariadb.jdbc.Connection connection) throws Exception, SQLException { boolean importedKeysWithConstraintNames = Boolean.parseBoolean( @@ -260,15 +261,18 @@ private ResultSet getImportedKeys( for (int i = 0; i < primaryKeyCols.size(); i++) { String[] row = new String[columnNames.length]; - row[0] = pkTable.schema; // PKTABLE_CAT - if (row[0] == null) { - row[0] = catalog; - } - row[1] = null; // PKTABLE_SCHEM + row[0] = + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? (pkTable.schema == null ? database : pkTable.schema) + : "def"; // PKTABLE_CAT + row[1] = + conf.useCatalogTerm() == CatalogTerm.UseSchema + ? (pkTable.schema == null ? database : pkTable.schema) + : null; // PKTABLE_SCHEM row[2] = pkTable.name; // PKTABLE_NAME row[3] = primaryKeyCols.get(i).name; // PKCOLUMN_NAME - row[4] = catalog; // FKTABLE_CAT - row[5] = null; // FKTABLE_SCHEM + row[4] = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? database : "def"; // FKTABLE_CAT + row[5] = conf.useCatalogTerm() == CatalogTerm.UseSchema ? database : null; // FKTABLE_SCHEM row[6] = tableName; // FKTABLE_NAME row[7] = foreignKeyCols.get(i).name; // FKCOLUMN_NAME row[8] = Integer.toString(i + 1); // KEY_SEQ @@ -311,18 +315,21 @@ private ResultSet getImportedKeys( } } String[][] arr = data.toArray(new String[0][]); - - /* Sort array by PKTABLE_CAT, PKTABLE_NAME, and KEY_SEQ.*/ + /* Sort array by PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, and KEY_SEQ.*/ Arrays.sort( arr, (row1, row2) -> { - int result = row1[0].compareTo(row2[0]); // PKTABLE_CAT + int result = 0; + if (row1[0] != null) result = row1[0].compareTo(row2[0]); // PKTABLE_CAT if (result == 0) { - result = row1[2].compareTo(row2[2]); // PKTABLE_NAME + if (row1[1] != null) result = row1[1].compareTo(row2[1]); // PKTABLE_SCHEM if (result == 0) { - result = row1[8].length() - row2[8].length(); // KEY_SEQ + result = row1[2].compareTo(row2[2]); // PKTABLE_NAME if (result == 0) { - result = row1[8].compareTo(row2[8]); + result = row1[8].length() - row2[8].length(); // KEY_SEQ + if (result == 0) { + result = row1[8].compareTo(row2[8]); + } } } } @@ -442,15 +449,16 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) throw new SQLException("'table' parameter in getImportedKeys cannot be null"); } - if (catalog == null || catalog.isEmpty()) { - return getImportedKeysUsingInformationSchema(catalog, table); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schema; + if (database == null || database.isEmpty()) { + return getImportedKeysUsingInformationSchema(database, table); } try { - return getImportedKeysUsingShowCreateTable(catalog, table); + return getImportedKeysUsingShowCreateTable(database, table); } catch (Exception e) { // Likely, parsing failed, try out I_S query. - return getImportedKeysUsingInformationSchema(catalog, table); + return getImportedKeysUsingInformationSchema(database, table); } } @@ -559,33 +567,42 @@ private String escapeQuote(String value) { * Generate part of the information schema query that restricts catalog names In the driver, * catalogs is the equivalent to MariaDB schemas. * + * @param firstCondition is the first condition ( must be a 'WHERE' or an 'AND') * @param columnName - column name in the information schema table - * @param catalog - catalog name. This driver does not (always) follow JDBC standard for following - * special values, due to ConnectorJ compatibility 1. empty string ("") - matches current - * catalog (i.e. database). JDBC standard says only tables without catalog should be returned - * - such tables do not exist in MariaDB. If there is no current catalog, then empty string - * matches any catalog. 2. null - if nullCatalogMeansCurrent=true (which is the default), then - * the handling is the same as for "" . i.e. return current catalog.JDBC-conforming way would - * be to match any catalog with null parameter. This can be switched with + * @param database - database name. This driver does not (always) follow JDBC standard for + * following special values, due to ConnectorJ compatibility 1. empty string ("") - matches + * current database. JDBC standard says only tables without database should be returned - such + * tables do not exist in MariaDB. If there is no current database, then empty string matches + * any database. 2. null - if nullCatalogMeansCurrent=true (which is the default), then the + * handling is the same as for "" . i.e. return current catalog.JDBC-conforming way would be + * to match any database with null parameter. This can be switched with * nullCatalogMeansCurrent=false in the connection URL. - * @return part of SQL query ,that restricts search for the catalog. + * @param usePattern can use pattern, or must it be strictly equal + * @return part of SQL query ,that restricts search for the database. */ - private boolean catalogCond( - boolean firstCondition, StringBuilder sb, String columnName, String catalog) { - // null catalog => searching without any catalog restriction - if (catalog == null) return firstCondition; - - // empty catalog => search restricting to current catalog - if (catalog.isEmpty()) { + private boolean databaseCond( + boolean firstCondition, + StringBuilder sb, + String columnName, + String database, + boolean usePattern) { + // null database => searching without any database restriction + if (database == null || ("%".equals(database) && usePattern)) return firstCondition; + + // empty database => search restricting to current database + if (database.isEmpty()) { sb.append(firstCondition ? " WHERE " : " AND ").append(columnName).append(" = database()"); return false; } - // search with specified catalog + // search with specified database sb.append(firstCondition ? " WHERE " : " AND ") .append(columnName) - .append("=") - .append(escapeQuote(catalog)); + .append( + !usePattern || (database.indexOf('%') == -1 && database.indexOf('_') == -1) + ? "=" + : " LIKE ") + .append(escapeQuote(database)); return false; } @@ -639,13 +656,18 @@ private boolean patternCond( public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { // MySQL 8 now use 'PRI' in place of 'pri' StringBuilder sb = - new StringBuilder( - "SELECT A.TABLE_SCHEMA TABLE_CAT, NULL TABLE_SCHEM, A.TABLE_NAME, A.COLUMN_NAME, B.SEQ_IN_INDEX KEY_SEQ, B.INDEX_NAME PK_NAME " - + " FROM INFORMATION_SCHEMA.COLUMNS A, INFORMATION_SCHEMA.STATISTICS B" - + " WHERE A.COLUMN_KEY in ('PRI','pri') AND B.INDEX_NAME='PRIMARY'"); - - catalogCond(false, sb, "A.TABLE_SCHEMA", catalog); - catalogCond(false, sb, "B.TABLE_SCHEMA", catalog); + new StringBuilder("SELECT ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "A.TABLE_SCHEMA TABLE_CAT, NULL TABLE_SCHEM" + : "A.TABLE_CATALOG TABLE_CAT, A.TABLE_SCHEMA TABLE_SCHEM") + .append( + ", A.TABLE_NAME, A.COLUMN_NAME, B.SEQ_IN_INDEX KEY_SEQ, B.INDEX_NAME PK_NAME " + + " FROM INFORMATION_SCHEMA.COLUMNS A, INFORMATION_SCHEMA.STATISTICS B" + + " WHERE A.COLUMN_KEY in ('PRI','pri') AND B.INDEX_NAME='PRIMARY'"); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schema; + databaseCond(false, sb, "A.TABLE_SCHEMA", database, false); + databaseCond(false, sb, "B.TABLE_SCHEMA", database, false); patternCond(false, sb, "A.TABLE_NAME", table); patternCond(false, sb, "B.TABLE_NAME", table); sb.append( @@ -703,8 +725,10 @@ public ResultSet getTables( + " TABLE_COMMENT REMARKS, NULL TYPE_CAT, NULL TYPE_SCHEM, NULL TYPE_NAME, NULL SELF_REFERENCING_COL_NAME, " + " NULL REF_GENERATION" + " FROM INFORMATION_SCHEMA.TABLES"); - boolean firstCondition = true; - firstCondition = catalogCond(true, sb, "TABLE_SCHEMA", catalog); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schemaPattern; + boolean firstCondition = + databaseCond( + true, sb, "TABLE_SCHEMA", database, conf.useCatalogTerm() == CatalogTerm.UseSchema); firstCondition = patternCond(firstCondition, sb, "TABLE_NAME", tableNamePattern); if (types != null && types.length > 0) { @@ -835,14 +859,19 @@ public ResultSet getColumns( // See https://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-4.html : version.versionGreaterOrEqual(5, 6, 4); StringBuilder sb = new StringBuilder(); - sb.append( - "SELECT TABLE_SCHEMA TABLE_CAT, NULL TABLE_SCHEM, TABLE_NAME, COLUMN_NAME," - + dataTypeClause("COLUMN_TYPE") - + " DATA_TYPE," - + DataTypeClause(conf) - + " TYPE_NAME, " - + " CASE DATA_TYPE" - + " WHEN 'date' THEN 10"); + sb.append("SELECT ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "TABLE_SCHEMA TABLE_CAT, NULL TABLE_SCHEM" + : "TABLE_CATALOG TABLE_CAT, TABLE_SCHEMA TABLE_SCHEM") + .append( + ", TABLE_NAME, COLUMN_NAME," + + dataTypeClause("COLUMN_TYPE") + + " DATA_TYPE," + + DataTypeClause(conf) + + " TYPE_NAME, " + + " CASE DATA_TYPE" + + " WHEN 'date' THEN 10"); if (supportsFractionalSeconds) { sb.append( " WHEN 'time' THEN " @@ -878,7 +907,10 @@ public ResultSet getColumns( + " IF(EXTRA = 'auto_increment','YES','NO') IS_AUTOINCREMENT, " + " IF(EXTRA in ('VIRTUAL', 'PERSISTENT', 'VIRTUAL GENERATED', 'STORED GENERATED') ,'YES','NO') IS_GENERATEDCOLUMN " + " FROM INFORMATION_SCHEMA.COLUMNS"); - boolean firstCondition = catalogCond(true, sb, "TABLE_SCHEMA", catalog); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schemaPattern; + boolean firstCondition = + databaseCond( + true, sb, "TABLE_SCHEMA", database, conf.useCatalogTerm() == CatalogTerm.UseSchema); firstCondition = patternCond(firstCondition, sb, "TABLE_NAME", tableNamePattern); firstCondition = patternCond(firstCondition, sb, "COLUMN_NAME", columnNamePattern); sb.append(" ORDER BY TABLE_CAT, TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION"); @@ -953,34 +985,50 @@ public ResultSet getColumns( public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { StringBuilder sb = - new StringBuilder( - "SELECT KCU.REFERENCED_TABLE_SCHEMA PKTABLE_CAT, NULL PKTABLE_SCHEM, KCU.REFERENCED_TABLE_NAME PKTABLE_NAME," - + " KCU.REFERENCED_COLUMN_NAME PKCOLUMN_NAME, KCU.TABLE_SCHEMA FKTABLE_CAT, NULL FKTABLE_SCHEM, " - + " KCU.TABLE_NAME FKTABLE_NAME, KCU.COLUMN_NAME FKCOLUMN_NAME, KCU.POSITION_IN_UNIQUE_CONSTRAINT KEY_SEQ," - + " CASE update_rule " - + " WHEN 'RESTRICT' THEN 1" - + " WHEN 'NO ACTION' THEN 3" - + " WHEN 'CASCADE' THEN 0" - + " WHEN 'SET NULL' THEN 2" - + " WHEN 'SET DEFAULT' THEN 4" - + " END UPDATE_RULE," - + " CASE DELETE_RULE" - + " WHEN 'RESTRICT' THEN 1" - + " WHEN 'NO ACTION' THEN 3" - + " WHEN 'CASCADE' THEN 0" - + " WHEN 'SET NULL' THEN 2" - + " WHEN 'SET DEFAULT' THEN 4" - + " END DELETE_RULE," - + " RC.CONSTRAINT_NAME FK_NAME," - + " RC.UNIQUE_CONSTRAINT_NAME PK_NAME," - + importedKeyNotDeferrable - + " DEFERRABILITY" - + " FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU" - + " INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC" - + " ON KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA" - + " AND KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME"); - boolean firstCondition = true; - firstCondition = catalogCond(firstCondition, sb, "KCU.REFERENCED_TABLE_SCHEMA", catalog); + new StringBuilder("SELECT ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "KCU.REFERENCED_TABLE_SCHEMA PKTABLE_CAT, NULL PKTABLE_SCHEM" + : "KCU.CONSTRAINT_CATALOG PKTABLE_CAT, KCU.REFERENCED_TABLE_SCHEMA PKTABLE_SCHEM") + .append( + ", KCU.REFERENCED_TABLE_NAME PKTABLE_NAME," + + " KCU.REFERENCED_COLUMN_NAME PKCOLUMN_NAME, ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "KCU.TABLE_SCHEMA FKTABLE_CAT, NULL FKTABLE_SCHEM" + : " TABLE_CATALOG FKTABLE_CAT, KCU.TABLE_SCHEMA FKTABLE_SCHEM") + .append( + ", KCU.TABLE_NAME FKTABLE_NAME, KCU.COLUMN_NAME FKCOLUMN_NAME, KCU.POSITION_IN_UNIQUE_CONSTRAINT KEY_SEQ," + + " CASE update_rule " + + " WHEN 'RESTRICT' THEN 1" + + " WHEN 'NO ACTION' THEN 3" + + " WHEN 'CASCADE' THEN 0" + + " WHEN 'SET NULL' THEN 2" + + " WHEN 'SET DEFAULT' THEN 4" + + " END UPDATE_RULE," + + " CASE DELETE_RULE" + + " WHEN 'RESTRICT' THEN 1" + + " WHEN 'NO ACTION' THEN 3" + + " WHEN 'CASCADE' THEN 0" + + " WHEN 'SET NULL' THEN 2" + + " WHEN 'SET DEFAULT' THEN 4" + + " END DELETE_RULE," + + " RC.CONSTRAINT_NAME FK_NAME," + + " RC.UNIQUE_CONSTRAINT_NAME PK_NAME," + + importedKeyNotDeferrable + + " DEFERRABILITY" + + " FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU" + + " INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC" + + " ON KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA" + + " AND KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME"); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schema; + boolean firstCondition = + databaseCond( + true, + sb, + "KCU.REFERENCED_TABLE_SCHEMA", + database, + conf.useCatalogTerm() == CatalogTerm.UseSchema); firstCondition = patternCond(firstCondition, sb, "KCU.REFERENCED_TABLE_NAME", table); sb.append(" ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, KEY_SEQ"); @@ -990,45 +1038,55 @@ public ResultSet getExportedKeys(String catalog, String schema, String table) /** * GetImportedKeysUsingInformationSchema. * - * @param catalog catalog + * @param database database * @param table table * @return resultset * @throws SQLException exception */ - public ResultSet getImportedKeysUsingInformationSchema(final String catalog, String table) + public ResultSet getImportedKeysUsingInformationSchema(final String database, String table) throws SQLException { if (table == null) { throw new SQLException("'table' parameter in getImportedKeys cannot be null"); } StringBuilder sb = - new StringBuilder( - "SELECT KCU.REFERENCED_TABLE_SCHEMA PKTABLE_CAT, NULL PKTABLE_SCHEM, KCU.REFERENCED_TABLE_NAME PKTABLE_NAME," - + " KCU.REFERENCED_COLUMN_NAME PKCOLUMN_NAME, KCU.TABLE_SCHEMA FKTABLE_CAT, NULL FKTABLE_SCHEM, " - + " KCU.TABLE_NAME FKTABLE_NAME, KCU.COLUMN_NAME FKCOLUMN_NAME, KCU.POSITION_IN_UNIQUE_CONSTRAINT KEY_SEQ," - + " CASE update_rule " - + " WHEN 'RESTRICT' THEN 1" - + " WHEN 'NO ACTION' THEN 3" - + " WHEN 'CASCADE' THEN 0" - + " WHEN 'SET NULL' THEN 2" - + " WHEN 'SET DEFAULT' THEN 4" - + " END UPDATE_RULE," - + " CASE DELETE_RULE" - + " WHEN 'RESTRICT' THEN 1" - + " WHEN 'NO ACTION' THEN 3" - + " WHEN 'CASCADE' THEN 0" - + " WHEN 'SET NULL' THEN 2" - + " WHEN 'SET DEFAULT' THEN 4" - + " END DELETE_RULE," - + " RC.CONSTRAINT_NAME FK_NAME," - + " RC.UNIQUE_CONSTRAINT_NAME PK_NAME," - + importedKeyNotDeferrable - + " DEFERRABILITY" - + " FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU" - + " INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC" - + " ON KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA" - + " AND KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME "); - - boolean firstCondition = catalogCond(true, sb, "KCU.TABLE_SCHEMA", catalog); + new StringBuilder("SELECT ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "KCU.REFERENCED_TABLE_SCHEMA PKTABLE_CAT, NULL PKTABLE_SCHEM" + : "KCU.TABLE_CATALOG PKTABLE_CAT, KCU.REFERENCED_TABLE_SCHEMA PKTABLE_SCHEM") + .append( + ", KCU.REFERENCED_TABLE_NAME PKTABLE_NAME," + + " KCU.REFERENCED_COLUMN_NAME PKCOLUMN_NAME, ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "KCU.TABLE_SCHEMA FKTABLE_CAT, NULL FKTABLE_SCHEM" + : "KCU.TABLE_CATALOG FKTABLE_CAT, KCU.TABLE_SCHEMA FKTABLE_SCHEM") + .append( + ", KCU.TABLE_NAME FKTABLE_NAME, KCU.COLUMN_NAME FKCOLUMN_NAME, KCU.POSITION_IN_UNIQUE_CONSTRAINT KEY_SEQ," + + " CASE update_rule " + + " WHEN 'RESTRICT' THEN 1" + + " WHEN 'NO ACTION' THEN 3" + + " WHEN 'CASCADE' THEN 0" + + " WHEN 'SET NULL' THEN 2" + + " WHEN 'SET DEFAULT' THEN 4" + + " END UPDATE_RULE," + + " CASE DELETE_RULE" + + " WHEN 'RESTRICT' THEN 1" + + " WHEN 'NO ACTION' THEN 3" + + " WHEN 'CASCADE' THEN 0" + + " WHEN 'SET NULL' THEN 2" + + " WHEN 'SET DEFAULT' THEN 4" + + " END DELETE_RULE," + + " RC.CONSTRAINT_NAME FK_NAME," + + " RC.UNIQUE_CONSTRAINT_NAME PK_NAME," + + importedKeyNotDeferrable + + " DEFERRABILITY" + + " FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU" + + " INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC" + + " ON KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA" + + " AND KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME "); + + boolean firstCondition = databaseCond(true, sb, "KCU.TABLE_SCHEMA", database, false); sb.append(firstCondition ? " WHERE " : " AND ") .append("KCU.TABLE_NAME = ") .append(escapeQuote(table)); @@ -1041,21 +1099,21 @@ public ResultSet getImportedKeysUsingInformationSchema(final String catalog, Str /** * GetImportedKeysUsingShowCreateTable. * - * @param catalog catalog + * @param database database * @param table table * @return resultset * @throws Exception exception */ - public ResultSet getImportedKeysUsingShowCreateTable(final String catalog, String table) + public ResultSet getImportedKeysUsingShowCreateTable(final String database, String table) throws Exception { ResultSet rs = connection .createStatement() .executeQuery( - "SHOW CREATE TABLE " + quoteIdentifier(catalog) + "." + quoteIdentifier(table)); + "SHOW CREATE TABLE " + quoteIdentifier(database) + "." + quoteIdentifier(table)); rs.next(); String tableDef = rs.getString(2); - return getImportedKeys(tableDef, table, catalog, connection); + return getImportedKeys(tableDef, table, database, connection); } /** @@ -1119,7 +1177,8 @@ public ResultSet getBestRowIdentifier( StringBuilder sbInner = new StringBuilder("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_KEY = 'PRI'"); - catalogCond(false, sbInner, "TABLE_SCHEMA", catalog); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schema; + databaseCond(false, sbInner, "TABLE_SCHEMA", database, false); sbInner.append(" AND TABLE_NAME = ").append(escapeQuote(table)); StringBuilder sb = @@ -1140,7 +1199,7 @@ public ResultSet getBestRowIdentifier( + " OR (COLUMN_KEY = 'UNI' AND NOT EXISTS (" + sbInner + " )))"); - catalogCond(false, sb, "TABLE_SCHEMA", catalog); + databaseCond(false, sb, "TABLE_SCHEMA", database, false); sb.append(" AND TABLE_NAME = ").append(escapeQuote(table)); if (!nullable) sb.append(" AND IS_NULLABLE = 'NO'"); @@ -1986,26 +2045,31 @@ public ResultSet getProcedures(String catalog, String schemaPattern, String proc throws SQLException { StringBuilder sb = - new StringBuilder( - "SELECT ROUTINE_SCHEMA PROCEDURE_CAT," - + "NULL PROCEDURE_SCHEM, " - + "ROUTINE_NAME PROCEDURE_NAME," - + " NULL RESERVED1," - + " NULL RESERVED2," - + " NULL RESERVED3," - + " ROUTINE_COMMENT REMARKS," - + " CASE ROUTINE_TYPE " - + " WHEN 'FUNCTION' THEN " - + procedureReturnsResult - + " WHEN 'PROCEDURE' THEN " - + procedureNoResult - + " ELSE " - + procedureResultUnknown - + " END PROCEDURE_TYPE," - + " SPECIFIC_NAME " - + " FROM INFORMATION_SCHEMA.ROUTINES "); - - boolean firstCondition = catalogCond(true, sb, "ROUTINE_SCHEMA", catalog); + new StringBuilder("SELECT ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "ROUTINE_SCHEMA PROCEDURE_CAT, NULL PROCEDURE_SCHEM" + : "ROUTINE_CATALOG PROCEDURE_CAT, ROUTINE_SCHEMA PROCEDURE_SCHEM") + .append( + ", ROUTINE_NAME PROCEDURE_NAME," + + " NULL RESERVED1," + + " NULL RESERVED2," + + " NULL RESERVED3," + + " ROUTINE_COMMENT REMARKS," + + " CASE ROUTINE_TYPE " + + " WHEN 'FUNCTION' THEN " + + procedureReturnsResult + + " WHEN 'PROCEDURE' THEN " + + procedureNoResult + + " ELSE " + + procedureResultUnknown + + " END PROCEDURE_TYPE," + + " SPECIFIC_NAME " + + " FROM INFORMATION_SCHEMA.ROUTINES "); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schemaPattern; + boolean firstCondition = + databaseCond( + true, sb, "ROUTINE_SCHEMA", database, conf.useCatalogTerm() == CatalogTerm.UseSchema); firstCondition = patternCond(firstCondition, sb, "ROUTINE_NAME", procedureNamePattern); return executeQuery(sb.toString()); @@ -2167,8 +2231,10 @@ public ResultSet getProcedureColumns( + " NULLABLE,NULL REMARKS,NULL COLUMN_DEF,0 SQL_DATA_TYPE,0 SQL_DATETIME_SUB," + "CHARACTER_OCTET_LENGTH CHAR_OCTET_LENGTH ,ORDINAL_POSITION, '' IS_NULLABLE, SPECIFIC_NAME " + " FROM INFORMATION_SCHEMA.PARAMETERS"); - - boolean firstCondition = catalogCond(true, sb, "SPECIFIC_SCHEMA", catalog); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schemaPattern; + boolean firstCondition = + databaseCond( + true, sb, "SPECIFIC_SCHEMA", database, conf.useCatalogTerm() == CatalogTerm.UseCatalog); firstCondition = patternCond(firstCondition, sb, "SPECIFIC_NAME", procedureNamePattern); firstCondition = patternCond(firstCondition, sb, "PARAMETER_NAME", columnNamePattern); sb.append(" ORDER BY SPECIFIC_SCHEMA, SPECIFIC_NAME, ORDINAL_POSITION"); @@ -2266,28 +2332,35 @@ public ResultSet getFunctionColumns( throws SQLException { StringBuilder sb = - new StringBuilder( - "SELECT SPECIFIC_SCHEMA `FUNCTION_CAT`, NULL `FUNCTION_SCHEM`, SPECIFIC_NAME FUNCTION_NAME," - + " PARAMETER_NAME COLUMN_NAME, " - + " CASE PARAMETER_MODE " - + " WHEN 'IN' THEN " - + functionColumnIn - + " WHEN 'OUT' THEN " - + functionColumnOut - + " WHEN 'INOUT' THEN " - + functionColumnInOut - + " ELSE " - + functionReturn - + " END COLUMN_TYPE," - + dataTypeClause("DTD_IDENTIFIER") - + " DATA_TYPE," - + "DATA_TYPE TYPE_NAME,NUMERIC_PRECISION `PRECISION`,CHARACTER_MAXIMUM_LENGTH LENGTH,NUMERIC_SCALE SCALE,10 RADIX," - + procedureNullableUnknown - + " NULLABLE,NULL REMARKS," - + "CHARACTER_OCTET_LENGTH CHAR_OCTET_LENGTH ,ORDINAL_POSITION, '' IS_NULLABLE, SPECIFIC_NAME " - + " FROM INFORMATION_SCHEMA.PARAMETERS"); - - boolean firstCondition = catalogCond(true, sb, "SPECIFIC_SCHEMA", catalog); + new StringBuilder("SELECT ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "SPECIFIC_SCHEMA `FUNCTION_CAT`, NULL `FUNCTION_SCHEM`" + : "SPECIFIC_CATALOG `FUNCTION_CAT`, SPECIFIC_SCHEMA `FUNCTION_SCHEM`") + .append( + ", SPECIFIC_NAME FUNCTION_NAME," + + " PARAMETER_NAME COLUMN_NAME, " + + " CASE PARAMETER_MODE " + + " WHEN 'IN' THEN " + + functionColumnIn + + " WHEN 'OUT' THEN " + + functionColumnOut + + " WHEN 'INOUT' THEN " + + functionColumnInOut + + " ELSE " + + functionReturn + + " END COLUMN_TYPE," + + dataTypeClause("DTD_IDENTIFIER") + + " DATA_TYPE," + + "DATA_TYPE TYPE_NAME,NUMERIC_PRECISION `PRECISION`,CHARACTER_MAXIMUM_LENGTH LENGTH,NUMERIC_SCALE SCALE,10 RADIX," + + procedureNullableUnknown + + " NULLABLE,NULL REMARKS," + + "CHARACTER_OCTET_LENGTH CHAR_OCTET_LENGTH ,ORDINAL_POSITION, '' IS_NULLABLE, SPECIFIC_NAME " + + " FROM INFORMATION_SCHEMA.PARAMETERS"); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schemaPattern; + boolean firstCondition = + databaseCond( + true, sb, "SPECIFIC_SCHEMA", database, conf.useCatalogTerm() == CatalogTerm.UseSchema); firstCondition = patternCond(firstCondition, sb, "SPECIFIC_NAME", functionNamePattern); firstCondition = patternCond(firstCondition, sb, "PARAMETER_NAME", columnNamePattern); sb.append(firstCondition ? " WHERE " : " AND ") @@ -2297,15 +2370,31 @@ public ResultSet getFunctionColumns( } public ResultSet getSchemas() throws SQLException { - return executeQuery("SELECT '' TABLE_SCHEM, '' TABLE_catalog FROM DUAL WHERE 1=0"); + if (conf.useCatalogTerm() == CatalogTerm.UseSchema) { + return executeQuery( + "SELECT SCHEMA_NAME as TABLE_SCHEM, CATALOG_NAME as TABLE_CATALOG FROM information_schema.SCHEMATA ORDER BY SCHEMA_NAME"); + } + return executeQuery("SELECT '' TABLE_SCHEM, '' TABLE_CATALOG FROM DUAL WHERE 1=0"); } public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { - return executeQuery("SELECT ' ' table_schem, ' ' table_catalog FROM DUAL WHERE 1=0"); + if (conf.useCatalogTerm() == CatalogTerm.UseSchema) { + StringBuilder sb = + new StringBuilder( + "SELECT SCHEMA_NAME as TABLE_SCHEM, CATALOG_NAME as TABLE_CATALOG FROM information_schema.SCHEMATA "); + boolean firstCondition = databaseCond(true, sb, "SCHEMA_NAME", schemaPattern, true); + sb.append(" ORDER BY SCHEMA_NAME"); + return executeQuery(sb.toString()); + } + return executeQuery("SELECT '' table_schem, '' table_catalog FROM DUAL WHERE 1=0"); } public ResultSet getCatalogs() throws SQLException { - return executeQuery("SELECT SCHEMA_NAME TABLE_CAT FROM INFORMATION_SCHEMA.SCHEMATA ORDER BY 1"); + if (conf.useCatalogTerm() == CatalogTerm.UseSchema) { + return executeQuery("SELECT null TABLE_CAT FROM DUAL WHERE 1=0"); + } + return executeQuery( + "SELECT SCHEMA_NAME TABLE_CAT FROM INFORMATION_SCHEMA.SCHEMATA ORDER BY SCHEMA_NAME"); } public ResultSet getTableTypes() throws SQLException { @@ -2364,7 +2453,8 @@ public ResultSet getColumnPrivileges( + "PRIVILEGE_TYPE AS PRIVILEGE, " + "IS_GRANTABLE " + "FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES"); - boolean firstCondition = catalogCond(true, sb, "TABLE_SCHEMA", catalog); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schema; + boolean firstCondition = databaseCond(true, sb, "TABLE_SCHEMA", database, false); sb.append(firstCondition ? " WHERE " : " AND ") .append(" TABLE_NAME = ") .append(escapeQuote(table)); @@ -2422,7 +2512,10 @@ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String + "PRIVILEGE_TYPE PRIVILEGE, " + "IS_GRANTABLE " + "FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES"); - boolean firstCondition = catalogCond(true, sb, "TABLE_SCHEMA", catalog); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schemaPattern; + boolean firstCondition = + databaseCond( + true, sb, "TABLE_SCHEMA", database, conf.useCatalogTerm() == CatalogTerm.UseSchema); firstCondition = patternCond(firstCondition, sb, "TABLE_NAME", tableNamePattern); sb.append(" ORDER BY TABLE_SCHEMA, TABLE_NAME, PRIVILEGE_TYPE "); @@ -2565,35 +2658,49 @@ public ResultSet getCrossReference( throws SQLException { StringBuilder sb = - new StringBuilder( - "SELECT KCU.REFERENCED_TABLE_SCHEMA PKTABLE_CAT, NULL PKTABLE_SCHEM, KCU.REFERENCED_TABLE_NAME PKTABLE_NAME," - + " KCU.REFERENCED_COLUMN_NAME PKCOLUMN_NAME, KCU.TABLE_SCHEMA FKTABLE_CAT, NULL FKTABLE_SCHEM, " - + " KCU.TABLE_NAME FKTABLE_NAME, KCU.COLUMN_NAME FKCOLUMN_NAME, KCU.POSITION_IN_UNIQUE_CONSTRAINT KEY_SEQ," - + " CASE update_rule " - + " WHEN 'RESTRICT' THEN 1" - + " WHEN 'NO ACTION' THEN 3" - + " WHEN 'CASCADE' THEN 0" - + " WHEN 'SET NULL' THEN 2" - + " WHEN 'SET DEFAULT' THEN 4" - + " END UPDATE_RULE," - + " CASE DELETE_RULE" - + " WHEN 'RESTRICT' THEN 1" - + " WHEN 'NO ACTION' THEN 3" - + " WHEN 'CASCADE' THEN 0" - + " WHEN 'SET NULL' THEN 2" - + " WHEN 'SET DEFAULT' THEN 4" - + " END DELETE_RULE," - + " RC.CONSTRAINT_NAME FK_NAME," - + " RC.UNIQUE_CONSTRAINT_NAME PK_NAME," - + importedKeyNotDeferrable - + " DEFERRABILITY " - + "FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU" - + " INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC" - + " ON KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA" - + " AND KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME "); - - boolean firstCondition = catalogCond(true, sb, "KCU.REFERENCED_TABLE_SCHEMA", parentCatalog); - firstCondition = catalogCond(firstCondition, sb, "KCU.TABLE_SCHEMA", foreignCatalog); + new StringBuilder("SELECT ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "KCU.REFERENCED_TABLE_SCHEMA PKTABLE_CAT, NULL PKTABLE_SCHEM" + : "KCU.TABLE_CATALOG PKTABLE_CAT, KCU.REFERENCED_TABLE_SCHEMA PKTABLE_SCHEM") + .append( + ", KCU.REFERENCED_TABLE_NAME PKTABLE_NAME," + + " KCU.REFERENCED_COLUMN_NAME PKCOLUMN_NAME, ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "KCU.TABLE_SCHEMA FKTABLE_CAT, NULL FKTABLE_SCHEM" + : "KCU.TABLE_CATALOG FKTABLE_CAT, KCU.TABLE_SCHEMA FKTABLE_SCHEM") + .append( + ", KCU.TABLE_NAME FKTABLE_NAME, KCU.COLUMN_NAME FKCOLUMN_NAME, KCU.POSITION_IN_UNIQUE_CONSTRAINT KEY_SEQ," + + " CASE update_rule " + + " WHEN 'RESTRICT' THEN 1" + + " WHEN 'NO ACTION' THEN 3" + + " WHEN 'CASCADE' THEN 0" + + " WHEN 'SET NULL' THEN 2" + + " WHEN 'SET DEFAULT' THEN 4" + + " END UPDATE_RULE," + + " CASE DELETE_RULE" + + " WHEN 'RESTRICT' THEN 1" + + " WHEN 'NO ACTION' THEN 3" + + " WHEN 'CASCADE' THEN 0" + + " WHEN 'SET NULL' THEN 2" + + " WHEN 'SET DEFAULT' THEN 4" + + " END DELETE_RULE," + + " RC.CONSTRAINT_NAME FK_NAME," + + " RC.UNIQUE_CONSTRAINT_NAME PK_NAME," + + importedKeyNotDeferrable + + " DEFERRABILITY " + + "FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU" + + " INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC" + + " ON KCU.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA" + + " AND KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME "); + String parentDatabase = + conf.useCatalogTerm() == CatalogTerm.UseCatalog ? parentCatalog : parentSchema; + String foreignDatabase = + conf.useCatalogTerm() == CatalogTerm.UseCatalog ? foreignCatalog : foreignSchema; + boolean firstCondition = + databaseCond(true, sb, "KCU.REFERENCED_TABLE_SCHEMA", parentDatabase, false); + firstCondition = databaseCond(firstCondition, sb, "KCU.TABLE_SCHEMA", foreignDatabase, false); firstCondition = patternCond(firstCondition, sb, "KCU.REFERENCED_TABLE_NAME", parentTable); firstCondition = patternCond(firstCondition, sb, "KCU.TABLE_NAME", foreignTable); sb.append("ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, KEY_SEQ"); @@ -3377,24 +3484,29 @@ public ResultSet getIndexInfo( throw new SQLException("'table' parameter must not be null"); } StringBuilder sb = - new StringBuilder( - "SELECT TABLE_SCHEMA TABLE_CAT, " - + "NULL TABLE_SCHEM, " - + "TABLE_NAME, " - + "NON_UNIQUE, " - + "TABLE_SCHEMA INDEX_QUALIFIER, " - + "INDEX_NAME, " - + tableIndexOther - + " TYPE, " - + "SEQ_IN_INDEX ORDINAL_POSITION, " - + "COLUMN_NAME, " - + "COLLATION ASC_OR_DESC, " - + "CARDINALITY, " - + "NULL PAGES, " - + "NULL FILTER_CONDITION" - + " FROM INFORMATION_SCHEMA.STATISTICS"); - - boolean firstCondition = catalogCond(true, sb, "TABLE_SCHEMA", catalog); + new StringBuilder("SELECT ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "TABLE_SCHEMA TABLE_CAT, NULL TABLE_SCHEM" + : "TABLE_CATALOG TABLE_CAT, TABLE_SCHEMA TABLE_SCHEM") + .append(", TABLE_NAME, " + "NON_UNIQUE, ") + .append( + conf.useCatalogTerm() == CatalogTerm.UseCatalog + ? "TABLE_SCHEMA INDEX_QUALIFIER" + : "TABLE_CATALOG INDEX_QUALIFIER") + .append( + ", INDEX_NAME, " + + tableIndexOther + + " TYPE, " + + "SEQ_IN_INDEX ORDINAL_POSITION, " + + "COLUMN_NAME, " + + "COLLATION ASC_OR_DESC, " + + "CARDINALITY, " + + "NULL PAGES, " + + "NULL FILTER_CONDITION" + + " FROM INFORMATION_SCHEMA.STATISTICS"); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schema; + boolean firstCondition = databaseCond(true, sb, "TABLE_SCHEMA", database, false); sb.append(firstCondition ? " WHERE " : " AND ") .append("TABLE_NAME = ") .append(escapeQuote(table)); @@ -3880,7 +3992,10 @@ public ResultSet getFunctions(String catalog, String schemaPattern, String funct + " FUNCTION_TYPE, " + "SPECIFIC_NAME " + " FROM INFORMATION_SCHEMA.ROUTINES"); - boolean firstCondition = catalogCond(true, sb, "ROUTINE_SCHEMA", catalog); + String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schemaPattern; + boolean firstCondition = + databaseCond( + true, sb, "ROUTINE_SCHEMA", database, conf.useCatalogTerm() == CatalogTerm.UseSchema); firstCondition = patternCond(firstCondition, sb, "ROUTINE_NAME", functionNamePattern); sb.append(firstCondition ? " WHERE " : " AND ").append(" ROUTINE_TYPE='FUNCTION'"); diff --git a/src/main/java/org/mariadb/jdbc/Driver.java b/src/main/java/org/mariadb/jdbc/Driver.java index db5da2728..e9e913d8a 100644 --- a/src/main/java/org/mariadb/jdbc/Driver.java +++ b/src/main/java/org/mariadb/jdbc/Driver.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/FunctionStatement.java b/src/main/java/org/mariadb/jdbc/FunctionStatement.java index c40df49df..1d5993480 100644 --- a/src/main/java/org/mariadb/jdbc/FunctionStatement.java +++ b/src/main/java/org/mariadb/jdbc/FunctionStatement.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/HostAddress.java b/src/main/java/org/mariadb/jdbc/HostAddress.java index f489b56b1..2a14bf066 100644 --- a/src/main/java/org/mariadb/jdbc/HostAddress.java +++ b/src/main/java/org/mariadb/jdbc/HostAddress.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; @@ -12,7 +12,7 @@ /** Host entry */ public class HostAddress { - + private long CONNECTED_VALUE_TIMEOUT = 3 * 60 * 1000; // 3 minutes /** host address */ public final String host; @@ -22,6 +22,9 @@ public class HostAddress { /** primary node */ public Boolean primary; + private Long threadsConnected; + private Long threadConnectedTimeout; + /** * Constructor. * @@ -190,4 +193,22 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(host, port, primary); } + + public void setThreadsConnected(long threadsConnected) { + this.threadsConnected = threadsConnected; + this.threadConnectedTimeout = System.currentTimeMillis() + CONNECTED_VALUE_TIMEOUT; + } + + public Long getThreadsConnected() { + return threadsConnected; + } + + public void forceThreadsConnected(long threadsConnected, long threadConnectedTimeout) { + this.threadsConnected = threadsConnected; + this.threadConnectedTimeout = threadConnectedTimeout; + } + + public Long getThreadConnectedTimeout() { + return threadConnectedTimeout; + } } diff --git a/src/main/java/org/mariadb/jdbc/MariaDbBlob.java b/src/main/java/org/mariadb/jdbc/MariaDbBlob.java index c0ff330af..b6dd1d99e 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbBlob.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbBlob.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/MariaDbClob.java b/src/main/java/org/mariadb/jdbc/MariaDbClob.java index a06cd206a..52f82109e 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbClob.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbClob.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/MariaDbDataSource.java b/src/main/java/org/mariadb/jdbc/MariaDbDataSource.java index f1060be2d..37889691c 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbDataSource.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbDataSource.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/MariaDbPoolConnection.java b/src/main/java/org/mariadb/jdbc/MariaDbPoolConnection.java index 340e68ca3..2ae12ad32 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbPoolConnection.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbPoolConnection.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/MariaDbPoolDataSource.java b/src/main/java/org/mariadb/jdbc/MariaDbPoolDataSource.java index 326a82f37..d04aedd74 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbPoolDataSource.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbPoolDataSource.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/MariaDbXid.java b/src/main/java/org/mariadb/jdbc/MariaDbXid.java index 3ba44e5e2..f206a1ee2 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbXid.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbXid.java @@ -1,3 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + package org.mariadb.jdbc; import java.util.Arrays; diff --git a/src/main/java/org/mariadb/jdbc/ParameterMetaData.java b/src/main/java/org/mariadb/jdbc/ParameterMetaData.java index 019e6723b..f20685f9f 100644 --- a/src/main/java/org/mariadb/jdbc/ParameterMetaData.java +++ b/src/main/java/org/mariadb/jdbc/ParameterMetaData.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/ProcedureStatement.java b/src/main/java/org/mariadb/jdbc/ProcedureStatement.java index b917cebe9..2e7818116 100644 --- a/src/main/java/org/mariadb/jdbc/ProcedureStatement.java +++ b/src/main/java/org/mariadb/jdbc/ProcedureStatement.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java b/src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java index 7dc982daf..563d42a2b 100644 --- a/src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java +++ b/src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; @@ -33,6 +33,7 @@ public class ServerPreparedStatement extends BasePreparedStatement { private static final Pattern PREPARABLE_STATEMENT_PATTERN = Pattern.compile("^(SELECT|UPDATE|INSERT|DELETE|REPLACE|DO|CALL)", Pattern.CASE_INSENSITIVE); private final boolean canCachePrepStmts; + /** * Server prepare statement constructor * @@ -155,7 +156,7 @@ private void executeStandard(String cmd) throws SQLException { false); } - private void executeInternalPreparedBatch() throws SQLException { + private boolean executeInternalPreparedBatch() throws SQLException { checkNotClosed(); String cmd = escapeTimeout(sql); if (batchParameters.size() > 1 && con.getContext().hasServerCapability(STMT_BULK_OPERATIONS)) { @@ -171,16 +172,21 @@ private void executeInternalPreparedBatch() throws SQLException { } if (!possibleLoadLocal) { - if (con.getContext().getConf().useBulkStmts() + Configuration conf = con.getContext().getConf(); + checkIfInsertCommand(); + if (((isCommandInsert && (conf.useBulkStmts() || conf.useBulkStmtsForInserts())) + || (!isCommandInsert && conf.useBulkStmts())) && autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS) { executeBatchBulk(cmd); + return isCommandInsert; } else { executeBatchPipeline(cmd); + return false; } - return; } } executeBatchStandard(cmd); + return false; } /** @@ -231,7 +237,6 @@ private void executeBatchBulk(String cmd) throws SQLException { closeOnCompletion, false); } - } catch (SQLException bue) { results = null; throw exceptionFactory() @@ -604,9 +609,24 @@ public int[] executeBatch() throws SQLException { if (batchParameters == null || batchParameters.isEmpty()) return new int[0]; lock.lock(); try { - executeInternalPreparedBatch(); + boolean wasBulkInsert = executeInternalPreparedBatch(); int[] updates = new int[batchParameters.size()]; + + // specific case for BULK INSERT + // return not Statement.SUCCESS_NO_INFO, but 1 + if (wasBulkInsert) { + int numberOfResult = 0; + for (int i = 0; i < results.size(); i++) { + numberOfResult += (int) ((OkPacket) results.get(i)).getAffectedRows(); + } + if (numberOfResult == updates.length) { + Arrays.fill(updates, 1); + currResult = results.remove(0); + return updates; + } + } + if (results.size() != updates.length) { for (int i = 0; i < updates.length; i++) { updates[i] = Statement.SUCCESS_NO_INFO; @@ -636,14 +656,29 @@ public long[] executeLargeBatch() throws SQLException { if (batchParameters == null || batchParameters.isEmpty()) return new long[0]; lock.lock(); try { - executeInternalPreparedBatch(); + boolean wasBulkInsert = executeInternalPreparedBatch(); long[] updates = new long[batchParameters.size()]; + + // specific case for BULK INSERT + // return not Statement.SUCCESS_NO_INFO, but 1 + if (wasBulkInsert) { + int numberOfResult = 0; + for (int i = 0; i < results.size(); i++) { + numberOfResult += (int) ((OkPacket) results.get(i)).getAffectedRows(); + } + if (numberOfResult == updates.length) { + Arrays.fill(updates, 1L); + currResult = results.remove(0); + return updates; + } + } if (results.size() != updates.length) { for (int i = 0; i < updates.length; i++) { updates[i] = Statement.SUCCESS_NO_INFO; } } else { + for (int i = 0; i < updates.length; i++) { if (results.get(i) instanceof OkPacket) { updates[i] = ((OkPacket) results.get(i)).getAffectedRows(); diff --git a/src/main/java/org/mariadb/jdbc/SimpleParameterMetaData.java b/src/main/java/org/mariadb/jdbc/SimpleParameterMetaData.java index 96b63fca0..60730c1bd 100644 --- a/src/main/java/org/mariadb/jdbc/SimpleParameterMetaData.java +++ b/src/main/java/org/mariadb/jdbc/SimpleParameterMetaData.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/Statement.java b/src/main/java/org/mariadb/jdbc/Statement.java index b98ca2cd7..85a761439 100644 --- a/src/main/java/org/mariadb/jdbc/Statement.java +++ b/src/main/java/org/mariadb/jdbc/Statement.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; @@ -726,6 +726,7 @@ public int[] executeBatch() throws SQLException { if (batchQueries == null || batchQueries.isEmpty()) return new int[0]; lock.lock(); try { + this.autoGeneratedKeys = java.sql.Statement.RETURN_GENERATED_KEYS; // ensure pipelining is possible (no LOAD DATA/XML INFILE commands) boolean possibleLoadLocal = con.getContext().hasClientCapability(LOCAL_FILES); if (possibleLoadLocal) { @@ -881,28 +882,26 @@ public ResultSet getGeneratedKeys() throws SQLException { "Cannot return generated keys: query was not set with Statement.RETURN_GENERATED_KEYS"); } - if (currResult instanceof OkPacket) { - - OkPacket ok = ((OkPacket) currResult); - if (ok.getLastInsertId() != 0) { - List insertIds = new ArrayList<>(); - insertIds.add(new String[] {String.valueOf(ok.getLastInsertId())}); - for (Completion result : results) { - if (result instanceof OkPacket) { - insertIds.add(new String[] {String.valueOf(((OkPacket) result).getLastInsertId())}); - } - } - String[][] ids = insertIds.toArray(new String[0][]); - return CompleteResult.createResultSet( - "insert_id", - DataType.BIGINT, - ids, - con.getContext(), - ColumnFlags.AUTO_INCREMENT | ColumnFlags.UNSIGNED); + List insertIds = new ArrayList<>(); + if (currResult instanceof OkPacket && ((OkPacket) currResult).getLastInsertId() != 0) { + insertIds.add(new String[] {String.valueOf(((OkPacket) currResult).getLastInsertId())}); + } + for (Completion result : results) { + if (result instanceof OkPacket && ((OkPacket) result).getLastInsertId() != 0) { + insertIds.add(new String[] {String.valueOf(((OkPacket) result).getLastInsertId())}); } } + if (insertIds.isEmpty()) { + return new CompleteResult(new ColumnDecoder[0], new byte[0][], con.getContext()); + } - return new CompleteResult(new ColumnDecoder[0], new byte[0][], con.getContext()); + String[][] ids = insertIds.toArray(new String[0][]); + return CompleteResult.createResultSet( + "insert_id", + DataType.BIGINT, + ids, + con.getContext(), + ColumnFlags.AUTO_INCREMENT | ColumnFlags.UNSIGNED); } /** @@ -1479,9 +1478,9 @@ public long getLargeUpdateCount() throws SQLException { public long[] executeLargeBatch() throws SQLException { checkNotClosed(); if (batchQueries == null || batchQueries.isEmpty()) return new long[0]; - lock.lock(); try { + this.autoGeneratedKeys = java.sql.Statement.RETURN_GENERATED_KEYS; // ensure pipelining is possible (no LOAD DATA/XML INFILE commands) boolean possibleLoadLocal = con.getContext().hasClientCapability(LOCAL_FILES); if (possibleLoadLocal) { diff --git a/src/main/java/org/mariadb/jdbc/TransactionIsolation.java b/src/main/java/org/mariadb/jdbc/TransactionIsolation.java index 37b219f6b..a910ecbd8 100644 --- a/src/main/java/org/mariadb/jdbc/TransactionIsolation.java +++ b/src/main/java/org/mariadb/jdbc/TransactionIsolation.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc; diff --git a/src/main/java/org/mariadb/jdbc/client/Client.java b/src/main/java/org/mariadb/jdbc/client/Client.java index 95f535b0a..768a8a698 100644 --- a/src/main/java/org/mariadb/jdbc/client/Client.java +++ b/src/main/java/org/mariadb/jdbc/client/Client.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client; diff --git a/src/main/java/org/mariadb/jdbc/client/Column.java b/src/main/java/org/mariadb/jdbc/client/Column.java index 8032aa8d9..b7bd667c5 100644 --- a/src/main/java/org/mariadb/jdbc/client/Column.java +++ b/src/main/java/org/mariadb/jdbc/client/Column.java @@ -1,7 +1,18 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + package org.mariadb.jdbc.client; public interface Column { + /** + * get column catalog + * + * @return column catalog + */ + String getCatalog(); + /** * get column schema * diff --git a/src/main/java/org/mariadb/jdbc/client/ColumnDecoder.java b/src/main/java/org/mariadb/jdbc/client/ColumnDecoder.java index ae2a033ff..d95225f72 100644 --- a/src/main/java/org/mariadb/jdbc/client/ColumnDecoder.java +++ b/src/main/java/org/mariadb/jdbc/client/ColumnDecoder.java @@ -1,3 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + package org.mariadb.jdbc.client; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/org/mariadb/jdbc/client/Completion.java b/src/main/java/org/mariadb/jdbc/client/Completion.java index 678b19d88..27e7c1a05 100644 --- a/src/main/java/org/mariadb/jdbc/client/Completion.java +++ b/src/main/java/org/mariadb/jdbc/client/Completion.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client; diff --git a/src/main/java/org/mariadb/jdbc/client/Context.java b/src/main/java/org/mariadb/jdbc/client/Context.java index 59c019ed0..500e79058 100644 --- a/src/main/java/org/mariadb/jdbc/client/Context.java +++ b/src/main/java/org/mariadb/jdbc/client/Context.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client; @@ -135,7 +135,7 @@ public interface Context { * * @return connection transaction isolation level */ - int getTransactionIsolationLevel(); + Integer getTransactionIsolationLevel(); /** * Set current connection transaction isolation level @@ -170,4 +170,28 @@ public interface Context { * @param state indicate that some connection state has changed */ void addStateFlag(int state); + + /** + * Indicate server charset change + * + * @param charset server charset + */ + void setCharset(String charset); + + /** + * Indicate server connection Id (not truncated) + * + * @param connectionId connection id + */ + void setThreadId(long connectionId); + + /** Indicate the number of connection on this server */ + void setTreadsConnected(long threadsConnected); + + /** + * Retrieve current charset if session state get it + * + * @return current charset + */ + String getCharset(); } diff --git a/src/main/java/org/mariadb/jdbc/client/DataType.java b/src/main/java/org/mariadb/jdbc/client/DataType.java index 4b5c5a260..8a3ca8c5d 100644 --- a/src/main/java/org/mariadb/jdbc/client/DataType.java +++ b/src/main/java/org/mariadb/jdbc/client/DataType.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client; diff --git a/src/main/java/org/mariadb/jdbc/client/PrepareCache.java b/src/main/java/org/mariadb/jdbc/client/PrepareCache.java index 4b7af9f59..32e5f9dcb 100644 --- a/src/main/java/org/mariadb/jdbc/client/PrepareCache.java +++ b/src/main/java/org/mariadb/jdbc/client/PrepareCache.java @@ -1,3 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + package org.mariadb.jdbc.client; import org.mariadb.jdbc.ServerPreparedStatement; diff --git a/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java b/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java index 06c61a224..e811b38ab 100644 --- a/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java +++ b/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client; diff --git a/src/main/java/org/mariadb/jdbc/client/ServerVersion.java b/src/main/java/org/mariadb/jdbc/client/ServerVersion.java index 0ef817705..e789b2cf2 100644 --- a/src/main/java/org/mariadb/jdbc/client/ServerVersion.java +++ b/src/main/java/org/mariadb/jdbc/client/ServerVersion.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client; diff --git a/src/main/java/org/mariadb/jdbc/client/SocketHelper.java b/src/main/java/org/mariadb/jdbc/client/SocketHelper.java index c8916c8c7..fc34be30f 100644 --- a/src/main/java/org/mariadb/jdbc/client/SocketHelper.java +++ b/src/main/java/org/mariadb/jdbc/client/SocketHelper.java @@ -1,3 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + package org.mariadb.jdbc.client; import java.io.IOException; diff --git a/src/main/java/org/mariadb/jdbc/client/column/BigDecimalColumn.java b/src/main/java/org/mariadb/jdbc/client/column/BigDecimalColumn.java index 7b114a6e1..1994f71fa 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/BigDecimalColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/BigDecimalColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/BitColumn.java b/src/main/java/org/mariadb/jdbc/client/column/BitColumn.java index 4a58cb072..019af86cf 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/BitColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/BitColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/BlobColumn.java b/src/main/java/org/mariadb/jdbc/client/column/BlobColumn.java index 5c591b46a..23477674a 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/BlobColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/BlobColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; @@ -99,6 +99,7 @@ public int getPrecision() { if (!isBinary()) { Integer maxWidth2 = CharsetEncodingLength.maxCharlen.get(charset); if (maxWidth2 != null) return (int) (columnLength / maxWidth2); + return (int) columnLength / 4; } return (int) columnLength; } diff --git a/src/main/java/org/mariadb/jdbc/client/column/DateColumn.java b/src/main/java/org/mariadb/jdbc/client/column/DateColumn.java index b4f32704a..59b3ccda9 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/DateColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/DateColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/DoubleColumn.java b/src/main/java/org/mariadb/jdbc/client/column/DoubleColumn.java index 0484b769b..0291442c1 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/DoubleColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/DoubleColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/FloatColumn.java b/src/main/java/org/mariadb/jdbc/client/column/FloatColumn.java index a2f08594c..b4a283975 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/FloatColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/FloatColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/GeometryColumn.java b/src/main/java/org/mariadb/jdbc/client/column/GeometryColumn.java index 468c5a21c..9ba3a07d3 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/GeometryColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/GeometryColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/JsonColumn.java b/src/main/java/org/mariadb/jdbc/client/column/JsonColumn.java index a3fb29c3c..d27519810 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/JsonColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/JsonColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/SignedBigIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/SignedBigIntColumn.java index 9fe947697..b6e8b6884 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/SignedBigIntColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/SignedBigIntColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/SignedIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/SignedIntColumn.java index e48b08346..88766d1c8 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/SignedIntColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/SignedIntColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/SignedMediumIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/SignedMediumIntColumn.java index f58bcb46f..62d25fd0a 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/SignedMediumIntColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/SignedMediumIntColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/SignedSmallIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/SignedSmallIntColumn.java index 8495106d0..b7299e6a3 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/SignedSmallIntColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/SignedSmallIntColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/SignedTinyIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/SignedTinyIntColumn.java index dc8d49cc5..5853a5d3a 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/SignedTinyIntColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/SignedTinyIntColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/StringColumn.java b/src/main/java/org/mariadb/jdbc/client/column/StringColumn.java index bafbecab6..17e2388b9 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/StringColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/StringColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; @@ -99,7 +99,7 @@ public String getColumnTypeName(Configuration conf) { public int getPrecision() { Integer maxWidth = CharsetEncodingLength.maxCharlen.get(charset); if (maxWidth == null) { - return (int) columnLength; + return (int) columnLength / 4; } return (int) (columnLength / maxWidth); } diff --git a/src/main/java/org/mariadb/jdbc/client/column/TimeColumn.java b/src/main/java/org/mariadb/jdbc/client/column/TimeColumn.java index aefdd6dd7..d9d9e28c2 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/TimeColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/TimeColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/TimestampColumn.java b/src/main/java/org/mariadb/jdbc/client/column/TimestampColumn.java index 05238afd5..19f3f3840 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/TimestampColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/TimestampColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/UnsignedBigIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UnsignedBigIntColumn.java index be98ef2f8..b8f231cb9 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/UnsignedBigIntColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/UnsignedBigIntColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/UnsignedIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UnsignedIntColumn.java index 6fe7d2825..bf8b574e3 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/UnsignedIntColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/UnsignedIntColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/UnsignedMediumIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UnsignedMediumIntColumn.java index d05e49979..74725fb5f 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/UnsignedMediumIntColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/UnsignedMediumIntColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/UnsignedSmallIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UnsignedSmallIntColumn.java index cda4428cb..bd0608062 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/UnsignedSmallIntColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/UnsignedSmallIntColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/UnsignedTinyIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UnsignedTinyIntColumn.java index 8c43a2d44..040d6671c 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/UnsignedTinyIntColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/UnsignedTinyIntColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/UuidColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UuidColumn.java index 349e068c7..62093e93e 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/UuidColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/UuidColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/column/YearColumn.java b/src/main/java/org/mariadb/jdbc/client/column/YearColumn.java index 5c1445eaa..fddce5a0d 100644 --- a/src/main/java/org/mariadb/jdbc/client/column/YearColumn.java +++ b/src/main/java/org/mariadb/jdbc/client/column/YearColumn.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.column; diff --git a/src/main/java/org/mariadb/jdbc/client/context/BaseContext.java b/src/main/java/org/mariadb/jdbc/client/context/BaseContext.java index 3645d1e7c..d5e99a81c 100644 --- a/src/main/java/org/mariadb/jdbc/client/context/BaseContext.java +++ b/src/main/java/org/mariadb/jdbc/client/context/BaseContext.java @@ -1,12 +1,13 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.context; import static org.mariadb.jdbc.util.constants.Capabilities.STMT_BULK_OPERATIONS; import org.mariadb.jdbc.Configuration; +import org.mariadb.jdbc.HostAddress; import org.mariadb.jdbc.client.Context; import org.mariadb.jdbc.client.PrepareCache; import org.mariadb.jdbc.client.ServerVersion; @@ -17,7 +18,7 @@ /** Context (current connection state) of a connection */ public class BaseContext implements Context { - private final long threadId; + private long threadId; private final long serverCapabilities; private final long clientCapabilities; private final byte[] seed; @@ -28,6 +29,8 @@ public class BaseContext implements Context { private final Configuration conf; private final ExceptionFactory exceptionFactory; + private String charset; + /** Server status context */ protected int serverStatus; @@ -35,7 +38,7 @@ public class BaseContext implements Context { private String database; /** Server current transaction isolation level */ - private int transactionIsolationLevel; + private Integer transactionIsolationLevel; /** Server current warning count */ private int warning; @@ -46,9 +49,12 @@ public class BaseContext implements Context { /** Connection state use flag */ private int stateFlag = 0; + private final HostAddress hostAddress; + /** * Constructor of connection context * + * @param hostAddress host address * @param handshake server handshake * @param clientCapabilities client capabilities * @param conf connection configuration @@ -56,11 +62,13 @@ public class BaseContext implements Context { * @param prepareCache LRU prepare cache */ public BaseContext( + HostAddress hostAddress, InitialHandshakePacket handshake, long clientCapabilities, Configuration conf, ExceptionFactory exceptionFactory, PrepareCache prepareCache) { + this.hostAddress = hostAddress; this.threadId = handshake.getThreadId(); this.seed = handshake.getSeed(); this.serverCapabilities = handshake.getCapabilities(); @@ -144,7 +152,7 @@ public Configuration getConf() { return conf; } - public int getTransactionIsolationLevel() { + public Integer getTransactionIsolationLevel() { return transactionIsolationLevel; } @@ -171,4 +179,20 @@ public void resetStateFlag() { public void addStateFlag(int state) { stateFlag |= state; } + + public void setCharset(String charset) { + this.charset = charset; + } + + public void setThreadId(long connectionId) { + threadId = connectionId; + } + + public void setTreadsConnected(long threadsConnected) { + if (hostAddress != null) hostAddress.setThreadsConnected(threadsConnected); + } + + public String getCharset() { + return charset; + } } diff --git a/src/main/java/org/mariadb/jdbc/client/context/RedoContext.java b/src/main/java/org/mariadb/jdbc/client/context/RedoContext.java index dd809ab7c..43d128e9f 100644 --- a/src/main/java/org/mariadb/jdbc/client/context/RedoContext.java +++ b/src/main/java/org/mariadb/jdbc/client/context/RedoContext.java @@ -1,10 +1,11 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.context; import org.mariadb.jdbc.Configuration; +import org.mariadb.jdbc.HostAddress; import org.mariadb.jdbc.client.PrepareCache; import org.mariadb.jdbc.client.impl.TransactionSaver; import org.mariadb.jdbc.export.ExceptionFactory; @@ -21,6 +22,7 @@ public class RedoContext extends BaseContext { /** * Constructor * + * @param hostAddress host address * @param handshake server handshake * @param clientCapabilities client capabilities * @param conf configuration @@ -28,12 +30,13 @@ public class RedoContext extends BaseContext { * @param prepareCache LRU prepare cache */ public RedoContext( + HostAddress hostAddress, InitialHandshakePacket handshake, long clientCapabilities, Configuration conf, ExceptionFactory exceptionFactory, PrepareCache prepareCache) { - super(handshake, clientCapabilities, conf, exceptionFactory, prepareCache); + super(hostAddress, handshake, clientCapabilities, conf, exceptionFactory, prepareCache); this.transactionSaver = new TransactionSaver(conf.transactionReplaySize()); } diff --git a/src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java b/src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java index 514a1173e..fb5ba8b63 100644 --- a/src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java +++ b/src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.impl; @@ -30,7 +30,7 @@ import org.mariadb.jdbc.message.client.SslRequestPacket; import org.mariadb.jdbc.message.server.AuthSwitchPacket; import org.mariadb.jdbc.message.server.ErrorPacket; -import org.mariadb.jdbc.message.server.InitialHandshakePacket; +import org.mariadb.jdbc.message.server.OkPacket; import org.mariadb.jdbc.plugin.AuthenticationPlugin; import org.mariadb.jdbc.plugin.Credential; import org.mariadb.jdbc.plugin.CredentialPlugin; @@ -181,7 +181,7 @@ public static long initializeClientCapabilities( capabilities |= Capabilities.CLIENT_INTERACTIVE; } - if (configuration.useBulkStmts()) { + if (configuration.useBulkStmts() || configuration.useBulkStmtsForInserts()) { capabilities |= Capabilities.STMT_BULK_OPERATIONS; } @@ -223,24 +223,6 @@ public static long initializeClientCapabilities( return capabilities & serverCapabilities; } - /** - * Default collation used for string exchanges with server. Always return 4 bytes utf8 collation - * for server that permit it. - * - * @param handshake initial handshake packet - * @return collation byte - */ - public static byte decideLanguage(InitialHandshakePacket handshake) { - short serverLanguage = handshake.getDefaultCollation(); - // return current server utf8mb4 collation - return (byte) - ((serverLanguage == 45 // utf8mb4_general_ci - || serverLanguage == 46 // utf8mb4_bin - || (serverLanguage >= 224 && serverLanguage <= 247)) - ? serverLanguage - : 224); // UTF8MB4_UNICODE_CI; - } - /** * Authentication swtich handler * @@ -292,11 +274,7 @@ public static void authenticationHandler( // OK_Packet -> Authenticated ! // see https://mariadb.com/kb/en/library/ok_packet/ // ************************************************************************************* - buf.skip(); // 0x00 OkPacket Header - buf.readLongLengthEncodedNotNull(); // skip affectedRows - buf.readLongLengthEncodedNotNull(); // skip insert id - // insertId - context.setServerStatus(buf.readShort()); + new OkPacket(buf, context); break authentication_loop; default: diff --git a/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java index 3f56543a8..5e4a2ba37 100644 --- a/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java +++ b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java index 824491160..c736136c9 100644 --- a/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java +++ b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java b/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java index 1500643e7..4e77e2588 100644 --- a/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java +++ b/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/impl/ReplayClient.java b/src/main/java/org/mariadb/jdbc/client/impl/ReplayClient.java index 7278bd834..70b0b0603 100644 --- a/src/main/java/org/mariadb/jdbc/client/impl/ReplayClient.java +++ b/src/main/java/org/mariadb/jdbc/client/impl/ReplayClient.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/impl/StandardClient.java b/src/main/java/org/mariadb/jdbc/client/impl/StandardClient.java index 9a91bb3f3..2b50e1ebd 100644 --- a/src/main/java/org/mariadb/jdbc/client/impl/StandardClient.java +++ b/src/main/java/org/mariadb/jdbc/client/impl/StandardClient.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.impl; @@ -110,7 +110,9 @@ public StandardClient( assignStream(out, in, conf, null); - if (conf.socketTimeout() > 0) setSocketTimeout(conf.socketTimeout()); + if (conf.connectTimeout() > 0) { + setSocketTimeout(conf.connectTimeout()); + } else if (conf.socketTimeout() > 0) setSocketTimeout(conf.socketTimeout()); // read server handshake ReadableByteBuf buf = reader.readReusablePacket(logger.isTraceEnabled()); @@ -128,12 +130,14 @@ public StandardClient( this.context = conf.transactionReplay() ? new RedoContext( + hostAddress, handshake, clientCapabilities, conf, this.exceptionFactory, new PrepareCache(conf.prepStmtCacheSize(), this)) : new BaseContext( + hostAddress, handshake, clientCapabilities, conf, @@ -143,14 +147,17 @@ public StandardClient( this.reader.setServerThreadId(handshake.getThreadId(), hostAddress); this.writer.setServerThreadId(handshake.getThreadId(), hostAddress); - byte exchangeCharset = ConnectionHelper.decideLanguage(handshake); - // ********************************************************************** // changing to SSL socket if needed // ********************************************************************** SSLSocket sslSocket = ConnectionHelper.sslWrapper( - hostAddress, socket, clientCapabilities, exchangeCharset, context, writer); + hostAddress, + socket, + clientCapabilities, + (byte) handshake.getDefaultCollation(), + context, + writer); if (sslSocket != null) { out = new BufferedOutputStream(sslSocket.getOutputStream(), 16384); @@ -178,7 +185,7 @@ public StandardClient( conf, host, clientCapabilities, - exchangeCharset) + (byte) handshake.getDefaultCollation()) .encode(writer, context); writer.flush(); @@ -201,6 +208,7 @@ public StandardClient( if (!skipPostCommands) { postConnectionQueries(); } + setSocketTimeout(conf.socketTimeout()); } catch (IOException ioException) { destroySocket(); @@ -308,7 +316,7 @@ private void postConnectionQueries() throws SQLException { } String serverTz = conf.timezone() != null ? handleTimezone() : null; - String sessionVariableQuery = createSessionVariableQuery(serverTz); + String sessionVariableQuery = createSessionVariableQuery(serverTz, context); if (sessionVariableQuery != null) commands.add(sessionVariableQuery); if (hostAddress != null @@ -324,6 +332,8 @@ private void postConnectionQueries() throws SQLException { commands.add(String.format("CREATE DATABASE IF NOT EXISTS `%s`", escapedDb)); commands.add(String.format("USE `%s`", escapedDb)); } + if (context.getCharset() == null || !"utf8mb4".equals(context.getCharset())) + commands.add("SET NAMES utf8mb4"); if (conf.initSql() != null) { commands.add(conf.initSql()); @@ -390,9 +400,10 @@ private void postConnectionQueries() throws SQLException { * Create session variable if configuration requires additional commands. * * @param serverTz server timezone + * @param context context * @return sql setting session command */ - public String createSessionVariableQuery(String serverTz) { + public String createSessionVariableQuery(String serverTz, Context context) { // In JDBC, connection must start in autocommit mode // [CONJ-269] we cannot rely on serverStatus & ServerStatus.AUTOCOMMIT before this command to // avoid this command. @@ -452,12 +463,12 @@ public String createSessionVariableQuery(String serverTz) { && ((major >= 8 && context.getVersion().versionGreaterOrEqual(8, 0, 3)) || (major < 8 && context.getVersion().versionGreaterOrEqual(5, 7, 20)))) { sessionCommands.add( - "transaction_isolation='" + conf.transactionIsolation().getValue() + "'"); + "@@session.transaction_isolation='" + conf.transactionIsolation().getValue() + "'"); } else { - sessionCommands.add("tx_isolation='" + conf.transactionIsolation().getValue() + "'"); + sessionCommands.add( + "@@session.tx_isolation='" + conf.transactionIsolation().getValue() + "'"); } } - if (!sessionCommands.isEmpty()) { return "set " + sessionCommands.stream().collect(Collectors.joining(",")); } diff --git a/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java b/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java index 62746b564..586d5a25c 100644 --- a/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java +++ b/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.impl; @@ -280,9 +280,11 @@ public byte[] readBytesNullEnd() { public StandardReadableByteBuf readLengthBuffer() { int len = this.readIntLengthEncodedNotNull(); - byte[] tmp = new byte[len]; - readBytes(tmp); - return new StandardReadableByteBuf(tmp, len); + + StandardReadableByteBuf b = new StandardReadableByteBuf(buf, pos + len); + b.pos = pos; + pos += len; + return b; } public String readString(int length) { diff --git a/src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java b/src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java index a9c8f5475..ace7eab12 100644 --- a/src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java +++ b/src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java b/src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java index e407ed5aa..100b8b598 100644 --- a/src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java +++ b/src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.result; diff --git a/src/main/java/org/mariadb/jdbc/client/result/Result.java b/src/main/java/org/mariadb/jdbc/client/result/Result.java index fe7ab994f..982f39aa9 100644 --- a/src/main/java/org/mariadb/jdbc/client/result/Result.java +++ b/src/main/java/org/mariadb/jdbc/client/result/Result.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.result; diff --git a/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java b/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java index 2f9628cfe..ee49039d4 100644 --- a/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java +++ b/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.result; @@ -10,6 +10,7 @@ import org.mariadb.jdbc.client.Column; import org.mariadb.jdbc.client.ColumnDecoder; import org.mariadb.jdbc.export.ExceptionFactory; +import org.mariadb.jdbc.util.constants.CatalogTerm; import org.mariadb.jdbc.util.constants.ColumnFlags; /** Result-set metadata */ @@ -165,6 +166,7 @@ public String getColumnName(final int idx) throws SQLException { * @throws SQLException if a database access error occurs */ public String getCatalogName(int column) throws SQLException { + if (conf.useCatalogTerm() == CatalogTerm.UseSchema) return getColumn(column).getCatalog(); return getColumn(column).getSchema(); } @@ -215,7 +217,8 @@ public String getTableName(final int column) throws SQLException { return getColumn(column).getTable(); } - public String getSchemaName(int column) { + public String getSchemaName(int column) throws SQLException { + if (conf.useCatalogTerm() == CatalogTerm.UseSchema) return getColumn(column).getSchema(); return ""; } diff --git a/src/main/java/org/mariadb/jdbc/client/result/StreamingResult.java b/src/main/java/org/mariadb/jdbc/client/result/StreamingResult.java index 24678c6a3..c3c9ce38c 100644 --- a/src/main/java/org/mariadb/jdbc/client/result/StreamingResult.java +++ b/src/main/java/org/mariadb/jdbc/client/result/StreamingResult.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.result; diff --git a/src/main/java/org/mariadb/jdbc/client/result/UpdatableResult.java b/src/main/java/org/mariadb/jdbc/client/result/UpdatableResult.java index 0947ba9a4..fc429b700 100644 --- a/src/main/java/org/mariadb/jdbc/client/result/UpdatableResult.java +++ b/src/main/java/org/mariadb/jdbc/client/result/UpdatableResult.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.result; diff --git a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/BinaryRowDecoder.java b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/BinaryRowDecoder.java index d247aeeea..47a36e1dd 100644 --- a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/BinaryRowDecoder.java +++ b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/BinaryRowDecoder.java @@ -1,3 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + package org.mariadb.jdbc.client.result.rowdecoder; import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH; diff --git a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/RowDecoder.java b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/RowDecoder.java index 2334ae47e..b39e6fc7d 100644 --- a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/RowDecoder.java +++ b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/RowDecoder.java @@ -1,3 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + package org.mariadb.jdbc.client.result.rowdecoder; import java.sql.Date; diff --git a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/TextRowDecoder.java b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/TextRowDecoder.java index 2a91c772d..42bf6c533 100644 --- a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/TextRowDecoder.java +++ b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/TextRowDecoder.java @@ -1,3 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + package org.mariadb.jdbc.client.result.rowdecoder; import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/Reader.java b/src/main/java/org/mariadb/jdbc/client/socket/Reader.java index 5dbf3f309..55aef8ecb 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/Reader.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/Reader.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/Writer.java b/src/main/java/org/mariadb/jdbc/client/socket/Writer.java index a9482e24d..4569d52a0 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/Writer.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/Writer.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java index c71690100..6c75f2ccf 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java index cd239c77e..7a9b2b8ac 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java index 0eaeefe35..ad8d980b0 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java index 26c09f1ba..e7234e2de 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java index 7504cc28d..9807bb937 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java index 83c9fb464..b58c1f331 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java index 33d8d51a9..99932408c 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java index b1b3d25e0..17ff0bbaa 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java index b0df28bee..5bac1f005 100644 --- a/src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java +++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.socket.impl; diff --git a/src/main/java/org/mariadb/jdbc/client/tls/HostnameVerifier.java b/src/main/java/org/mariadb/jdbc/client/tls/HostnameVerifier.java index 393f57f6a..cb0e9aa72 100644 --- a/src/main/java/org/mariadb/jdbc/client/tls/HostnameVerifier.java +++ b/src/main/java/org/mariadb/jdbc/client/tls/HostnameVerifier.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.tls; diff --git a/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509KeyManager.java b/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509KeyManager.java index e879285c5..de32f5c34 100644 --- a/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509KeyManager.java +++ b/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509KeyManager.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.tls; diff --git a/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509TrustingManager.java b/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509TrustingManager.java index 15c7b272f..ff463e2b6 100644 --- a/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509TrustingManager.java +++ b/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509TrustingManager.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.tls; diff --git a/src/main/java/org/mariadb/jdbc/client/util/MutableByte.java b/src/main/java/org/mariadb/jdbc/client/util/MutableByte.java index ccec43b17..fe043e266 100644 --- a/src/main/java/org/mariadb/jdbc/client/util/MutableByte.java +++ b/src/main/java/org/mariadb/jdbc/client/util/MutableByte.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.util; diff --git a/src/main/java/org/mariadb/jdbc/client/util/MutableInt.java b/src/main/java/org/mariadb/jdbc/client/util/MutableInt.java index 05ec48ec1..e97338ef3 100644 --- a/src/main/java/org/mariadb/jdbc/client/util/MutableInt.java +++ b/src/main/java/org/mariadb/jdbc/client/util/MutableInt.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.util; diff --git a/src/main/java/org/mariadb/jdbc/client/util/Parameter.java b/src/main/java/org/mariadb/jdbc/client/util/Parameter.java index 0f41bef31..3b260ee8b 100644 --- a/src/main/java/org/mariadb/jdbc/client/util/Parameter.java +++ b/src/main/java/org/mariadb/jdbc/client/util/Parameter.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.util; diff --git a/src/main/java/org/mariadb/jdbc/client/util/Parameters.java b/src/main/java/org/mariadb/jdbc/client/util/Parameters.java index dc42f18b3..6e8726b28 100644 --- a/src/main/java/org/mariadb/jdbc/client/util/Parameters.java +++ b/src/main/java/org/mariadb/jdbc/client/util/Parameters.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.client.util; diff --git a/src/main/java/org/mariadb/jdbc/codec/NonNullParameter.java b/src/main/java/org/mariadb/jdbc/codec/NonNullParameter.java index aca1704a6..a7df9f2f8 100644 --- a/src/main/java/org/mariadb/jdbc/codec/NonNullParameter.java +++ b/src/main/java/org/mariadb/jdbc/codec/NonNullParameter.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.codec; diff --git a/src/main/java/org/mariadb/jdbc/codec/Parameter.java b/src/main/java/org/mariadb/jdbc/codec/Parameter.java index 3367bf40e..2e66b4416 100644 --- a/src/main/java/org/mariadb/jdbc/codec/Parameter.java +++ b/src/main/java/org/mariadb/jdbc/codec/Parameter.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.codec; diff --git a/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java b/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java index bfcd18a41..990483b66 100644 --- a/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java +++ b/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.codec; diff --git a/src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java b/src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java index f8ab415c4..c85b37948 100644 --- a/src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java +++ b/src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.export; diff --git a/src/main/java/org/mariadb/jdbc/export/HaMode.java b/src/main/java/org/mariadb/jdbc/export/HaMode.java index 4a1267cb3..95d5ee26e 100644 --- a/src/main/java/org/mariadb/jdbc/export/HaMode.java +++ b/src/main/java/org/mariadb/jdbc/export/HaMode.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.export; @@ -16,6 +16,9 @@ public Optional getAvailableHost( List hostAddresses, ConcurrentMap denyList, boolean primary) { + HostAddress hostWithLessConnection = + getHostWithLessConnections(hostAddresses, denyList, primary); + if (hostWithLessConnection != null) return Optional.of(hostWithLessConnection); return HaMode.getAvailableRoundRobinHost(this, hostAddresses, denyList, primary); } }, @@ -37,6 +40,9 @@ public Optional getAvailableHost( List hostAddresses, ConcurrentMap denyList, boolean primary) { + HostAddress hostWithLessConnection = + getHostWithLessConnections(hostAddresses, denyList, primary); + if (hostWithLessConnection != null) return Optional.of(hostWithLessConnection); return HaMode.getAvailableRoundRobinHost(this, hostAddresses, denyList, primary); } }, @@ -58,6 +64,12 @@ public Optional getAvailableHost( this.value = value; } + /** For testing purpose only */ + public void resetLast() { + lastRoundRobinPrimaryHost = null; + lastRoundRobinSecondaryHost = null; + } + /** * Get HAMode from values or aliases * @@ -100,6 +112,46 @@ public static Optional getAvailableHostInOrder( return Optional.empty(); } + /** + * If all hosts not blacklisted connection number are known, choose the host with the less + * connections. + * + * @param hostAddresses host addresses + * @param denyList blacklist + * @param primary requires primary host + * @return the host with less connection, or null if unknown. + */ + public static HostAddress getHostWithLessConnections( + List hostAddresses, ConcurrentMap denyList, boolean primary) { + long currentTime = System.currentTimeMillis(); + HostAddress hostAddressWithLessConnections = null; + + for (HostAddress hostAddress : hostAddresses) { + if (hostAddress.primary == primary) { + if (denyList.containsKey(hostAddress)) { + // take in account denied server that have reached denied timeout + if (denyList.get(hostAddress) > System.currentTimeMillis()) { + continue; + } else { + denyList.remove(hostAddress); + } + } + + // All host must have recently been connected + if (hostAddress.getThreadConnectedTimeout() == null + || hostAddress.getThreadConnectedTimeout() < currentTime) { + return null; + } + if (hostAddressWithLessConnections == null + || hostAddressWithLessConnections.getThreadsConnected() + > hostAddress.getThreadsConnected()) { + hostAddressWithLessConnections = hostAddress; + } + } + } + return hostAddressWithLessConnections; + } + /** * return hosts of corresponding type (primary or not) without blacklisted hosts. hosts in * blacklist reaching blacklist timeout will be present, RoundRobin Order. diff --git a/src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java b/src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java index 253e7e942..23e0da7b4 100644 --- a/src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java +++ b/src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.export; diff --git a/src/main/java/org/mariadb/jdbc/export/Prepare.java b/src/main/java/org/mariadb/jdbc/export/Prepare.java index bb451aff7..de3a86cdb 100644 --- a/src/main/java/org/mariadb/jdbc/export/Prepare.java +++ b/src/main/java/org/mariadb/jdbc/export/Prepare.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.export; diff --git a/src/main/java/org/mariadb/jdbc/export/SslMode.java b/src/main/java/org/mariadb/jdbc/export/SslMode.java index 1878f1967..fa28d1552 100644 --- a/src/main/java/org/mariadb/jdbc/export/SslMode.java +++ b/src/main/java/org/mariadb/jdbc/export/SslMode.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.export; diff --git a/src/main/java/org/mariadb/jdbc/message/ClientMessage.java b/src/main/java/org/mariadb/jdbc/message/ClientMessage.java index e6f38154f..979832937 100644 --- a/src/main/java/org/mariadb/jdbc/message/ClientMessage.java +++ b/src/main/java/org/mariadb/jdbc/message/ClientMessage.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message; @@ -303,12 +303,12 @@ default boolean validateLocalFileName(String fileName, Context context) { */ static boolean validateLocalFileName( String sql, Parameters parameters, String fileName, Context context) { - Pattern pattern = - Pattern.compile( - "^(\\s*\\/\\*([^\\*]|\\*[^\\/])*\\*\\/)*\\s*LOAD\\s+(DATA|XML)\\s+((LOW_PRIORITY|CONCURRENT)\\s+)?LOCAL\\s+INFILE\\s+'" - + fileName - + "'", - Pattern.CASE_INSENSITIVE); + String reg = + "^(\\s*\\/\\*([^\\*]|\\*[^\\/])*\\*\\/)*\\s*LOAD\\s+(DATA|XML)\\s+((LOW_PRIORITY|CONCURRENT)\\s+)?LOCAL\\s+INFILE\\s+'" + + Pattern.quote(fileName.replace("\\", "\\\\")) + + "'"; + + Pattern pattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE); if (pattern.matcher(sql).find()) { return true; } @@ -321,7 +321,9 @@ static boolean validateLocalFileName( if (pattern.matcher(sql).find() && parameters.size() > 0) { String paramString = parameters.get(0).bestEffortStringValue(context); if (paramString != null) { - return paramString.toLowerCase().equals("'" + fileName.toLowerCase() + "'"); + return paramString + .toLowerCase() + .equals("'" + fileName.replace("\\", "\\\\").toLowerCase() + "'"); } return true; } diff --git a/src/main/java/org/mariadb/jdbc/message/ServerMessage.java b/src/main/java/org/mariadb/jdbc/message/ServerMessage.java index ad40b11f7..7028c3ebe 100644 --- a/src/main/java/org/mariadb/jdbc/message/ServerMessage.java +++ b/src/main/java/org/mariadb/jdbc/message/ServerMessage.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message; diff --git a/src/main/java/org/mariadb/jdbc/message/client/AuthMoreRawPacket.java b/src/main/java/org/mariadb/jdbc/message/client/AuthMoreRawPacket.java index 3edacc00a..ad84bce06 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/AuthMoreRawPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/AuthMoreRawPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/BulkExecutePacket.java b/src/main/java/org/mariadb/jdbc/message/client/BulkExecutePacket.java index d0a1a69d7..f5b70e984 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/BulkExecutePacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/BulkExecutePacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/ChangeDbPacket.java b/src/main/java/org/mariadb/jdbc/message/client/ChangeDbPacket.java index c0c1e202a..cdceafcc5 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/ChangeDbPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/ChangeDbPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/ClosePreparePacket.java b/src/main/java/org/mariadb/jdbc/message/client/ClosePreparePacket.java index ff417625a..575d6be4b 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/ClosePreparePacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/ClosePreparePacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; @@ -29,6 +29,7 @@ public ClosePreparePacket(int statementId) { /** send packet to socket */ @Override public int encode(Writer writer, Context context) throws IOException { + assert statementId != 0; writer.initPacket(); writer.writeByte(0x19); writer.writeInt(statementId); diff --git a/src/main/java/org/mariadb/jdbc/message/client/ExecutePacket.java b/src/main/java/org/mariadb/jdbc/message/client/ExecutePacket.java index 297559165..4f8e9b9eb 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/ExecutePacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/ExecutePacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/HandshakeResponse.java b/src/main/java/org/mariadb/jdbc/message/client/HandshakeResponse.java index d0a406e59..209e53a85 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/HandshakeResponse.java +++ b/src/main/java/org/mariadb/jdbc/message/client/HandshakeResponse.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/LongDataPacket.java b/src/main/java/org/mariadb/jdbc/message/client/LongDataPacket.java index 2caee049d..c54f5ec47 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/LongDataPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/LongDataPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/PingPacket.java b/src/main/java/org/mariadb/jdbc/message/client/PingPacket.java index 9504c5ba1..02870f223 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/PingPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/PingPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/PrepareExecutePacket.java b/src/main/java/org/mariadb/jdbc/message/client/PrepareExecutePacket.java index 9b8d6dfdc..8a5023733 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/PrepareExecutePacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/PrepareExecutePacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/PreparePacket.java b/src/main/java/org/mariadb/jdbc/message/client/PreparePacket.java index 111241948..e09b9eb99 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/PreparePacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/PreparePacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/QueryPacket.java b/src/main/java/org/mariadb/jdbc/message/client/QueryPacket.java index 98d2ee798..133403058 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/QueryPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/QueryPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java b/src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java index 7c76a6e78..62e71faa3 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/QuitPacket.java b/src/main/java/org/mariadb/jdbc/message/client/QuitPacket.java index 001f59cd4..211e6ab3e 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/QuitPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/QuitPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/RedoableClientMessage.java b/src/main/java/org/mariadb/jdbc/message/client/RedoableClientMessage.java index fed79a808..d1ec53f07 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/RedoableClientMessage.java +++ b/src/main/java/org/mariadb/jdbc/message/client/RedoableClientMessage.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/RedoableWithPrepareClientMessage.java b/src/main/java/org/mariadb/jdbc/message/client/RedoableWithPrepareClientMessage.java index 1891e62f7..34fa0717a 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/RedoableWithPrepareClientMessage.java +++ b/src/main/java/org/mariadb/jdbc/message/client/RedoableWithPrepareClientMessage.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/ResetPacket.java b/src/main/java/org/mariadb/jdbc/message/client/ResetPacket.java index 372b280d3..64141b391 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/ResetPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/ResetPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/client/SslRequestPacket.java b/src/main/java/org/mariadb/jdbc/message/client/SslRequestPacket.java index 642992a75..0009a5847 100644 --- a/src/main/java/org/mariadb/jdbc/message/client/SslRequestPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/client/SslRequestPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.client; diff --git a/src/main/java/org/mariadb/jdbc/message/server/AuthSwitchPacket.java b/src/main/java/org/mariadb/jdbc/message/server/AuthSwitchPacket.java index f12cb49a1..3beecb895 100644 --- a/src/main/java/org/mariadb/jdbc/message/server/AuthSwitchPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/server/AuthSwitchPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.server; diff --git a/src/main/java/org/mariadb/jdbc/message/server/CachedPrepareResultPacket.java b/src/main/java/org/mariadb/jdbc/message/server/CachedPrepareResultPacket.java index edf5219fa..4ae9166ec 100644 --- a/src/main/java/org/mariadb/jdbc/message/server/CachedPrepareResultPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/server/CachedPrepareResultPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.server; diff --git a/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java b/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java index 51bc56d0a..9ca8ade63 100644 --- a/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.server; @@ -69,6 +69,10 @@ public ColumnDefinitionPacket( this.extTypeFormat = extTypeFormat; } + public String getCatalog() { + return "def"; + } + public String getSchema() { buf.pos(stringPos[0]); return buf.readString(buf.readIntLengthEncodedNotNull()); @@ -124,6 +128,7 @@ public int getDisplaySize() { || dataType == DataType.LONGBLOB)) { Integer maxWidth = CharsetEncodingLength.maxCharlen.get(charset); if (maxWidth != null) return (int) (columnLength / maxWidth); + return (int) (columnLength / 4); } return (int) columnLength; } diff --git a/src/main/java/org/mariadb/jdbc/message/server/ErrorPacket.java b/src/main/java/org/mariadb/jdbc/message/server/ErrorPacket.java index 965e20295..822650897 100644 --- a/src/main/java/org/mariadb/jdbc/message/server/ErrorPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/server/ErrorPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.server; diff --git a/src/main/java/org/mariadb/jdbc/message/server/InitialHandshakePacket.java b/src/main/java/org/mariadb/jdbc/message/server/InitialHandshakePacket.java index 863a3660a..bb1492b20 100644 --- a/src/main/java/org/mariadb/jdbc/message/server/InitialHandshakePacket.java +++ b/src/main/java/org/mariadb/jdbc/message/server/InitialHandshakePacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.server; diff --git a/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java b/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java index 1eff4c4d6..d05fda5d6 100644 --- a/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.server; @@ -35,26 +35,41 @@ public OkPacket(ReadableByteBuf buf, Context context) { if (buf.readableBytes() > 0 && context.hasClientCapability(Capabilities.CLIENT_SESSION_TRACK)) { buf.skip(buf.readIntLengthEncodedNotNull()); // skip info while (buf.readableBytes() > 0) { - if (buf.readIntLengthEncodedNotNull() > 0) { - switch (buf.readByte()) { + ReadableByteBuf sessionStateBuf = buf.readLengthBuffer(); + while (sessionStateBuf.readableBytes() > 0) { + switch (sessionStateBuf.readByte()) { case StateChange.SESSION_TRACK_SYSTEM_VARIABLES: - buf.readIntLengthEncodedNotNull(); - String variable = buf.readString(buf.readIntLengthEncodedNotNull()); - Integer len = buf.readLength(); - String value = len == null ? null : buf.readString(len); - logger.debug("System variable change: {} = {}", variable, value); + ReadableByteBuf tmpBufsv; + do { + tmpBufsv = sessionStateBuf.readLengthBuffer(); + String variableSv = tmpBufsv.readString(tmpBufsv.readIntLengthEncodedNotNull()); + Integer lenSv = tmpBufsv.readLength(); + String valueSv = lenSv == null ? null : tmpBufsv.readString(lenSv); + logger.debug("System variable change: {} = {}", variableSv, valueSv); + switch (variableSv) { + case "character_set_client": + context.setCharset(valueSv); + break; + case "connection_id": + context.setThreadId(Long.parseLong(valueSv)); + break; + case "threads_Connected": + context.setTreadsConnected(Long.parseLong(valueSv)); + break; + } + } while (tmpBufsv.readableBytes() > 0); break; case StateChange.SESSION_TRACK_SCHEMA: - buf.readIntLengthEncodedNotNull(); - Integer dbLen = buf.readLength(); - String database = dbLen == null ? null : buf.readString(dbLen); + sessionStateBuf.readIntLengthEncodedNotNull(); + Integer dbLen = sessionStateBuf.readLength(); + String database = dbLen == null ? null : sessionStateBuf.readString(dbLen); context.setDatabase(database.isEmpty() ? null : database); logger.debug("Database change: is '{}'", database); break; default: - buf.skip(buf.readIntLengthEncodedNotNull()); + // buf.skip(buf.readIntLengthEncodedNotNull()); } } } diff --git a/src/main/java/org/mariadb/jdbc/message/server/PrepareResultPacket.java b/src/main/java/org/mariadb/jdbc/message/server/PrepareResultPacket.java index 1e1b57976..982159f12 100644 --- a/src/main/java/org/mariadb/jdbc/message/server/PrepareResultPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/server/PrepareResultPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.server; diff --git a/src/main/java/org/mariadb/jdbc/message/server/util/ServerVersionUtility.java b/src/main/java/org/mariadb/jdbc/message/server/util/ServerVersionUtility.java index 8e601b051..aa8905d8b 100644 --- a/src/main/java/org/mariadb/jdbc/message/server/util/ServerVersionUtility.java +++ b/src/main/java/org/mariadb/jdbc/message/server/util/ServerVersionUtility.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.message.server.util; diff --git a/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java index a87001628..6f06c3128 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin; diff --git a/src/main/java/org/mariadb/jdbc/plugin/Codec.java b/src/main/java/org/mariadb/jdbc/plugin/Codec.java index 2b5c0e214..8df9ee260 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/Codec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/Codec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin; diff --git a/src/main/java/org/mariadb/jdbc/plugin/Credential.java b/src/main/java/org/mariadb/jdbc/plugin/Credential.java index 9e07e9a4a..a5b71ab69 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/Credential.java +++ b/src/main/java/org/mariadb/jdbc/plugin/Credential.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin; diff --git a/src/main/java/org/mariadb/jdbc/plugin/CredentialPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/CredentialPlugin.java index e80d20b7a..de25dc904 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/CredentialPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/CredentialPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin; diff --git a/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java index 6b5abaa05..3c4cb93cd 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/AuthenticationPluginLoader.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/AuthenticationPluginLoader.java index 9e43b22da..4a997b7a4 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/AuthenticationPluginLoader.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/AuthenticationPluginLoader.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/ClearPasswordPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/ClearPasswordPlugin.java index f24048bde..0e4730f9b 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/ClearPasswordPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/ClearPasswordPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication.addon; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/SendGssApiAuthPacket.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/SendGssApiAuthPacket.java index ac447884a..8de9e88ba 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/SendGssApiAuthPacket.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/SendGssApiAuthPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication.addon; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssUtility.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssUtility.java index 1b6d3f506..07e8436f4 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssUtility.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssUtility.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication.addon.gssapi; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssapiAuth.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssapiAuth.java index e6e906cba..5f970ae88 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssapiAuth.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssapiAuth.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication.addon.gssapi; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/StandardGssapiAuthentication.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/StandardGssapiAuthentication.java index 190e85e25..3ce75b9ee 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/StandardGssapiAuthentication.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/StandardGssapiAuthentication.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication.addon.gssapi; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/WindowsNativeSspiAuthentication.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/WindowsNativeSspiAuthentication.java index 6d9c8d811..d87c376aa 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/WindowsNativeSspiAuthentication.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/WindowsNativeSspiAuthentication.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication.addon.gssapi; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/CachingSha2PasswordPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/CachingSha2PasswordPlugin.java index 0577efb15..0dbeeaeec 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/CachingSha2PasswordPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/CachingSha2PasswordPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication.standard; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/Ed25519PasswordPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/Ed25519PasswordPlugin.java index 735921e22..2968b3f04 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/Ed25519PasswordPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/Ed25519PasswordPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication.standard; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/NativePasswordPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/NativePasswordPlugin.java index 75cfa0413..3d8721e9b 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/NativePasswordPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/NativePasswordPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication.standard; diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/SendPamAuthPacket.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/SendPamAuthPacket.java index e965feec7..a9c40c3e0 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/SendPamAuthPacket.java +++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/SendPamAuthPacket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.authentication.standard; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java index 5a8fdca3e..01d1fda09 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java index cdaa01f6d..fa07f8300 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java index 780204460..45855bc5b 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java index 869e7def1..3f3107401 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java index 2681a20eb..9f1eca923 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java index a5b9d7699..fc9dda8f3 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java index 0555bc0be..e2a1cbbc1 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java index 2f2848e4e..718abab61 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java index b6c60d93c..f9dceeb55 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java index 5b3299fd7..58fb773dd 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java index a374d6a3a..5460d0929 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java index 6b5a6556a..3976a8172 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java index ff0806816..ecec9d2cf 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/InstantCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/InstantCodec.java index 579d45e2d..cb422f7c1 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/InstantCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/InstantCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java index d1b02831e..bb5ab8358 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java index 3a69aec3b..4a942c830 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java index fc2b84459..55c6ab154 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java index 3ab4269b8..b1d1057b9 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java index adb2d95f6..03e37bf08 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java index e4d844e42..9199baa7e 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java index b28fca9b3..ad23a9210 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java index a89a3fceb..9fe876fe2 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java index ad0d6cd53..220ed2861 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/OffsetDateTimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/OffsetDateTimeCodec.java index 0d448c6ec..79f454a1f 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/OffsetDateTimeCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/OffsetDateTimeCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java index 11315234b..d356c8120 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java index d5200c41b..fac094439 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java index e159aea68..38d5d8e1a 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java index 876b5d16a..217096557 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java index 1ccf3637d..829e4d4c0 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java index d62d3ea35..b42d34e01 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java index 13944876b..4d4ebf199 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/TimestampCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/TimestampCodec.java index 13fb18dbe..8c2b6cbdc 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/TimestampCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/TimestampCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/UuidCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/UuidCodec.java index 79987c7d2..16847e3c5 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/UuidCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/UuidCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ZonedDateTimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ZonedDateTimeCodec.java index 1a3718a3b..77f11420d 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/ZonedDateTimeCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ZonedDateTimeCodec.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.codec; diff --git a/src/main/java/org/mariadb/jdbc/plugin/credential/CredentialPluginLoader.java b/src/main/java/org/mariadb/jdbc/plugin/credential/CredentialPluginLoader.java index 62441dcf1..abf733587 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/credential/CredentialPluginLoader.java +++ b/src/main/java/org/mariadb/jdbc/plugin/credential/CredentialPluginLoader.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.credential; diff --git a/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsCredentialGenerator.java b/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsCredentialGenerator.java index 89305791f..3c5248ce0 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsCredentialGenerator.java +++ b/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsCredentialGenerator.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.credential.aws; diff --git a/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsIamCredentialPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsIamCredentialPlugin.java index 4524297be..1a7a9e86d 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsIamCredentialPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsIamCredentialPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.credential.aws; diff --git a/src/main/java/org/mariadb/jdbc/plugin/credential/env/EnvCredentialPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/credential/env/EnvCredentialPlugin.java index 883bb138e..46135245b 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/credential/env/EnvCredentialPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/credential/env/EnvCredentialPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.credential.env; diff --git a/src/main/java/org/mariadb/jdbc/plugin/credential/system/PropertiesCredentialPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/credential/system/PropertiesCredentialPlugin.java index 2ef777d8a..37180658d 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/credential/system/PropertiesCredentialPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/credential/system/PropertiesCredentialPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.credential.system; diff --git a/src/main/java/org/mariadb/jdbc/plugin/tls/TlsSocketPluginLoader.java b/src/main/java/org/mariadb/jdbc/plugin/tls/TlsSocketPluginLoader.java index 80cbe3069..d8a5cd7de 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/tls/TlsSocketPluginLoader.java +++ b/src/main/java/org/mariadb/jdbc/plugin/tls/TlsSocketPluginLoader.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.tls; diff --git a/src/main/java/org/mariadb/jdbc/plugin/tls/main/DefaultTlsSocketPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/tls/main/DefaultTlsSocketPlugin.java index feab50f33..c5f678c93 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/tls/main/DefaultTlsSocketPlugin.java +++ b/src/main/java/org/mariadb/jdbc/plugin/tls/main/DefaultTlsSocketPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.plugin.tls.main; @@ -35,6 +35,7 @@ public class DefaultTlsSocketPlugin implements TlsSocketPlugin { private static KeyManager loadClientCerts( String keyStoreUrl, String keyStorePassword, + String keyPassword, String storeType, ExceptionFactory exceptionFactory) throws SQLException { @@ -42,11 +43,17 @@ private static KeyManager loadClientCerts( try { try (InputStream inStream = loadFromUrl(keyStoreUrl)) { char[] keyStorePasswordChars = - keyStorePassword == null ? null : keyStorePassword.toCharArray(); + keyStorePassword == null + ? null + : (keyStorePassword == "") ? null : keyStorePassword.toCharArray(); + char[] keyStoreChars = + (keyPassword == null) + ? keyStorePasswordChars + : (keyPassword == "") ? null : keyPassword.toCharArray(); KeyStore ks = KeyStore.getInstance(storeType != null ? storeType : KeyStore.getDefaultType()); ks.load(inStream, keyStorePasswordChars); - return new MariaDbX509KeyManager(ks, keyStorePasswordChars); + return new MariaDbX509KeyManager(ks, keyStoreChars); } } catch (IOException | GeneralSecurityException ex) { throw exceptionFactory.create( @@ -82,7 +89,11 @@ public SSLSocketFactory getSocketFactory(Configuration conf, ExceptionFactory ex KeyStore ks; try { - ks = KeyStore.getInstance(KeyStore.getDefaultType()); + ks = + KeyStore.getInstance( + conf.trustStoreType() != null + ? conf.trustStoreType() + : KeyStore.getDefaultType()); } catch (GeneralSecurityException generalSecurityEx) { throw exceptionFactory.create( "Failed to create keystore instance", "08000", generalSecurityEx); @@ -129,7 +140,11 @@ public SSLSocketFactory getSocketFactory(Configuration conf, ExceptionFactory ex keyManager = new KeyManager[] { loadClientCerts( - conf.keyStore(), conf.keyStorePassword(), conf.keyStoreType(), exceptionFactory) + conf.keyStore(), + conf.keyStorePassword(), + conf.keyPassword(), + conf.keyStoreType(), + exceptionFactory) }; } else { String keyStore = System.getProperty("javax.net.ssl.keyStore"); @@ -140,7 +155,8 @@ public SSLSocketFactory getSocketFactory(Configuration conf, ExceptionFactory ex try { keyManager = new KeyManager[] { - loadClientCerts(keyStore, keyStorePassword, keyStoreType, exceptionFactory) + loadClientCerts( + keyStore, keyStorePassword, keyStorePassword, keyStoreType, exceptionFactory) }; } catch (SQLException queryException) { keyManager = null; diff --git a/src/main/java/org/mariadb/jdbc/pool/MariaDbInnerPoolConnection.java b/src/main/java/org/mariadb/jdbc/pool/MariaDbInnerPoolConnection.java index ae4d9965c..55639f073 100644 --- a/src/main/java/org/mariadb/jdbc/pool/MariaDbInnerPoolConnection.java +++ b/src/main/java/org/mariadb/jdbc/pool/MariaDbInnerPoolConnection.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.pool; diff --git a/src/main/java/org/mariadb/jdbc/pool/Pool.java b/src/main/java/org/mariadb/jdbc/pool/Pool.java index 953d1de37..0a03ca2cf 100644 --- a/src/main/java/org/mariadb/jdbc/pool/Pool.java +++ b/src/main/java/org/mariadb/jdbc/pool/Pool.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.pool; diff --git a/src/main/java/org/mariadb/jdbc/pool/PoolMBean.java b/src/main/java/org/mariadb/jdbc/pool/PoolMBean.java index 5114e5c78..ede26387b 100644 --- a/src/main/java/org/mariadb/jdbc/pool/PoolMBean.java +++ b/src/main/java/org/mariadb/jdbc/pool/PoolMBean.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.pool; diff --git a/src/main/java/org/mariadb/jdbc/pool/PoolThreadFactory.java b/src/main/java/org/mariadb/jdbc/pool/PoolThreadFactory.java index 910c67d9a..b75b5bee0 100644 --- a/src/main/java/org/mariadb/jdbc/pool/PoolThreadFactory.java +++ b/src/main/java/org/mariadb/jdbc/pool/PoolThreadFactory.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.pool; diff --git a/src/main/java/org/mariadb/jdbc/pool/Pools.java b/src/main/java/org/mariadb/jdbc/pool/Pools.java index 809e51639..f27cb063a 100644 --- a/src/main/java/org/mariadb/jdbc/pool/Pools.java +++ b/src/main/java/org/mariadb/jdbc/pool/Pools.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.pool; diff --git a/src/main/java/org/mariadb/jdbc/type/Geometry.java b/src/main/java/org/mariadb/jdbc/type/Geometry.java index 0cd27dffa..b2fd20937 100644 --- a/src/main/java/org/mariadb/jdbc/type/Geometry.java +++ b/src/main/java/org/mariadb/jdbc/type/Geometry.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.type; diff --git a/src/main/java/org/mariadb/jdbc/type/GeometryCollection.java b/src/main/java/org/mariadb/jdbc/type/GeometryCollection.java index af70ffa23..18ea83ce1 100644 --- a/src/main/java/org/mariadb/jdbc/type/GeometryCollection.java +++ b/src/main/java/org/mariadb/jdbc/type/GeometryCollection.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.type; diff --git a/src/main/java/org/mariadb/jdbc/type/LineString.java b/src/main/java/org/mariadb/jdbc/type/LineString.java index 9a4c1705c..bac4bfee9 100644 --- a/src/main/java/org/mariadb/jdbc/type/LineString.java +++ b/src/main/java/org/mariadb/jdbc/type/LineString.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.type; diff --git a/src/main/java/org/mariadb/jdbc/type/MultiLineString.java b/src/main/java/org/mariadb/jdbc/type/MultiLineString.java index 5bdd5f1ce..c06fd7b09 100644 --- a/src/main/java/org/mariadb/jdbc/type/MultiLineString.java +++ b/src/main/java/org/mariadb/jdbc/type/MultiLineString.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.type; diff --git a/src/main/java/org/mariadb/jdbc/type/MultiPoint.java b/src/main/java/org/mariadb/jdbc/type/MultiPoint.java index 27953807d..29736b804 100644 --- a/src/main/java/org/mariadb/jdbc/type/MultiPoint.java +++ b/src/main/java/org/mariadb/jdbc/type/MultiPoint.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.type; diff --git a/src/main/java/org/mariadb/jdbc/type/MultiPolygon.java b/src/main/java/org/mariadb/jdbc/type/MultiPolygon.java index e5cd79996..d90a1948c 100644 --- a/src/main/java/org/mariadb/jdbc/type/MultiPolygon.java +++ b/src/main/java/org/mariadb/jdbc/type/MultiPolygon.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.type; diff --git a/src/main/java/org/mariadb/jdbc/type/Point.java b/src/main/java/org/mariadb/jdbc/type/Point.java index ae0e06206..a84db24ff 100644 --- a/src/main/java/org/mariadb/jdbc/type/Point.java +++ b/src/main/java/org/mariadb/jdbc/type/Point.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.type; diff --git a/src/main/java/org/mariadb/jdbc/type/Polygon.java b/src/main/java/org/mariadb/jdbc/type/Polygon.java index 738c39d63..5e82fbc92 100644 --- a/src/main/java/org/mariadb/jdbc/type/Polygon.java +++ b/src/main/java/org/mariadb/jdbc/type/Polygon.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.type; diff --git a/src/main/java/org/mariadb/jdbc/util/CharsetEncodingLength.java b/src/main/java/org/mariadb/jdbc/util/CharsetEncodingLength.java index 033024aa6..c77e28926 100644 --- a/src/main/java/org/mariadb/jdbc/util/CharsetEncodingLength.java +++ b/src/main/java/org/mariadb/jdbc/util/CharsetEncodingLength.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util; @@ -93,6 +93,7 @@ public final class CharsetEncodingLength { maxCharlen.put(73, 1); maxCharlen.put(74, 1); maxCharlen.put(75, 1); + maxCharlen.put(76, 3); maxCharlen.put(77, 1); maxCharlen.put(78, 1); maxCharlen.put(79, 1); @@ -238,6 +239,72 @@ public final class CharsetEncodingLength { maxCharlen.put(245, 4); maxCharlen.put(246, 4); maxCharlen.put(247, 4); + maxCharlen.put(248, 4); + maxCharlen.put(249, 4); + maxCharlen.put(250, 4); + maxCharlen.put(255, 4); + maxCharlen.put(256, 4); + maxCharlen.put(257, 4); + maxCharlen.put(258, 4); + maxCharlen.put(259, 4); + maxCharlen.put(260, 4); + maxCharlen.put(261, 4); + maxCharlen.put(262, 4); + maxCharlen.put(263, 4); + maxCharlen.put(264, 4); + maxCharlen.put(265, 4); + maxCharlen.put(266, 4); + maxCharlen.put(267, 4); + maxCharlen.put(268, 4); + maxCharlen.put(269, 4); + maxCharlen.put(270, 4); + maxCharlen.put(271, 4); + maxCharlen.put(273, 4); + maxCharlen.put(274, 4); + maxCharlen.put(275, 4); + maxCharlen.put(277, 4); + maxCharlen.put(278, 4); + maxCharlen.put(279, 4); + maxCharlen.put(280, 4); + maxCharlen.put(281, 4); + maxCharlen.put(282, 4); + maxCharlen.put(283, 4); + maxCharlen.put(284, 4); + maxCharlen.put(285, 4); + maxCharlen.put(286, 4); + maxCharlen.put(287, 4); + maxCharlen.put(288, 4); + maxCharlen.put(289, 4); + maxCharlen.put(290, 4); + maxCharlen.put(291, 4); + maxCharlen.put(292, 4); + maxCharlen.put(293, 4); + maxCharlen.put(294, 4); + maxCharlen.put(296, 4); + maxCharlen.put(297, 4); + maxCharlen.put(298, 4); + maxCharlen.put(300, 4); + maxCharlen.put(303, 4); + maxCharlen.put(304, 4); + maxCharlen.put(305, 4); + maxCharlen.put(306, 4); + maxCharlen.put(307, 4); + maxCharlen.put(308, 4); + maxCharlen.put(309, 4); + maxCharlen.put(310, 4); + maxCharlen.put(311, 4); + maxCharlen.put(312, 4); + maxCharlen.put(313, 4); + maxCharlen.put(314, 4); + maxCharlen.put(315, 4); + maxCharlen.put(316, 4); + maxCharlen.put(317, 4); + maxCharlen.put(318, 4); + maxCharlen.put(319, 4); + maxCharlen.put(320, 4); + maxCharlen.put(321, 4); + maxCharlen.put(322, 4); + maxCharlen.put(323, 4); maxCharlen.put(576, 3); maxCharlen.put(577, 3); maxCharlen.put(578, 3); diff --git a/src/main/java/org/mariadb/jdbc/util/ClientParser.java b/src/main/java/org/mariadb/jdbc/util/ClientParser.java index 50d2ca5dc..148fc0c36 100644 --- a/src/main/java/org/mariadb/jdbc/util/ClientParser.java +++ b/src/main/java/org/mariadb/jdbc/util/ClientParser.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util; diff --git a/src/main/java/org/mariadb/jdbc/util/ConfigurableSocketFactory.java b/src/main/java/org/mariadb/jdbc/util/ConfigurableSocketFactory.java index 15507d336..f2475cb9b 100644 --- a/src/main/java/org/mariadb/jdbc/util/ConfigurableSocketFactory.java +++ b/src/main/java/org/mariadb/jdbc/util/ConfigurableSocketFactory.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util; diff --git a/src/main/java/org/mariadb/jdbc/util/NativeSql.java b/src/main/java/org/mariadb/jdbc/util/NativeSql.java index e3f894ccf..4e5075b5a 100644 --- a/src/main/java/org/mariadb/jdbc/util/NativeSql.java +++ b/src/main/java/org/mariadb/jdbc/util/NativeSql.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util; diff --git a/src/main/java/org/mariadb/jdbc/util/ParameterList.java b/src/main/java/org/mariadb/jdbc/util/ParameterList.java index 6e43e0797..950ab6650 100644 --- a/src/main/java/org/mariadb/jdbc/util/ParameterList.java +++ b/src/main/java/org/mariadb/jdbc/util/ParameterList.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util; diff --git a/src/main/java/org/mariadb/jdbc/util/PrepareResult.java b/src/main/java/org/mariadb/jdbc/util/PrepareResult.java index 4c071eca5..21740f45c 100644 --- a/src/main/java/org/mariadb/jdbc/util/PrepareResult.java +++ b/src/main/java/org/mariadb/jdbc/util/PrepareResult.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util; diff --git a/src/main/java/org/mariadb/jdbc/util/Security.java b/src/main/java/org/mariadb/jdbc/util/Security.java index 9595aa0ca..6ec0c4def 100644 --- a/src/main/java/org/mariadb/jdbc/util/Security.java +++ b/src/main/java/org/mariadb/jdbc/util/Security.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util; diff --git a/src/main/java/org/mariadb/jdbc/util/Version.java b/src/main/java/org/mariadb/jdbc/util/Version.java index 38f7700f6..c07306060 100644 --- a/src/main/java/org/mariadb/jdbc/util/Version.java +++ b/src/main/java/org/mariadb/jdbc/util/Version.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util; diff --git a/src/main/java/org/mariadb/jdbc/util/VersionFactory.java b/src/main/java/org/mariadb/jdbc/util/VersionFactory.java index 496ef099d..94133e849 100644 --- a/src/main/java/org/mariadb/jdbc/util/VersionFactory.java +++ b/src/main/java/org/mariadb/jdbc/util/VersionFactory.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util; diff --git a/src/main/java/org/mariadb/jdbc/util/constants/Capabilities.java b/src/main/java/org/mariadb/jdbc/util/constants/Capabilities.java index 114bfa204..fc165c86c 100644 --- a/src/main/java/org/mariadb/jdbc/util/constants/Capabilities.java +++ b/src/main/java/org/mariadb/jdbc/util/constants/Capabilities.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.constants; diff --git a/src/main/java/org/mariadb/jdbc/util/constants/CatalogTerm.java b/src/main/java/org/mariadb/jdbc/util/constants/CatalogTerm.java new file mode 100644 index 000000000..2faa37db9 --- /dev/null +++ b/src/main/java/org/mariadb/jdbc/util/constants/CatalogTerm.java @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + +package org.mariadb.jdbc.util.constants; + +public enum CatalogTerm { + UseCatalog, + UseSchema +} diff --git a/src/main/java/org/mariadb/jdbc/util/constants/ColumnFlags.java b/src/main/java/org/mariadb/jdbc/util/constants/ColumnFlags.java index 7b7fad27a..274efb456 100644 --- a/src/main/java/org/mariadb/jdbc/util/constants/ColumnFlags.java +++ b/src/main/java/org/mariadb/jdbc/util/constants/ColumnFlags.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.constants; diff --git a/src/main/java/org/mariadb/jdbc/util/constants/ConnectionState.java b/src/main/java/org/mariadb/jdbc/util/constants/ConnectionState.java index 3544473e5..e58936c95 100644 --- a/src/main/java/org/mariadb/jdbc/util/constants/ConnectionState.java +++ b/src/main/java/org/mariadb/jdbc/util/constants/ConnectionState.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.constants; diff --git a/src/main/java/org/mariadb/jdbc/util/constants/ServerStatus.java b/src/main/java/org/mariadb/jdbc/util/constants/ServerStatus.java index 67976e838..f2cfbeca5 100644 --- a/src/main/java/org/mariadb/jdbc/util/constants/ServerStatus.java +++ b/src/main/java/org/mariadb/jdbc/util/constants/ServerStatus.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.constants; diff --git a/src/main/java/org/mariadb/jdbc/util/constants/StateChange.java b/src/main/java/org/mariadb/jdbc/util/constants/StateChange.java index 613b750b6..040fc637f 100644 --- a/src/main/java/org/mariadb/jdbc/util/constants/StateChange.java +++ b/src/main/java/org/mariadb/jdbc/util/constants/StateChange.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.constants; diff --git a/src/main/java/org/mariadb/jdbc/util/log/ConsoleLogger.java b/src/main/java/org/mariadb/jdbc/util/log/ConsoleLogger.java index 75310d030..8a3dd0456 100644 --- a/src/main/java/org/mariadb/jdbc/util/log/ConsoleLogger.java +++ b/src/main/java/org/mariadb/jdbc/util/log/ConsoleLogger.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.log; diff --git a/src/main/java/org/mariadb/jdbc/util/log/JdkLogger.java b/src/main/java/org/mariadb/jdbc/util/log/JdkLogger.java index d06e42e77..66aa84bef 100644 --- a/src/main/java/org/mariadb/jdbc/util/log/JdkLogger.java +++ b/src/main/java/org/mariadb/jdbc/util/log/JdkLogger.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.log; diff --git a/src/main/java/org/mariadb/jdbc/util/log/Logger.java b/src/main/java/org/mariadb/jdbc/util/log/Logger.java index baa47f180..b12309aeb 100644 --- a/src/main/java/org/mariadb/jdbc/util/log/Logger.java +++ b/src/main/java/org/mariadb/jdbc/util/log/Logger.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.log; diff --git a/src/main/java/org/mariadb/jdbc/util/log/LoggerHelper.java b/src/main/java/org/mariadb/jdbc/util/log/LoggerHelper.java index e1a7d7616..5b68cb3e2 100644 --- a/src/main/java/org/mariadb/jdbc/util/log/LoggerHelper.java +++ b/src/main/java/org/mariadb/jdbc/util/log/LoggerHelper.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.log; diff --git a/src/main/java/org/mariadb/jdbc/util/log/Loggers.java b/src/main/java/org/mariadb/jdbc/util/log/Loggers.java index c1ad6992e..7001efb51 100644 --- a/src/main/java/org/mariadb/jdbc/util/log/Loggers.java +++ b/src/main/java/org/mariadb/jdbc/util/log/Loggers.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.log; diff --git a/src/main/java/org/mariadb/jdbc/util/log/NoLogger.java b/src/main/java/org/mariadb/jdbc/util/log/NoLogger.java index dc80ebc16..7caf7aa58 100644 --- a/src/main/java/org/mariadb/jdbc/util/log/NoLogger.java +++ b/src/main/java/org/mariadb/jdbc/util/log/NoLogger.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.log; diff --git a/src/main/java/org/mariadb/jdbc/util/log/Slf4JLogger.java b/src/main/java/org/mariadb/jdbc/util/log/Slf4JLogger.java index 40fa94945..4be762e66 100644 --- a/src/main/java/org/mariadb/jdbc/util/log/Slf4JLogger.java +++ b/src/main/java/org/mariadb/jdbc/util/log/Slf4JLogger.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.log; diff --git a/src/main/java/org/mariadb/jdbc/util/options/OptionAliases.java b/src/main/java/org/mariadb/jdbc/util/options/OptionAliases.java index 78cc9b156..596512529 100644 --- a/src/main/java/org/mariadb/jdbc/util/options/OptionAliases.java +++ b/src/main/java/org/mariadb/jdbc/util/options/OptionAliases.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.util.options; diff --git a/src/main/java11/org/mariadb/jdbc/client/SocketHelper.java b/src/main/java11/org/mariadb/jdbc/client/SocketHelper.java index c85acded8..573f1c3e5 100644 --- a/src/main/java11/org/mariadb/jdbc/client/SocketHelper.java +++ b/src/main/java11/org/mariadb/jdbc/client/SocketHelper.java @@ -1,3 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + package org.mariadb.jdbc.client; import jdk.net.ExtendedSocketOptions; diff --git a/src/main/resources/driver.properties b/src/main/resources/driver.properties index db5ff939b..d4b79f74d 100644 --- a/src/main/resources/driver.properties +++ b/src/main/resources/driver.properties @@ -54,6 +54,8 @@ allowLocalInfile=Indicate if LOAD DATA LOCAL INFILE commands are permitted. This geometryDefaultType=Indicate what default Object type Geometry a resultset.getObject must return. null or empty is WKB byte array. 'default' will return org.mariadb.mariadb.jdbc.type Object. Default null keyStore=File path of the keyStore file that contain client private key store and associate certificates (similar to java System property "javax.net.ssl.keyStore", but ensure that only the private key's entries are used) keyStorePassword="Password for the client certificate keyStore (similar to java System property "javax.net.ssl.keyStorePassword") +keyPassword="Password for the client certificate keyStore alias +trustStoreType=indicate trust store type (JKS/PKCS12). default is null, then using java default type keyStoreType=indicate key store type (JKS/PKCS12). default is null, then using java default type transactionIsolation=Default transaction isolation level. Possible values READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE. default REPEATABLE-READ restrictedAuth=if set, restrict authentication plugin to secure list. Default provided plugins are mysql_native_password,client_ed25519,auth_gssapi_client,caching_sha2_password,dialog and mysql_clear_password. (String) Default null @@ -66,4 +68,7 @@ createDatabaseIfNotExist=the specified database in the url will be created if no initSql=Initial command to execute on new connection creation transformedBitIsBoolean=Indicate for TINYINT(1) in column metadata that type is BOOLEAN in place of BIT disablePipeline=option permitting disabling pipelining -uuidAsString=must uuid fields return as String and not java.util.UUID when using getObject() \ No newline at end of file +uuidAsString=must uuid fields return as String and not java.util.UUID when using getObject() +useCatalogTerm="schema" and "database" are server synonymous. Connector historically get/set database using Connection.setCatalog()/getCatalog(), setSchema()/getSchema() being no-op. This parameter indicate to change that behavior to use Schema in place of Catalog. Behavior will change 1: database change will be done with either Connection.setCatalog()/getCatalog() or Connection.setSchema()/getSchema(), 2: DatabaseMetadata methods that use catalog or schema filtering, 3: ResultsetMetadata database will be retrieved +useLocalSessionState=indicate if connector can use local state to avoid unnecessary queries. This means application must use JDBC dedicated methods, like connection.setTransactionIsolation and never queries like "SET SESSION TRANSACTION ISOLATION LEVEL X" directly +useBulkStmtsForInserts=use Bulk batch for insert only. This permits to ensure returning expected affected rows and not Statement.SUCCESS_NO_INFO. This option is enabled when useBulkStmts is enabled \ No newline at end of file diff --git a/src/test/java/org/mariadb/jdbc/integration/BatchTest.java b/src/test/java/org/mariadb/jdbc/integration/BatchTest.java index fda00f4a7..a507c2c9e 100644 --- a/src/test/java/org/mariadb/jdbc/integration/BatchTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/BatchTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -80,36 +80,56 @@ public void wrongParameter(Connection con) throws SQLException { @Test public void differentParameterType() throws SQLException { - try (Connection con = createCon("&useServerPrepStmts=false&useBulkStmts=false")) { + try (Connection con = createCon("&useServerPrepStmts=false&useBulkStmtsForInserts=false")) { differentParameterType(con, false); } - try (Connection con = createCon("&useServerPrepStmts=false&useBulkStmts=true")) { + try (Connection con = + createCon("&useServerPrepStmts=false&useBulkStmts&useBulkStmtsForInserts")) { differentParameterType(con, isMariaDBServer() && !isXpand()); } try (Connection con = - createCon("&useServerPrepStmts=false&useBulkStmts=true&disablePipeline")) { + createCon( + "&useServerPrepStmts=false&useBulkStmtsForInserts&useBulkStmts&disablePipeline")) { differentParameterType(con, isMariaDBServer() && !isXpand()); } - try (Connection con = createCon("&useServerPrepStmts&useBulkStmts=false")) { + try (Connection con = createCon("&useServerPrepStmts&useBulkStmtsForInserts=false")) { + differentParameterType(con, false); + } + try (Connection con = + createCon("&useServerPrepStmts&useBulkStmtsForInserts&allowLocalInfile=false")) { differentParameterType(con, false); } - try (Connection con = createCon("&useServerPrepStmts&useBulkStmts&allowLocalInfile=false")) { + try (Connection con = + createCon( + "&useServerPrepStmts&useBulkStmts&useBulkStmtsForInserts&allowLocalInfile=false")) { differentParameterType(con, isMariaDBServer() && !isXpand()); } - try (Connection con = createCon("&useServerPrepStmts=false&allowLocalInfile")) { + try (Connection con = createCon("&useServerPrepStmts=false&useBulkStmts&allowLocalInfile")) { differentParameterType(con, isMariaDBServer() && !isXpand()); } - try (Connection con = createCon("&useServerPrepStmts&useBulkStmts=false")) { + try (Connection con = createCon("&useServerPrepStmts=false&allowLocalInfile")) { + differentParameterType(con, false); + } + try (Connection con = createCon("&useServerPrepStmts&useBulkStmtsForInserts=false")) { differentParameterType(con, false); } - try (Connection con = createCon("&useServerPrepStmts&useBulkStmts")) { + try (Connection con = createCon("&useServerPrepStmts&useBulkStmtsForInserts")) { + differentParameterType(con, false); + } + try (Connection con = createCon("&useServerPrepStmts&useBulkStmts&useBulkStmtsForInserts")) { differentParameterType(con, isMariaDBServer() && !isXpand()); } - try (Connection con = createCon("&useServerPrepStmts&useBulkStmts&allowLocalInfile=false")) { + try (Connection con = + createCon( + "&useServerPrepStmts&useBulkStmts&useBulkStmtsForInserts&allowLocalInfile=false")) { differentParameterType(con, isMariaDBServer() && !isXpand()); } try (Connection con = - createCon("&useServerPrepStmts&useBulkStmts=false&disablePipeline=true")) { + createCon("&useServerPrepStmts&useBulkStmtsForInserts&allowLocalInfile=false")) { + differentParameterType(con, false); + } + try (Connection con = + createCon("&useServerPrepStmts&useBulkStmtsForInserts=false&disablePipeline=true")) { differentParameterType(con, false); } } @@ -118,6 +138,7 @@ public void differentParameterType(Connection con, boolean expectSuccessUnknown) throws SQLException { Statement stmt = con.createStatement(); stmt.execute("TRUNCATE BatchTest"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement prep = con.prepareStatement("INSERT INTO BatchTest(t1, t2) VALUES (?,?)")) { prep.setInt(1, 1); @@ -132,15 +153,9 @@ public void differentParameterType(Connection con, boolean expectSuccessUnknown) prep.addBatch(); int[] res = prep.executeBatch(); assertEquals(3, res.length); - if (expectSuccessUnknown) { - assertEquals(Statement.SUCCESS_NO_INFO, res[0]); - assertEquals(Statement.SUCCESS_NO_INFO, res[1]); - assertEquals(Statement.SUCCESS_NO_INFO, res[2]); - } else { - assertEquals(1, res[0]); - assertEquals(1, res[1]); - assertEquals(1, res[2]); - } + assertEquals(1, res[0]); + assertEquals(1, res[1]); + assertEquals(1, res[2]); } ResultSet rs = stmt.executeQuery("SELECT * FROM BatchTest"); assertTrue(rs.next()); @@ -166,13 +181,8 @@ public void differentParameterType(Connection con, boolean expectSuccessUnknown) prep.addBatch(); int[] res = prep.executeBatch(); assertEquals(2, res.length); - if (expectSuccessUnknown) { - assertEquals(Statement.SUCCESS_NO_INFO, res[0]); - assertEquals(Statement.SUCCESS_NO_INFO, res[1]); - } else { - assertEquals(1, res[0]); - assertEquals(1, res[1]); - } + assertEquals(1, res[0]); + assertEquals(1, res[1]); } rs = stmt.executeQuery("SELECT * FROM BatchTest"); assertTrue(rs.next()); @@ -241,21 +251,45 @@ public void differentParameterType(Connection con, boolean expectSuccessUnknown) assertEquals(2, rs.getInt(1)); assertEquals("2", rs.getString(2)); assertFalse(rs.next()); + + try (PreparedStatement prep = + con.prepareStatement("UPDATE BatchTest SET t1=t1+10 WHERE t1=?")) { + prep.setInt(1, 1); + prep.addBatch(); + + prep.setInt(1, 2); + prep.addBatch(); + int[] res = prep.executeBatch(); + if (expectSuccessUnknown) { + assertEquals(Statement.SUCCESS_NO_INFO, res[0]); + assertEquals(Statement.SUCCESS_NO_INFO, res[1]); + } else { + assertEquals(1, res[0]); + assertEquals(1, res[1]); + } + } + con.rollback(); } @Test public void largeBatch() throws SQLException { - for (int i = 0; i < 32; i++) { + for (int i = 0; i < 64; i++) { boolean useServerPrepStmts = (i & 2) > 0; boolean useBulkStmts = (i & 4) > 0; boolean allowLocalInfile = (i & 8) > 0; boolean useCompression = (i & 16) > 0; - - try (Connection con = - createCon( - String.format( - "&useServerPrepStmts=%s&useBulkStmts=%s&allowLocalInfile=%s&useCompression=%s", - useServerPrepStmts, useBulkStmts, allowLocalInfile, useCompression))) { + boolean useBulkStmtsForInserts = (i & 32) > 0; + + String confString = + String.format( + "&useServerPrepStmts=%s&useBulkStmts=%s&allowLocalInfile=%s&useCompression=%s&useBulkStmtsForInserts=%s", + useServerPrepStmts, + useBulkStmts, + allowLocalInfile, + useCompression, + useBulkStmtsForInserts); + try (Connection con = createCon(confString)) { + System.out.println("########################################" + confString); largeBatch(con); } } diff --git a/src/test/java/org/mariadb/jdbc/integration/BlobTest.java b/src/test/java/org/mariadb/jdbc/integration/BlobTest.java index d78dfa878..ca02e9420 100644 --- a/src/test/java/org/mariadb/jdbc/integration/BlobTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/BlobTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/BulkStmtSplitError.java b/src/test/java/org/mariadb/jdbc/integration/BulkStmtSplitErrorTest.java similarity index 82% rename from src/test/java/org/mariadb/jdbc/integration/BulkStmtSplitError.java rename to src/test/java/org/mariadb/jdbc/integration/BulkStmtSplitErrorTest.java index 96fb947b7..4bc9c1cea 100644 --- a/src/test/java/org/mariadb/jdbc/integration/BulkStmtSplitError.java +++ b/src/test/java/org/mariadb/jdbc/integration/BulkStmtSplitErrorTest.java @@ -1,3 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab + package org.mariadb.jdbc.integration; import java.sql.PreparedStatement; @@ -7,7 +11,7 @@ import org.junit.jupiter.api.*; import org.mariadb.jdbc.Statement; -public class BulkStmtSplitError extends Common { +public class BulkStmtSplitErrorTest extends Common { @AfterAll public static void drop() throws SQLException { @@ -42,7 +46,7 @@ public void BulkStmtSplitError() throws SQLException { // eat } - ResultSet rs = stmt.executeQuery("SELECT count(*) FROM agent"); + ResultSet rs = stmt.executeQuery("SELECT count(*) FROM BulkStmtSplitError"); Assertions.assertTrue(rs.next()); Assertions.assertEquals(2, rs.getInt(1)); } diff --git a/src/test/java/org/mariadb/jdbc/integration/ClientPreparedStatementParsingTest.java b/src/test/java/org/mariadb/jdbc/integration/ClientPreparedStatementParsingTest.java index 9e05a4971..745fa45f3 100644 --- a/src/test/java/org/mariadb/jdbc/integration/ClientPreparedStatementParsingTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/ClientPreparedStatementParsingTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/ClobTest.java b/src/test/java/org/mariadb/jdbc/integration/ClobTest.java index 193beebf8..172b31377 100644 --- a/src/test/java/org/mariadb/jdbc/integration/ClobTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/ClobTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/Common.java b/src/test/java/org/mariadb/jdbc/integration/Common.java index b0003e833..78e3ba0dc 100644 --- a/src/test/java/org/mariadb/jdbc/integration/Common.java +++ b/src/test/java/org/mariadb/jdbc/integration/Common.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -233,6 +233,17 @@ public static Connection createCon(String option, Integer sslPort) throws SQLExc return Driver.connect(conf); } + public static Connection createBasicCon(String option, Integer sslPort) throws SQLException { + Configuration conf = + Configuration.parse(mDefUrl.substring(0, mDefUrl.indexOf("?")) + "?" + option); + if (sslPort != null) { + for (HostAddress hostAddress : conf.addresses()) { + hostAddress.port = sslPort; + } + } + return Driver.connect(conf); + } + @AfterEach public void afterEach1() throws SQLException { sharedConn.isValid(2000); diff --git a/src/test/java/org/mariadb/jdbc/integration/CompressTest.java b/src/test/java/org/mariadb/jdbc/integration/CompressTest.java index 9fcbf5db0..31f070641 100644 --- a/src/test/java/org/mariadb/jdbc/integration/CompressTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/CompressTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/ConfigurationTest.java b/src/test/java/org/mariadb/jdbc/integration/ConfigurationTest.java index aa26f4aba..884009e90 100644 --- a/src/test/java/org/mariadb/jdbc/integration/ConfigurationTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/ConfigurationTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java b/src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java index 0f4c8b1f3..f1a4ce8c5 100644 --- a/src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -863,8 +863,6 @@ public void pamAuthPlugin() throws Throwable { stmt.execute("CREATE USER '" + pamUser + "'@'%' IDENTIFIED VIA pam USING 'mariadb'"); stmt.execute("GRANT SELECT ON *.* TO '" + pamUser + "'@'%' IDENTIFIED VIA pam"); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); stmt.execute("FLUSH PRIVILEGES"); int testPort = port; @@ -1003,8 +1001,6 @@ public void localSocket() throws Exception { stmt.execute("CREATE USER testSocket IDENTIFIED BY 'heyPassw!µ20§rd'"); stmt.execute("GRANT SELECT on *.* to testSocket"); } - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); stmt.execute("FLUSH PRIVILEGES"); String url = diff --git a/src/test/java/org/mariadb/jdbc/integration/CredentialPluginTest.java b/src/test/java/org/mariadb/jdbc/integration/CredentialPluginTest.java index fbf197c59..1852c8457 100644 --- a/src/test/java/org/mariadb/jdbc/integration/CredentialPluginTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/CredentialPluginTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -50,8 +50,6 @@ public static void beforeTest() throws SQLException { stmt.execute("CREATE USER 'identityUser'@'%' IDENTIFIED BY '!Passw0rd3Works'"); stmt.execute("GRANT SELECT ON " + sharedConn.getCatalog() + ".* TO 'identityUser'@'%'"); } - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); stmt.execute("FLUSH PRIVILEGES"); } diff --git a/src/test/java/org/mariadb/jdbc/integration/DataSourceTest.java b/src/test/java/org/mariadb/jdbc/integration/DataSourceTest.java index f04fbab03..a97db8683 100644 --- a/src/test/java/org/mariadb/jdbc/integration/DataSourceTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/DataSourceTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -151,8 +151,6 @@ public void switchUser() throws SQLException { + sharedConn.getCatalog() + ".* TO 'dsUser'@'%' IDENTIFIED BY 'MySup8%rPassw@ord'"); } - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); stmt.execute("FLUSH PRIVILEGES"); DataSource ds = new MariaDbDataSource(mDefUrl + "&allowPublicKeyRetrieval"); diff --git a/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java b/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java index ff8702557..69abf84b9 100644 --- a/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -170,6 +170,25 @@ public void primaryKeysTest() throws SQLException { assertEquals(2, counter); } + @Test + public void primaryKeysSchemaTest() throws SQLException { + try (Connection con = createCon("&useCatalogTerm=Schema")) { + DatabaseMetaData meta = con.getMetaData(); + ResultSet rs = meta.getPrimaryKeys(null, database, "dbpk_test"); + int counter = 0; + while (rs.next()) { + counter++; + assertEquals("def", rs.getString("table_cat")); + assertEquals(database, rs.getString("table_schem")); + assertEquals("dbpk_test", rs.getString("table_name")); + assertEquals("id" + counter, rs.getString("column_name")); + assertEquals("id" + counter, rs.getString("column_name")); + assertEquals("PRIMARY", rs.getString("PK_NAME")); + } + assertEquals(2, counter); + } + } + @Test public void primaryKeyTest2() throws SQLException { java.sql.Statement stmt = sharedConn.createStatement(); @@ -197,6 +216,35 @@ public void primaryKeyTest2() throws SQLException { stmt.execute("drop table if exists primarykeytest1"); } + @Test + public void primaryKeyTest2Schema() throws SQLException { + try (Connection con = createCon("&useCatalogTerm=Schema")) { + java.sql.Statement stmt = con.createStatement(); + stmt.execute("drop table if exists primarykeytest2"); + stmt.execute("drop table if exists primarykeytest1"); + stmt.execute("CREATE TABLE primarykeytest1 ( id1 integer, constraint pk primary key(id1))"); + stmt.execute( + "CREATE TABLE primarykeytest2 (id2a integer, id2b integer, constraint pk primary key(id2a, id2b), " + + "constraint fk1 foreign key(id2a) references primarykeytest1(id1), constraint fk2 foreign key(id2b) " + + "references primarykeytest1(id1))"); + + DatabaseMetaData dbmd = con.getMetaData(); + ResultSet rs = dbmd.getPrimaryKeys(con.getCatalog(), null, "primarykeytest2"); + int counter = 0; + while (rs.next()) { + counter++; + assertEquals("def", rs.getString("table_cat")); + assertEquals(database, rs.getString("table_schem")); + assertEquals("primarykeytest2", rs.getString("table_name")); + assertEquals(counter, rs.getShort("key_seq")); + assertEquals("PRIMARY", rs.getString("pk_name")); + } + assertEquals(2, counter); + stmt.execute("drop table if exists primarykeytest2"); + stmt.execute("drop table if exists primarykeytest1"); + } + } + @Test public void datetimeTest() throws SQLException { java.sql.Statement stmt = sharedConn.createStatement(); @@ -245,29 +293,85 @@ public void functionColumns() throws SQLException { stmt.execute("DROP FUNCTION IF EXISTS hello"); } + @Test + public void functionColumnsSchema() throws SQLException { + try (Connection con = createCon("&useCatalogTerm=Schema")) { + java.sql.Statement stmt = con.createStatement(); + DatabaseMetaData meta = con.getMetaData(); + + if (meta.getDatabaseMajorVersion() < 5) { + return; + } else if (meta.getDatabaseMajorVersion() == 5 && meta.getDatabaseMinorVersion() < 5) { + return; + } + + stmt.execute("DROP FUNCTION IF EXISTS hello"); + stmt.execute( + "CREATE FUNCTION hello (s CHAR(20), i int) RETURNS CHAR(50) DETERMINISTIC " + + "RETURN CONCAT('Hello, ',s,'!')"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER + ResultSet rs = meta.getFunctionColumns(null, null, "hello", null); + + assertTrue(rs.next()); + /* First row is for return value */ + assertEquals(rs.getString("FUNCTION_CAT"), "def"); + assertEquals(rs.getString("FUNCTION_SCHEM"), database); + assertEquals(rs.getString("COLUMN_NAME"), null); /* No name, since it is return value */ + assertEquals(rs.getInt("COLUMN_TYPE"), DatabaseMetaData.functionReturn); + assertEquals(rs.getInt("DATA_TYPE"), Types.CHAR); + assertEquals(rs.getString("TYPE_NAME"), "char"); + + assertTrue(rs.next()); + assertEquals(rs.getString("COLUMN_NAME"), "s"); /* input parameter 's' (CHAR) */ + assertEquals(rs.getInt("COLUMN_TYPE"), DatabaseMetaData.functionColumnIn); + assertEquals(rs.getInt("DATA_TYPE"), Types.CHAR); + assertEquals(rs.getString("TYPE_NAME"), "char"); + + assertTrue(rs.next()); + assertEquals(rs.getString("COLUMN_NAME"), "i"); /* input parameter 'i' (INT) */ + assertEquals(rs.getInt("COLUMN_TYPE"), DatabaseMetaData.functionColumnIn); + assertEquals(rs.getInt("DATA_TYPE"), Types.INTEGER); + assertEquals(rs.getString("TYPE_NAME"), "int"); + stmt.execute("DROP FUNCTION IF EXISTS hello"); + } + } + /** Same as getImportedKeys, with one foreign key in a table in another catalog. */ @Test public void getImportedKeys() throws Exception { - getImportedKeys(sharedConn, true); + getImportedKeys(sharedConn, true, true); try (org.mariadb.jdbc.Connection con = createCon()) { java.sql.Statement stmt = con.createStatement(); stmt.execute("SET sql_mode = concat(@@sql_mode,',NO_BACKSLASH_ESCAPES')"); - getImportedKeys(con, true); + getImportedKeys(con, true, true); } try (org.mariadb.jdbc.Connection con = createCon("importedKeysWithConstraintNames=false")) { java.sql.Statement stmt = con.createStatement(); stmt.execute("SET sql_mode = concat(@@sql_mode,',NO_BACKSLASH_ESCAPES')"); - getImportedKeys(con, false); + getImportedKeys(con, false, true); + } + try (org.mariadb.jdbc.Connection con = createCon("&useCatalogTerm=Schema")) { + java.sql.Statement stmt = con.createStatement(); + stmt.execute("SET sql_mode = concat(@@sql_mode,',NO_BACKSLASH_ESCAPES')"); + getImportedKeys(con, true, false); + } + try (org.mariadb.jdbc.Connection con = + createCon("importedKeysWithConstraintNames=false&useCatalogTerm=Schema")) { + java.sql.Statement stmt = con.createStatement(); + stmt.execute("SET sql_mode = concat(@@sql_mode,',NO_BACKSLASH_ESCAPES')"); + getImportedKeys(con, false, false); } } private void getImportedKeys( - org.mariadb.jdbc.Connection con, boolean importedKeysWithConstraintNames) throws Exception { + org.mariadb.jdbc.Connection con, boolean importedKeysWithConstraintNames, boolean useCatalog) + throws Exception { // cancel for MySQL 8.0, since CASCADE with I_S give importedKeySetDefault, not // importedKeyCascade // Assumptions.assumeFalse(!isMariaDBServer() && minVersion(8, 0, 0)); Assumptions.assumeFalse(isXpand()); java.sql.Statement st = con.createStatement(); + st.execute("USE " + database); st.execute("DROP TABLE IF EXISTS `product order 1`"); st.execute("DROP TABLE IF EXISTS `other sch'ema`.`product order.2`"); st.execute("DROP DATABASE IF EXISTS `other sch'ema`"); @@ -338,28 +442,33 @@ private void getImportedKeys( Common.assertThrowsContains( SQLException.class, - () -> con.getMetaData().getImportedKeys(con.getCatalog(), null, null), + () -> + con.getMetaData() + .getImportedKeys(useCatalog ? con.getCatalog() : con.getSchema(), null, null), "'table' parameter in getImportedKeys cannot be null"); /* Test that I_S implementation is equivalent to parsing "show create table" . Get result sets using either method and compare (ignore minor differences INT vs SMALLINT */ ResultSet rs1 = - con.getMetaData().getImportedKeysUsingShowCreateTable(con.getCatalog(), "product order 1"); + con.getMetaData() + .getImportedKeysUsingShowCreateTable( + useCatalog ? con.getCatalog() : con.getSchema(), "product order 1"); ResultSet rs2 = con.getMetaData() - .getImportedKeysUsingInformationSchema(con.getCatalog(), "product order 1"); + .getImportedKeysUsingInformationSchema( + useCatalog ? con.getCatalog() : con.getSchema(), "product order 1"); assertEquals(rs1.getMetaData().getColumnCount(), rs2.getMetaData().getColumnCount()); for (int i = 0; i < 2; i++) { ResultSet rs = i == 0 ? rs1 : rs2; assertTrue(rs.next()); - assertEquals("t1", rs.getString("PKTABLE_CAT")); - assertEquals(null, rs.getString("PKTABLE_SCHEM")); + assertEquals(useCatalog ? "t1" : "def", rs.getString("PKTABLE_CAT")); + assertEquals(useCatalog ? null : "t1", rs.getString("PKTABLE_SCHEM")); assertEquals("product", rs.getString("PKTABLE_NAME")); assertEquals("category", rs.getString("PKCOLUMN_NAME")); - assertEquals(sharedConn.getCatalog(), rs.getString("FKTABLE_CAT")); - assertEquals(null, rs.getString("FKTABLE_SCHEM")); + assertEquals(useCatalog ? con.getCatalog() : "def", rs.getString("FKTABLE_CAT")); + assertEquals(useCatalog ? null : con.getSchema(), rs.getString("FKTABLE_SCHEM")); assertEquals("product order 1", rs.getString("FKTABLE_NAME")); assertEquals("product_category", rs.getString("FKCOLUMN_NAME")); assertEquals(1, rs.getInt("KEY_SEQ")); @@ -373,12 +482,12 @@ Get result sets using either method and compare (ignore minor differences INT vs assertEquals(DatabaseMetaData.importedKeyNotDeferrable, rs.getInt("DEFERRABILITY")); assertTrue(rs.next()); - assertEquals("t1", rs.getString("PKTABLE_CAT")); - assertEquals(null, rs.getString("PKTABLE_SCHEM")); + assertEquals(useCatalog ? "t1" : "def", rs.getString("PKTABLE_CAT")); + assertEquals(useCatalog ? null : "t1", rs.getString("PKTABLE_SCHEM")); assertEquals("product", rs.getString("PKTABLE_NAME")); assertEquals("id", rs.getString("PKCOLUMN_NAME")); - assertEquals(sharedConn.getCatalog(), rs.getString("FKTABLE_CAT")); - assertEquals(null, rs.getString("FKTABLE_SCHEM")); + assertEquals(useCatalog ? con.getCatalog() : "def", rs.getString("FKTABLE_CAT")); + assertEquals(useCatalog ? null : con.getSchema(), rs.getString("FKTABLE_SCHEM")); assertEquals("product order 1", rs.getString("FKTABLE_NAME")); assertEquals("product_id", rs.getString("FKCOLUMN_NAME")); assertEquals(2, rs.getInt("KEY_SEQ")); @@ -392,12 +501,12 @@ Get result sets using either method and compare (ignore minor differences INT vs assertEquals(DatabaseMetaData.importedKeyNotDeferrable, rs.getInt("DEFERRABILITY")); assertTrue(rs.next()); - assertEquals(sharedConn.getCatalog(), rs.getString("PKTABLE_CAT")); - assertEquals(null, rs.getString("PKTABLE_SCHEM")); + assertEquals(useCatalog ? database : "def", rs.getString("PKTABLE_CAT")); + assertEquals(useCatalog ? null : database, rs.getString("PKTABLE_SCHEM")); assertEquals("cus`tomer", rs.getString("PKTABLE_NAME")); assertEquals("id", rs.getString("PKCOLUMN_NAME")); - assertEquals(sharedConn.getCatalog(), rs.getString("FKTABLE_CAT")); - assertEquals(null, rs.getString("FKTABLE_SCHEM")); + assertEquals(useCatalog ? con.getCatalog() : "def", rs.getString("FKTABLE_CAT")); + assertEquals(useCatalog ? null : con.getSchema(), rs.getString("FKTABLE_SCHEM")); assertEquals("product order 1", rs.getString("FKTABLE_NAME")); assertEquals("customer_id", rs.getString("FKCOLUMN_NAME")); assertEquals(1, rs.getInt("KEY_SEQ")); @@ -558,6 +667,80 @@ public void exportedKeysTest() throws SQLException { assertEquals("unik_name", rs.getString("PK_NAME")); } + @Test + public void exportedKeysTestSchema() throws SQLException { + try (Connection con = createCon("&useCatalogTerm=Schema")) { + DatabaseMetaData dbmd = con.getMetaData(); + assertEquals(database, con.getSchema()); + assertEquals("def", con.getCatalog()); + ResultSet rs = dbmd.getExportedKeys(null, con.getSchema(), "cross%"); + assertTrue(rs.next()); + assertEquals("def", rs.getString("PKTABLE_CAT")); + assertEquals(database, rs.getString("PKTABLE_SCHEM")); + assertEquals("cross1", rs.getString("PKTABLE_NAME")); + assertEquals("id", rs.getString("PKCOLUMN_NAME")); + assertEquals("def", rs.getString("FKTABLE_CAT")); + assertEquals(database, rs.getString("FKTABLE_SCHEM")); + assertEquals("cross2", rs.getString("FKTABLE_NAME")); + assertEquals("id_ref0", rs.getString("FKCOLUMN_NAME")); + assertTrue(rs.getInt("KEY_SEQ") == 1 || rs.wasNull()); + if (!isMariaDBServer() && minVersion(8, 0, 0)) { + assertEquals(DatabaseMetaData.importedKeyNoAction, rs.getInt("UPDATE_RULE")); + assertEquals(DatabaseMetaData.importedKeyNoAction, rs.getInt("DELETE_RULE")); + } else { + assertEquals(DatabaseMetaData.importedKeyRestrict, rs.getInt("UPDATE_RULE")); + assertEquals(DatabaseMetaData.importedKeyRestrict, rs.getInt("DELETE_RULE")); + } + assertEquals("cross2_ibfk_1", rs.getString("FK_NAME")); + assertTrue( + "PRIMARY".equals(rs.getString("PK_NAME")) + || "__idx_cross1__PRIMARY".equals(rs.getString("PK_NAME"))); + + assertTrue(rs.next()); + + assertEquals("def", rs.getString("PKTABLE_CAT")); + assertEquals(database, rs.getString("PKTABLE_SCHEM")); + assertEquals("cross2", rs.getString("PKTABLE_NAME")); + assertEquals("id", rs.getString("PKCOLUMN_NAME")); + assertEquals("def", rs.getString("FKTABLE_CAT")); + assertEquals(database, rs.getString("FKTABLE_SCHEM")); + assertEquals("cross3", rs.getString("FKTABLE_NAME")); + assertEquals("id_ref1", rs.getString("FKCOLUMN_NAME")); + assertTrue(rs.getInt("KEY_SEQ") == 1 || rs.wasNull()); + assertEquals(DatabaseMetaData.importedKeyCascade, rs.getInt("UPDATE_RULE")); + if (!isMariaDBServer() && minVersion(8, 0, 0)) { + assertEquals(DatabaseMetaData.importedKeyNoAction, rs.getInt("DELETE_RULE")); + } else { + assertEquals(DatabaseMetaData.importedKeyRestrict, rs.getInt("DELETE_RULE")); + } + assertTrue( + "cross3_ibfk_1".equals(rs.getString("FK_NAME")) + || "fk_my_name".equals(rs.getString("FK_NAME"))); + assertEquals("unik_name", rs.getString("PK_NAME")); + + assertTrue(rs.next()); + assertEquals(con.getCatalog(), rs.getString("PKTABLE_CAT")); + assertEquals(database, rs.getString("PKTABLE_SCHEM")); + assertEquals("cross2", rs.getString("PKTABLE_NAME")); + assertEquals("id2", rs.getString("PKCOLUMN_NAME")); + assertEquals(con.getCatalog(), rs.getString("FKTABLE_CAT")); + assertEquals(database, rs.getString("FKTABLE_SCHEM")); + assertEquals("cross3", rs.getString("FKTABLE_NAME")); + assertEquals("id_ref2", rs.getString("FKCOLUMN_NAME")); + assertTrue(rs.getInt("KEY_SEQ") == 2 || rs.wasNull()); + assertEquals(DatabaseMetaData.importedKeyCascade, rs.getInt("UPDATE_RULE")); + if (!isMariaDBServer() && minVersion(8, 0, 0)) { + assertEquals(DatabaseMetaData.importedKeyNoAction, rs.getInt("DELETE_RULE")); + } else { + assertEquals(DatabaseMetaData.importedKeyRestrict, rs.getInt("DELETE_RULE")); + } + assertTrue( + "fk_my_name".equals(rs.getString("FK_NAME")) + || "cross3_ibfk_1".equals(rs.getString("FK_NAME"))); + assertEquals("unik_name", rs.getString("PK_NAME")); + } + } + @Test public void importedKeysTest() throws SQLException { java.sql.Statement stmt = sharedConn.createStatement(); @@ -606,6 +789,11 @@ public void testGetCatalogs() throws SQLException { } if (!isXpand()) assertTrue(haveMysql); assertTrue(haveInformationSchema); + try (Connection con = createCon("&useCatalogTerm=Schema")) { + dbmd = con.getMetaData(); + rs = dbmd.getCatalogs(); + assertFalse(rs.next()); + } } @Test @@ -818,6 +1006,139 @@ public void testGetColumns() throws SQLException { assertFalse(rs.next()); } + @Test + public void testGetColumnsSchema() throws SQLException { + // mysql 5.6 doesn't permit VIRTUAL keyword + Assumptions.assumeTrue(isMariaDBServer() || !isMariaDBServer() && minVersion(5, 7, 0)); + // Xpand doesn't support PERSISTENT keyword + Assumptions.assumeFalse(isXpand()); + try (Connection con = createCon("&useCatalogTerm=Schema")) { + System.out.println(con.getSchema()); + java.sql.Statement stmt = con.createStatement(); + if (minVersion(10, 2, 0) || !isMariaDBServer()) { + stmt.execute( + "CREATE TABLE IF NOT EXISTS " + + database + + ".`ta\nble'getcolumns`(" + + "a INT NOT NULL primary key auto_increment, b VARCHAR(32), c INT AS (CHAR_LENGTH(b)) VIRTUAL, " + + "d VARCHAR(5) AS (left(b,5)) STORED) CHARACTER SET 'utf8mb4'"); + } else { + stmt.execute( + "CREATE TABLE IF NOT EXISTS \"+database+\".`ta\nble'getcolumns`(" + + "a INT NOT NULL primary key auto_increment, b VARCHAR(32), c INT AS (CHAR_LENGTH(b)) VIRTUAL, " + + "d VARCHAR(5) AS (left(b,5)) PERSISTENT) CHARACTER SET 'utf8mb4'"); + } + + DatabaseMetaData dbmd = con.getMetaData(); + ResultSet rs = dbmd.getColumns(null, null, "ta\nble'getcolumns", null); + + assertTrue(rs.next()); + assertEquals("def", rs.getString(1)); // TABLE_CAT + assertEquals(database, rs.getString(2)); // TABLE_SCHEM + assertEquals("ta\nble'getcolumns", rs.getString(3)); // TABLE_NAME + assertEquals("a", rs.getString(4)); // COLUMN_NAME + assertEquals(Types.INTEGER, rs.getInt(5)); // DATA_TYPE + assertEquals("INT", rs.getString(6)); // "TYPE_NAME + assertEquals(10, rs.getInt(7)); // "COLUMN_SIZE + assertEquals(0, rs.getInt(9)); // DECIMAL_DIGITS + assertEquals(10, rs.getInt(10)); // NUM_PREC_RADIX + assertEquals(0, rs.getInt(11)); // NULLABLE + assertEquals("", rs.getString(12)); // REMARKS + assertEquals(null, rs.getString(13)); // COLUMN_DEF + assertEquals(0, rs.getInt(16)); // CHAR_OCTET_LENGTH + assertEquals(1, rs.getInt(17)); // ORDINAL_POSITION + assertEquals("NO", rs.getString(18)); // IS_NULLABLE + assertEquals(null, rs.getString(19)); // SCOPE_CATALOG + assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA + assertEquals(null, rs.getString(21)); // SCOPE_TABLE + assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE + assertEquals("YES", rs.getString(23)); // IS_AUTOINCREMENT + assertEquals("NO", rs.getString(24)); // IS_GENERATEDCOLUMN + + assertTrue(rs.next()); + assertEquals("def", rs.getString(1)); // TABLE_CAT + assertEquals(database, rs.getString(2)); // TABLE_SCHEM + assertEquals("ta\nble'getcolumns", rs.getString(3)); // TABLE_NAME + assertEquals("b", rs.getString(4)); // COLUMN_NAME + assertEquals(Types.VARCHAR, rs.getInt(5)); // DATA_TYPE + assertEquals("VARCHAR", rs.getString(6)); // "TYPE_NAME + assertEquals(32, rs.getInt(7)); // "COLUMN_SIZE + assertEquals(0, rs.getInt(9)); // DECIMAL_DIGITS + assertEquals(10, rs.getInt(10)); // NUM_PREC_RADIX + assertEquals(1, rs.getInt(11)); // NULLABLE + assertEquals("", rs.getString(12)); // REMARKS + + // since 10.2.7, value that are expected as String are enclosed with single quotes as javadoc + // require + assertTrue( + "null".equalsIgnoreCase(rs.getString(13)) || rs.getString(13) == null); // COLUMN_DEF + assertEquals(32 * 4, rs.getInt(16)); // CHAR_OCTET_LENGTH + assertEquals(2, rs.getInt(17)); // ORDINAL_POSITION + assertEquals("YES", rs.getString(18)); // IS_NULLABLE + assertEquals(null, rs.getString(19)); // SCOPE_CATALOG + assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA + assertEquals(null, rs.getString(21)); // SCOPE_TABLE + assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE + assertEquals("NO", rs.getString(23)); // IS_AUTOINCREMENT + assertEquals("NO", rs.getString(24)); // IS_GENERATEDCOLUMN + + assertTrue(rs.next()); + assertEquals("def", rs.getString(1)); // TABLE_CAT + assertEquals(database, rs.getString(2)); // TABLE_SCHEM + assertEquals("ta\nble'getcolumns", rs.getString(3)); // TABLE_NAME + assertEquals("c", rs.getString(4)); // COLUMN_NAME + assertEquals(Types.INTEGER, rs.getInt(5)); // DATA_TYPE + assertEquals("INT", rs.getString(6)); // "TYPE_NAME + assertEquals(10, rs.getInt(7)); // "COLUMN_SIZE + assertEquals(0, rs.getInt(9)); // DECIMAL_DIGITS + assertEquals(10, rs.getInt(10)); // NUM_PREC_RADIX + assertEquals(1, rs.getInt(11)); // NULLABLE + assertEquals("", rs.getString(12)); // REMARKS + + // since 10.2.7, value that are expected as String are enclosed with single quotes as javadoc + // require + assertTrue( + "null".equalsIgnoreCase(rs.getString(13)) || rs.getString(13) == null); // COLUMN_DEF + + assertEquals(0, rs.getInt(16)); // CHAR_OCTET_LENGTH + assertEquals(3, rs.getInt(17)); // ORDINAL_POSITION + assertEquals("YES", rs.getString(18)); // IS_NULLABLE + assertEquals(null, rs.getString(19)); // SCOPE_CATALOG + assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA + assertEquals(null, rs.getString(21)); // SCOPE_TABLE + assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE + assertEquals("NO", rs.getString(23)); // IS_AUTOINCREMENT + assertEquals("YES", rs.getString(24)); // IS_GENERATEDCOLUMN + + assertTrue(rs.next()); + assertEquals("def", rs.getString(1)); // TABLE_CAT + assertEquals(database, rs.getString(2)); // TABLE_SCHEM + assertEquals("ta\nble'getcolumns", rs.getString(3)); // TABLE_NAME + assertEquals("d", rs.getString(4)); // COLUMN_NAME + assertEquals(Types.VARCHAR, rs.getInt(5)); // DATA_TYPE + assertEquals("VARCHAR", rs.getString(6)); // "TYPE_NAME + assertEquals(5, rs.getInt(7)); // "COLUMN_SIZE + assertEquals(0, rs.getInt(9)); // DECIMAL_DIGITS + assertEquals(10, rs.getInt(10)); // NUM_PREC_RADIX + assertEquals(1, rs.getInt(11)); // NULLABLE + assertEquals("", rs.getString(12)); // REMARKS + // since 10.2.7, value that are expected as String are enclosed with single quotes as javadoc + // require + assertTrue( + "null".equalsIgnoreCase(rs.getString(13)) || rs.getString(13) == null); // COLUMN_DEF + assertEquals(5 * 4, rs.getInt(16)); // CHAR_OCTET_LENGTH + assertEquals(4, rs.getInt(17)); // ORDINAL_POSITION + assertEquals("YES", rs.getString(18)); // IS_NULLABLE + assertEquals(null, rs.getString(19)); // SCOPE_CATALOG + assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA + assertEquals(null, rs.getString(21)); // SCOPE_TABLE + assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE + assertEquals("NO", rs.getString(23)); // IS_AUTOINCREMENT + assertEquals("YES", rs.getString(24)); // IS_GENERATEDCOLUMN + assertFalse(rs.next()); + } + } + @Test public void testGetColumnstinyInt1isBit() throws SQLException { try (Connection con = createCon("tinyInt1isBit=false")) { @@ -833,6 +1154,7 @@ public void testGetColumnstinyInt1isBit() throws SQLException { private void testGetColumnstinyInt1isBit(Connection con) throws SQLException { try { java.sql.Statement stmt = con.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute( "CREATE TABLE IF NOT EXISTS `tinyInt1\nisBitCols`(id1 tinyint(1), id2 tinyint(2))"); stmt.execute("INSERT INTO `tinyInt1\nisBitCols` VALUES (1,2)"); @@ -866,6 +1188,7 @@ private void testGetColumnstinyInt1isBit(Connection con) throws SQLException { } finally { con.createStatement().execute("DROP TABLE IF EXISTS `tinyInt1\nisBitCols`"); + con.rollback(); } } @@ -891,6 +1214,7 @@ private void testTransformedBitIsBoolean( Connection con, boolean tinyInt1isBit, boolean transformedBitIsBoolean) throws SQLException { try { java.sql.Statement stmt = con.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute( "CREATE TABLE IF NOT EXISTS `tinyInt1\nisBitCols`(id1 tinyint(1), id2 tinyint(2))"); stmt.execute("INSERT INTO `tinyInt1\nisBitCols` VALUES (1,2)"); @@ -940,6 +1264,7 @@ private void testTransformedBitIsBoolean( } finally { con.createStatement().execute("DROP TABLE IF EXISTS `tinyInt1\nisBitCols`"); + con.rollback(); } } @@ -1028,9 +1353,16 @@ public void getSchemas() throws SQLException { DatabaseMetaData dbmd = sharedConn.getMetaData(); ResultSet rs = dbmd.getSchemas(); assertFalse(rs.next()); - rs = dbmd.getSchemas("*", "*"); assertFalse(rs.next()); + + try (Connection con = createCon("&useCatalogTerm=Schema")) { + dbmd = con.getMetaData(); + rs = dbmd.getSchemas(); + assertTrue(rs.next()); + rs = dbmd.getSchemas("", "%"); + assertTrue(rs.next()); + } } @Test @@ -1452,6 +1784,73 @@ public void getCrossReferenceResults() throws SQLException { assertFalse(rs.next()); } + @Test + public void getCrossReferenceResultsSchema() throws SQLException { + try (Connection con = createCon("&useCatalogTerm=Schema")) { + DatabaseMetaData dbmd = con.getMetaData(); + ResultSet rs = dbmd.getCrossReference(null, null, "cross%", null, null, "cross%"); + + assertTrue(rs.next()); + assertEquals("def", rs.getString(1)); + assertEquals(database, rs.getString(2)); + assertEquals("cross1", rs.getString(3)); + assertEquals("id", rs.getString(4)); + assertEquals("def", rs.getString(5)); + assertEquals(database, rs.getString(6)); + assertEquals("cross2", rs.getString(7)); + assertEquals("id_ref0", rs.getString(8)); + assertTrue(rs.getInt(9) == 1 || rs.wasNull()); + if (!isMariaDBServer() && minVersion(8, 0, 0)) { + assertEquals(DatabaseMetaData.importedKeyNoAction, rs.getInt("UPDATE_RULE")); + assertEquals(DatabaseMetaData.importedKeyNoAction, rs.getInt("DELETE_RULE")); + } else { + assertEquals(DatabaseMetaData.importedKeyRestrict, rs.getInt("UPDATE_RULE")); + assertEquals(DatabaseMetaData.importedKeyRestrict, rs.getInt("DELETE_RULE")); + } + assertEquals("cross2_ibfk_1", rs.getString(12)); + + assertTrue(rs.next()); + assertEquals("def", rs.getString(1)); + assertEquals(database, rs.getString(2)); + assertEquals("cross2", rs.getString(3)); + assertEquals("id", rs.getString(4)); + assertEquals("def", rs.getString(5)); + assertEquals(database, rs.getString(6)); + assertEquals("cross3", rs.getString(7)); + assertEquals("id_ref1", rs.getString(8)); + assertTrue(rs.getInt(9) == 1 || rs.wasNull()); + assertEquals(DatabaseMetaData.importedKeyCascade, rs.getInt(10)); + if (!isMariaDBServer() && minVersion(8, 0, 0)) { + assertEquals(DatabaseMetaData.importedKeyNoAction, rs.getInt("DELETE_RULE")); + } else { + assertEquals(DatabaseMetaData.importedKeyRestrict, rs.getInt("DELETE_RULE")); + } + assertTrue( + "fk_my_name".equals(rs.getString("FK_NAME")) + || "cross3_ibfk_1".equals(rs.getString("FK_NAME"))); + + assertTrue(rs.next()); + assertEquals("def", rs.getString(1)); + assertEquals(database, rs.getString(2)); + assertEquals("cross2", rs.getString(3)); + assertEquals("id2", rs.getString(4)); + assertEquals("def", rs.getString(5)); + assertEquals(database, rs.getString(6)); + assertEquals("cross3", rs.getString(7)); + assertEquals("id_ref2", rs.getString(8)); + assertTrue(rs.getInt(9) == 2 || rs.wasNull()); + assertEquals(DatabaseMetaData.importedKeyCascade, rs.getInt(10)); + if (!isMariaDBServer() && minVersion(8, 0, 0)) { + assertEquals(DatabaseMetaData.importedKeyNoAction, rs.getInt("DELETE_RULE")); + } else { + assertEquals(DatabaseMetaData.importedKeyRestrict, rs.getInt("DELETE_RULE")); + } + assertTrue("fk_my_name".equals(rs.getString(12)) || "cross3_ibfk_1".equals(rs.getString(12))); + + assertFalse(rs.next()); + } + } + @Test public void getUdtsBasic() throws SQLException { testResultSetColumns( @@ -1494,6 +1893,11 @@ public void testGetSchemas2() throws SQLException { } } assertEquals(true, foundTestUnitsJdbc); + try (Connection con = createCon("&useCatalogTerm=Schema")) { + dbmd = con.getMetaData(); + rs = dbmd.getCatalogs(); + assertFalse(rs.next()); + } } @Test @@ -1902,6 +2306,79 @@ public void getIndexInfo() throws SQLException { assertNull(rs.getString(13)); } + @Test + public void getIndexInfoSchema() throws SQLException { + try (Connection con = createCon("&useCatalogTerm=Schema")) { + DatabaseMetaData meta = con.getMetaData(); + + Common.assertThrowsContains( + SQLException.class, + () -> meta.getIndexInfo(null, null, null, true, true), + "'table' parameter must not be null"); + + ResultSet rs = meta.getIndexInfo(null, null, "get_index_info", false, true); + rs.next(); + assertEquals("def", rs.getString(1)); + assertEquals(database, rs.getString(2)); + assertEquals("get_index_info", rs.getString(3)); + assertFalse(rs.getBoolean(4)); + assertEquals(con.getCatalog(), rs.getString(5)); + assertEquals("PRIMARY", rs.getString(6)); + assertEquals(DatabaseMetaData.tableIndexOther, rs.getShort(7)); + assertEquals(1, rs.getShort(8)); + assertEquals("no", rs.getString(9)); + assertEquals("A", rs.getString(10)); + assertEquals(0L, rs.getLong(11)); + assertNull(rs.getString(12)); + assertNull(rs.getString(13)); + + assertTrue(rs.next()); + assertEquals("def", rs.getString(1)); + assertEquals(database, rs.getString(2)); + assertEquals("get_index_info", rs.getString(3)); + assertTrue(rs.getBoolean(4)); + assertEquals(con.getCatalog(), rs.getString(5)); + assertEquals("ind_cust", rs.getString(6)); + assertEquals(DatabaseMetaData.tableIndexOther, rs.getShort(7)); + assertEquals(1, rs.getShort(8)); + assertEquals("customer_id", rs.getString(9)); + assertEquals("A", rs.getString(10)); + assertEquals(0L, rs.getLong(11)); + assertNull(rs.getString(12)); + assertNull(rs.getString(13)); + + assertTrue(rs.next()); + assertEquals(con.getCatalog(), rs.getString(1)); + assertEquals(database, rs.getString(2)); + assertEquals("get_index_info", rs.getString(3)); + assertTrue(rs.getBoolean(4)); + assertEquals(con.getCatalog(), rs.getString(5)); + assertEquals("ind_prod", rs.getString(6)); + assertEquals(DatabaseMetaData.tableIndexOther, rs.getShort(7)); + assertEquals(1, rs.getShort(8)); + assertEquals("product_category", rs.getString(9)); + assertEquals("A", rs.getString(10)); + assertEquals(0L, rs.getLong(11)); + assertNull(rs.getString(12)); + assertNull(rs.getString(13)); + + assertTrue(rs.next()); + assertEquals(con.getCatalog(), rs.getString(1)); + assertEquals(database, rs.getString(2)); + assertEquals("get_index_info", rs.getString(3)); + assertTrue(rs.getBoolean(4)); + assertEquals(con.getCatalog(), rs.getString(5)); + assertEquals("ind_prod", rs.getString(6)); + assertEquals(DatabaseMetaData.tableIndexOther, rs.getShort(7)); + assertEquals(2, rs.getShort(8)); + assertEquals("product_id", rs.getString(9)); + assertEquals("A", rs.getString(10)); + assertEquals(0L, rs.getLong(11)); + assertNull(rs.getString(12)); + assertNull(rs.getString(13)); + } + } + @Test public void getPseudoColumns() throws SQLException { DatabaseMetaData meta = sharedConn.getMetaData(); @@ -2108,6 +2585,35 @@ public void testMetaCatalog() throws Exception { assertFalse(rs.next()); } + @Test + public void testMetaCatalogSchema() throws Exception { + try (Connection con = createCon("&useCatalogTerm=Schema")) { + DatabaseMetaData meta = con.getMetaData(); + ResultSet rs = meta.getProcedures(null, con.getSchema(), "testMetaCatalog"); + assertTrue(rs.next()); + assertEquals("def", rs.getString(1)); + assertEquals(database, rs.getString(2)); + assertEquals("testMetaCatalog", rs.getString(3)); + assertNull(rs.getString(4)); + assertNull(rs.getString(5)); + assertNull(rs.getString(6)); + assertEquals("comments", rs.getString(7)); + assertEquals(DatabaseMetaData.procedureNoResult, rs.getInt(8)); + assertEquals("testMetaCatalog", rs.getString(9)); + assertFalse(rs.next()); + + // test with bad catalog + rs = meta.getProcedures(null, "yahoooo", "testMetaCatalog"); + assertFalse(rs.next()); + + // test without catalog + rs = meta.getProcedures(null, null, "testMetaCatalog"); + assertTrue(rs.next()); + assertTrue("testMetaCatalog".equals(rs.getString(3))); + assertFalse(rs.next()); + } + } + @Test public void getMetaData() throws SQLException { ResultSet rs = sharedConn.createStatement().executeQuery("SELECT * FROM json_test"); @@ -2191,7 +2697,28 @@ public void foreignKeyTest() throws SQLException { assertTrue(rs.next()); } finally { con.setCatalog(db); - stmt.execute("DROP DATABASE dbTmp"); + } + + try (Connection con2 = createCon("&useCatalogTerm=Schema")) { + dbmd = con.getMetaData(); + rs = dbmd.getImportedKeys(null, null, "tableWithForeignKey"); + assertTrue(rs.next()); + rs.close(); + + rs = dbmd.getImportedKeys(null, "", "tableWithForeignKey"); + assertTrue(rs.next()); + + con2.setCatalog("dbTmp"); + try { + rs = dbmd.getImportedKeys(null, "", "tableWithForeignKey"); + assertTrue(rs.next()); + + rs = dbmd.getImportedKeys(null, null, "tableWithForeignKey"); + assertTrue(rs.next()); + } finally { + con2.setCatalog(db); + stmt.execute("DROP DATABASE dbTmp"); + } } } } diff --git a/src/test/java/org/mariadb/jdbc/integration/DriverTest.java b/src/test/java/org/mariadb/jdbc/integration/DriverTest.java index 03d871253..c1174ce37 100644 --- a/src/test/java/org/mariadb/jdbc/integration/DriverTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/DriverTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/EofTest.java b/src/test/java/org/mariadb/jdbc/integration/EofTest.java index 5f1069eee..c2b913401 100644 --- a/src/test/java/org/mariadb/jdbc/integration/EofTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/EofTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/ErrorTest.java b/src/test/java/org/mariadb/jdbc/integration/ErrorTest.java index 8fb519f94..25f762213 100644 --- a/src/test/java/org/mariadb/jdbc/integration/ErrorTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/ErrorTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/FailoverTest.java b/src/test/java/org/mariadb/jdbc/integration/FailoverTest.java index 5925bfbc9..ecdfc4976 100644 --- a/src/test/java/org/mariadb/jdbc/integration/FailoverTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/FailoverTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/FunctionTest.java b/src/test/java/org/mariadb/jdbc/integration/FunctionTest.java index cdc7696db..49bcc23a3 100644 --- a/src/test/java/org/mariadb/jdbc/integration/FunctionTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/FunctionTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/GaleraTest.java b/src/test/java/org/mariadb/jdbc/integration/GaleraTest.java index e55ae0950..e23b85c3d 100644 --- a/src/test/java/org/mariadb/jdbc/integration/GaleraTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/GaleraTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/GssapiAuthenticationTest.java b/src/test/java/org/mariadb/jdbc/integration/GssapiAuthenticationTest.java index af4016440..bdb468d33 100644 --- a/src/test/java/org/mariadb/jdbc/integration/GssapiAuthenticationTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/GssapiAuthenticationTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -12,7 +12,7 @@ public class GssapiAuthenticationTest extends Common { @Test public void nativePassword() throws Exception { - Assumptions.assumeTrue(isWindows()); + Assumptions.assumeTrue(isWindows() && isMariaDBServer()); Statement stmt = sharedConn.createStatement(); try { stmt.execute("INSTALL SONAME 'auth_gssapi'"); diff --git a/src/test/java/org/mariadb/jdbc/integration/LocalInfileTest.java b/src/test/java/org/mariadb/jdbc/integration/LocalInfileTest.java index c5f1461a7..bed57d7f8 100644 --- a/src/test/java/org/mariadb/jdbc/integration/LocalInfileTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/LocalInfileTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -299,6 +299,56 @@ public void loadDataBasic() throws Exception { } } + @Test + public void loadDataBasicWindows() throws Exception { + Assumptions.assumeTrue(checkLocal()); + Assumptions.assumeTrue( + !"skysql".equals(System.getenv("srv")) && !"skysql-ha".equals(System.getenv("srv"))); + File temp = File.createTempFile("dummyloadDataBasic", ".txt"); + try (BufferedWriter bw = new BufferedWriter(new FileWriter(temp))) { + bw.write("1\thello2\n2\tworld\n"); + } + + try (Connection con = createCon("allowLocalInfile")) { + Statement stmt = con.createStatement(); + stmt.execute("TRUNCATE LocalInfileInputStreamTest2"); + stmt.execute( + "LOAD DATA LOCAL INFILE '" + + temp.getCanonicalPath().replace("\\", "\\\\") + + "' INTO TABLE LocalInfileInputStreamTest2 (id, test)"); + ResultSet rs = stmt.executeQuery("SELECT * FROM LocalInfileInputStreamTest2"); + assertTrue(rs.next()); + assertEquals(1, rs.getInt(1)); + assertEquals("hello2", rs.getString(2)); + assertTrue(rs.next()); + assertEquals(2, rs.getInt(1)); + assertEquals("world", rs.getString(2)); + while (rs.next()) { + System.out.println(rs.getString(2)); + } + assertFalse(rs.next()); + + stmt.execute("TRUNCATE LocalInfileInputStreamTest2"); + stmt.addBatch( + "LOAD DATA LOCAL INFILE '" + + temp.getCanonicalPath().replace("\\", "\\\\") + + "' INTO TABLE LocalInfileInputStreamTest2 (id, test)"); + stmt.addBatch("SET UNIQUE_CHECKS=1"); + stmt.executeBatch(); + + rs = stmt.executeQuery("SELECT * FROM LocalInfileInputStreamTest2"); + assertTrue(rs.next()); + assertEquals(1, rs.getInt(1)); + assertEquals("hello2", rs.getString(2)); + assertTrue(rs.next()); + assertEquals(2, rs.getInt(1)); + assertEquals("world", rs.getString(2)); + assertFalse(rs.next()); + } finally { + temp.delete(); + } + } + @Test public void loadDataValidationFails() throws Exception { Assumptions.assumeTrue(checkLocal()); diff --git a/src/test/java/org/mariadb/jdbc/integration/LoggingTest.java b/src/test/java/org/mariadb/jdbc/integration/LoggingTest.java index 916a5c44d..e1e20318c 100644 --- a/src/test/java/org/mariadb/jdbc/integration/LoggingTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/LoggingTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/MultiHostTest.java b/src/test/java/org/mariadb/jdbc/integration/MultiHostTest.java index cda7d8e22..5bb2cad48 100644 --- a/src/test/java/org/mariadb/jdbc/integration/MultiHostTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/MultiHostTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/MultiPacketTest.java b/src/test/java/org/mariadb/jdbc/integration/MultiPacketTest.java index 08a4fd201..ba1faa494 100644 --- a/src/test/java/org/mariadb/jdbc/integration/MultiPacketTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/MultiPacketTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/MultiQueriesTest.java b/src/test/java/org/mariadb/jdbc/integration/MultiQueriesTest.java index b4ce9c3a9..fac1f0144 100644 --- a/src/test/java/org/mariadb/jdbc/integration/MultiQueriesTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/MultiQueriesTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -69,6 +69,7 @@ public void checkMultiGeneratedKeys() throws SQLException { public void allowMultiQueriesFetchTest() throws SQLException { try (Connection connection = createCon("&allowMultiQueries=true")) { try (Statement stmt = connection.createStatement()) { + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.setFetchSize(1); stmt.execute("SELECT * from AllowMultiQueriesTest;SELECT * from AllowMultiQueriesTest;"); do { diff --git a/src/test/java/org/mariadb/jdbc/integration/ParameterMetaDataTest.java b/src/test/java/org/mariadb/jdbc/integration/ParameterMetaDataTest.java index 3c5fd24fa..50bf44e55 100644 --- a/src/test/java/org/mariadb/jdbc/integration/ParameterMetaDataTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/ParameterMetaDataTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/PoolDataSourceTest.java b/src/test/java/org/mariadb/jdbc/integration/PoolDataSourceTest.java index 46c54bfc2..300140f0b 100644 --- a/src/test/java/org/mariadb/jdbc/integration/PoolDataSourceTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/PoolDataSourceTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -53,8 +53,6 @@ public static void beforeClassDataSourceTest() throws SQLException { stmt.execute( "CREATE TABLE testResetRollback(id int not null primary key auto_increment, test varchar(20))"); stmt.execute("FLUSH TABLES"); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); stmt.execute("FLUSH PRIVILEGES"); } diff --git a/src/test/java/org/mariadb/jdbc/integration/PooledConnectionTest.java b/src/test/java/org/mariadb/jdbc/integration/PooledConnectionTest.java index 2b4a3e895..e4bf9dd8b 100644 --- a/src/test/java/org/mariadb/jdbc/integration/PooledConnectionTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/PooledConnectionTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -79,7 +79,7 @@ public void testPoolFailover() throws Exception { } try (MariaDbPoolDataSource ds = - new MariaDbPoolDataSource(url + "&poolValidMinDelay=1&connectTimeout=10&maxPoolSize=1")) { + new MariaDbPoolDataSource(url + "&poolValidMinDelay=1&connectTimeout=500&maxPoolSize=1")) { PooledConnection pc = ds.getPooledConnection(); pc.getConnection().isValid(1); @@ -240,8 +240,6 @@ public void testPooledConnectionStatementError() throws Exception { + sharedConn.getCatalog() + ".* TO 'dsUser'@'%' IDENTIFIED BY 'MySup8%rPassw@ord'"); } - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); stmt.execute("FLUSH PRIVILEGES"); ConnectionPoolDataSource ds = new MariaDbDataSource(mDefUrl); diff --git a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementMetadataTest.java b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementMetadataTest.java index acd494293..3393d3d59 100644 --- a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementMetadataTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementMetadataTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementParametersTest.java b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementParametersTest.java index f723f2560..4161ae732 100644 --- a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementParametersTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementParametersTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementTest.java b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementTest.java index efae5d761..dfb7e003f 100644 --- a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -88,6 +88,7 @@ public void execute() throws SQLException { private void execute(Connection conn) throws SQLException { Statement stmt = conn.createStatement(); stmt.execute("TRUNCATE prepare1"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement preparedStatement = conn.prepareStatement("INSERT INTO prepare1(t1, t2) VALUES (?,?)")) { preparedStatement.setInt(1, 5); @@ -179,6 +180,8 @@ private void execute(Connection conn) throws SQLException { assertEquals(7, rs.getInt(1)); assertEquals(12, rs.getInt(2)); assertFalse(rs.next()); + } finally { + conn.rollback(); } } @@ -191,6 +194,7 @@ public void executeWithoutAllParameters() throws SQLException { public void executeWithoutAllParameters(Connection con) throws SQLException { Statement stmt = con.createStatement(); stmt.execute("TRUNCATE prepare1"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement preparedStatement = con.prepareStatement("INSERT INTO prepare1(t1, t2) VALUES (?,?)")) { preparedStatement.setInt(2, 10); @@ -207,12 +211,14 @@ public void executeWithoutAllParameters(Connection con) throws SQLException { assertEquals(10, rs.getInt(2)); assertFalse(rs.next()); } + con.rollback(); } @Test public void executeUpdate() throws SQLException { Statement stmt = sharedConn.createStatement(); stmt.execute("TRUNCATE prepare1"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement preparedStatement = sharedConn.prepareStatement("INSERT INTO prepare1(t1, t2) VALUES (?,?)")) { preparedStatement.setInt(1, 5); @@ -247,6 +253,8 @@ public void executeUpdate() throws SQLException { SQLException.class, preparedStatement::executeUpdate, "the given SQL statement produces an unexpected ResultSet object"); + } finally { + sharedConn.rollback(); } } @@ -287,6 +295,7 @@ private void executeQuery(Connection con) throws SQLException { Statement stmt = con.createStatement(); stmt.execute("DROP TABLE IF EXISTS prepare10"); stmt.execute("CREATE TABLE prepare10 (t1 int not null primary key auto_increment, t2 int)"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("INSERT INTO prepare10(t1, t2) VALUES (5,10), (40,20), (127,45)"); try (PreparedStatement preparedStatement = con.prepareStatement("SELECT * FROM prepare10 WHERE t1 > ?")) { @@ -324,6 +333,7 @@ private void executeQuery(Connection con) throws SQLException { preparedStatement.setInt(1, 20); preparedStatement.executeQuery(); } + con.rollback(); } @Test @@ -468,7 +478,8 @@ private void executeWrongBatch(Connection con) throws SQLException { public void executeBatchMultiple() throws SQLException { // xpand don't support DO command Assumptions.assumeFalse(isXpand()); - try (Connection con = createCon("allowMultiQueries&useBulkStmts=false")) { + try (Connection con = + createCon("allowMultiQueries&useBulkStmts=false&useBulkStmtsForInserts=false")) { executeBatchMultiple(con); } } @@ -476,6 +487,7 @@ public void executeBatchMultiple() throws SQLException { private void executeBatchMultiple(Connection con) throws SQLException { Statement stmt = con.createStatement(); stmt.execute("TRUNCATE prepare1"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement preparedStatement = con.prepareStatement("INSERT INTO prepare1(t1, t2) VALUES (?,?);DO 1")) { int[] res = preparedStatement.executeBatch(); @@ -513,6 +525,7 @@ private void executeBatchMultiple(Connection con) throws SQLException { assertEquals(45, rs.getInt(2)); assertFalse(rs.next()); } + con.rollback(); } @Test @@ -926,6 +939,7 @@ private void largeMaxRows(Connection con) throws SQLException { stmt.execute("DROP TABLE IF EXISTS largeMaxRows"); stmt.setFetchSize(3); stmt.execute("CREATE TABLE largeMaxRows(id int)"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement prep = con.prepareStatement("INSERT INTO largeMaxRows(id) VALUE (?)")) { for (int i = 1; i < 51; i++) { prep.setInt(1, i); @@ -981,6 +995,7 @@ private void largeMaxRows(Connection con) throws SQLException { prep.setQueryTimeout(0); prep.setQueryTimeout(0); } + con.rollback(); } @Test @@ -1006,6 +1021,7 @@ private void largeMaxRowsBatch(Connection con) throws SQLException { stmt.execute("DROP TABLE IF EXISTS large_max_rows_batch"); stmt.setFetchSize(3); stmt.execute("CREATE TABLE large_max_rows_batch(id int)"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement prep = con.prepareStatement("INSERT INTO large_max_rows_batch(id) VALUE (?)")) { prepareInsert(prep); @@ -1028,6 +1044,7 @@ private void largeMaxRowsBatch(Connection con) throws SQLException { ResultSet rs = stmt.executeQuery("SELECT count(*) FROM large_max_rows_batch"); rs.next(); assertEquals(12, rs.getInt(1)); + con.rollback(); } @Test @@ -1266,4 +1283,20 @@ public void prepareStmtToString(java.sql.Connection conn, String prefix) throws preparedStatement.toString()); } } + + @Test + public void textPrefix() throws SQLException { + try (Connection con = createCon("&useServerPrepStmts&allowMultiQueries")) { + + try (PreparedStatement prep = + con.prepareStatement("/*client prepare*/SET @name := ?; SELECT @name ")) { + prep.setString(1, "test"); + prep.executeQuery(); + assertTrue(prep.getMoreResults(Statement.CLOSE_CURRENT_RESULT)); + ResultSet rs = prep.getResultSet(); + assertTrue(rs.next()); + assertEquals("test", rs.getString(1)); + } + } + } } diff --git a/src/test/java/org/mariadb/jdbc/integration/ProcedureParameterTest.java b/src/test/java/org/mariadb/jdbc/integration/ProcedureParameterTest.java index 72ab795bd..395e8e0d1 100644 --- a/src/test/java/org/mariadb/jdbc/integration/ProcedureParameterTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/ProcedureParameterTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -50,6 +50,22 @@ public void callUseParameterName() throws Exception { assertEquals(res, 1); } + @Test + public void callWithoutBracket() throws Exception { + // error MXS-3929 for maxscale 6.2.0 + Assumptions.assumeTrue( + !sharedConn.getMetaData().getDatabaseProductVersion().contains("maxScale-6.2.0")); + // https://jira.mariadb.org/browse/XPT-267 + Assumptions.assumeFalse(isXpand()); + + CallableStatement stmt = sharedConn.prepareCall("call useParameterName(?)"); + stmt.setInt(1, 1); + ResultSet rs = stmt.executeQuery(); + assertTrue(rs.next()); + int res = rs.getInt(1); + assertEquals(res, 1); + } + @Test public void callWithStrangeParameter() throws SQLException { // error MXS-3929 for maxscale 6.2.0 @@ -86,15 +102,15 @@ public void basicProcedure() throws SQLException { Assumptions.assumeFalse(isXpand()); Statement stmt = sharedConn.createStatement(); - stmt.execute("DROP PROCEDURE IF EXISTS basic_proc"); + stmt.execute("DROP PROCEDURE IF EXISTS basic_proc2"); stmt.execute( - "CREATE PROCEDURE basic_proc (INOUT t1 INT, IN t2 MEDIUMINT unsigned, OUT t3 DECIMAL(8,3), OUT t4 VARCHAR(20), IN t5 SMALLINT) BEGIN \n" + "CREATE PROCEDURE basic_proc2 (INOUT t1 INT, IN t2 MEDIUMINT unsigned, OUT t3 DECIMAL(8,3), OUT t4 VARCHAR(20), IN t5 SMALLINT) BEGIN \n" + "set t3 = t1 * t5;\n" + "set t1 = t2 * t1;\n" + "set t4 = 'return data';\n" + "END"); try (CallableStatement callableStatement = - sharedConn.prepareCall("{call basic_proc(?,?,?,?)}")) { + sharedConn.prepareCall("{call basic_proc2(?,?,?,?)}")) { ParameterMetaData meta = callableStatement.getParameterMetaData(); assertEquals(5, meta.getParameterCount()); assertEquals("int", meta.getParameterClassName(1)); diff --git a/src/test/java/org/mariadb/jdbc/integration/ProcedureTest.java b/src/test/java/org/mariadb/jdbc/integration/ProcedureTest.java index 660cec93b..46ef29d50 100644 --- a/src/test/java/org/mariadb/jdbc/integration/ProcedureTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/ProcedureTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/ResultSetTest.java b/src/test/java/org/mariadb/jdbc/integration/ResultSetTest.java index 093114883..ef2f500c7 100644 --- a/src/test/java/org/mariadb/jdbc/integration/ResultSetTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/ResultSetTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/Sha256AuthenticationTest.java b/src/test/java/org/mariadb/jdbc/integration/Sha256AuthenticationTest.java index 635bdce0a..ffe0b14dc 100644 --- a/src/test/java/org/mariadb/jdbc/integration/Sha256AuthenticationTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/Sha256AuthenticationTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -88,8 +88,6 @@ public static void init() throws Exception { stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'cachingSha256User2'@'%'"); stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'cachingSha256User3'@'%'"); stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'cachingSha256User4'@'%'"); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); stmt.execute("FLUSH PRIVILEGES"); } @@ -119,8 +117,6 @@ public void nativePassword() throws Exception { stmt.execute( "CREATE USER tmpUser@'%' IDENTIFIED WITH mysql_native_password BY '!Passw0rd3Works'"); stmt.execute("grant all on `" + sharedConn.getCatalog() + "`.* TO tmpUser@'%'"); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); stmt.execute("FLUSH PRIVILEGES"); // reset cache try (Connection con = createCon("user=tmpUser&password=!Passw0rd3Works")) { con.isValid(1); @@ -136,8 +132,6 @@ public void nativePassword() throws Exception { public void cachingSha256Empty() throws Exception { Assumptions.assumeTrue( !isWindows() && !isMariaDBServer() && rsaPublicKey != null && minVersion(8, 0, 0)); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !minVersion(8, 0, 31)); sharedConn.createStatement().execute("FLUSH PRIVILEGES"); // reset cache try (Connection con = createCon("user=cachingSha256User2&allowPublicKeyRetrieval&password=")) { con.isValid(1); @@ -148,8 +142,6 @@ public void cachingSha256Empty() throws Exception { public void wrongRsaPath() throws Exception { Assumptions.assumeTrue( !isWindows() && !isMariaDBServer() && rsaPublicKey != null && minVersion(8, 0, 0)); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); sharedConn.createStatement().execute("FLUSH PRIVILEGES"); // reset cache File tempFile = File.createTempFile("log", ".tmp"); Common.assertThrowsContains( @@ -165,8 +157,6 @@ public void wrongRsaPath() throws Exception { @Test public void cachingSha256Allow() throws Exception { Assumptions.assumeTrue(!isMariaDBServer() && rsaPublicKey != null && minVersion(8, 0, 0)); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !minVersion(8, 0, 31)); sharedConn.createStatement().execute("FLUSH PRIVILEGES"); // reset cache try (Connection con = createCon("user=cachingSha256User3&allowPublicKeyRetrieval&password=!Passw0rd3Works")) { @@ -177,8 +167,6 @@ public void cachingSha256Allow() throws Exception { @Test public void cachingSha256PluginTest() throws Exception { Assumptions.assumeTrue(!isMariaDBServer() && rsaPublicKey != null && minVersion(8, 0, 0)); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); sharedConn.createStatement().execute("FLUSH PRIVILEGES"); // reset cache try (Connection con = @@ -215,8 +203,6 @@ public void cachingSha256PluginTest() throws Exception { @Test public void cachingSha256PluginTestWithoutServerRsaKey() throws Exception { Assumptions.assumeTrue(!isWindows() && minVersion(8, 0, 0)); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !minVersion(8, 0, 31)); sharedConn.createStatement().execute("FLUSH PRIVILEGES"); // reset cache try (Connection con = createCon("user=cachingSha256User&password=!Passw0rd3Works&allowPublicKeyRetrieval")) { @@ -227,8 +213,6 @@ public void cachingSha256PluginTestWithoutServerRsaKey() throws Exception { @Test public void cachingSha256PluginTestException() throws Exception { Assumptions.assumeTrue(!isMariaDBServer() && minVersion(8, 0, 0)); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31)); sharedConn.createStatement().execute("FLUSH PRIVILEGES"); // reset cache Common.assertThrowsContains( diff --git a/src/test/java/org/mariadb/jdbc/integration/SslTest.java b/src/test/java/org/mariadb/jdbc/integration/SslTest.java index 5d3e89210..8d7fd803f 100644 --- a/src/test/java/org/mariadb/jdbc/integration/SslTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/SslTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -44,8 +44,6 @@ public static void beforeAll2() throws SQLException { createSslUser("mutualAuthUser", "REQUIRE X509"); Statement stmt = sharedConn.createStatement(); - // mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now - Assumptions.assumeTrue(isMariaDBServer() || (!isMariaDBServer() && !exactVersion(8, 0, 31))); stmt.execute("FLUSH PRIVILEGES"); sslPort = System.getenv("TEST_MAXSCALE_TLS_PORT") == null @@ -86,9 +84,13 @@ private static void createSslUser(String user, String requirement) throws SQLExc private String getSslVersion(Connection con) throws SQLException { Statement stmt = con.createStatement(); - ResultSet rs = stmt.executeQuery("show STATUS LIKE 'Ssl_version'"); - if (rs.next()) { - return rs.getString(2); + if ("maxscale".equals(System.getenv("srv")) || "skysql-ha".equals(System.getenv("srv"))) { + return "ok"; + } else { + ResultSet rs = stmt.executeQuery("show STATUS LIKE 'Ssl_version'"); + if (rs.next()) { + return rs.getString(2); + } } return null; } @@ -166,7 +168,30 @@ public void enabledSslCipherSuites() throws SQLException { } @Test - public void mutualAuthSsl() throws SQLException { + public void errorUsingWrongTypeOfKeystore() throws Exception { + Assumptions.assumeTrue( + !"maxscale".equals(System.getenv("srv")) && !"skysql-ha".equals(System.getenv("srv"))); + String pkcsFile = System.getenv("TEST_DB_CLIENT_PKCS"); + Assumptions.assumeTrue(pkcsFile != null); + + if (checkFileExists(pkcsFile) != null) { + // wrong keystore type + assertThrows( + SQLNonTransientConnectionException.class, + () -> + createCon( + baseMutualOptions + + "&sslMode=verify-ca&serverSslCert=" + + pkcsFile + + "&trustStoreType=JKS&keyStore=" + + System.getenv("TEST_DB_CLIENT_PKCS") + + "&keyStorePassword=kspass", + sslPort)); + } + } + + @Test + public void mutualAuthSsl() throws Exception { Assumptions.assumeTrue( !"maxscale".equals(System.getenv("srv")) && !"skysql-ha".equals(System.getenv("srv"))); Assumptions.assumeTrue(System.getenv("TEST_DB_CLIENT_PKCS") != null); @@ -256,7 +281,8 @@ public void mutualAuthSsl() throws SQLException { @Test public void certificateMandatorySsl() throws Throwable { - + Assumptions.assumeTrue( + !"maxscale".equals(System.getenv("srv")) && !"skysql-ha".equals(System.getenv("srv"))); String serverCertPath = retrieveCertificatePath(); Assumptions.assumeTrue(serverCertPath != null, "Canceled, server certificate not provided"); @@ -310,15 +336,18 @@ public void certificateMandatorySsl() throws Throwable { createCon(baseOptions + "&sslMode=VERIFY_CA&serverSslCert=" + certificateString, sslPort)) { assertNotNull(getSslVersion(con)); } - - assertThrows( + assertThrowsContains( SQLNonTransientConnectionException.class, - () -> createCon(baseOptions + "&sslMode=VERIFY_CA", sslPort)); - assertThrows( - SQLInvalidAuthorizationSpecException.class, - () -> - createCon( - baseMutualOptions + "&sslMode=VERIFY_CA&serverSslCert=" + serverCertPath, sslPort)); + () -> createBasicCon(baseOptions + "&sslMode=VERIFY_CA", sslPort), + "unable to find valid certification"); + if (!"maxscale".equals(System.getenv("srv"))) { + assertThrows( + SQLInvalidAuthorizationSpecException.class, + () -> + createBasicCon( + baseMutualOptions + "&sslMode=VERIFY_CA&serverSslCert=" + serverCertPath, + sslPort)); + } } private String getServerCertificate(String serverCertPath) throws SQLException { @@ -338,6 +367,9 @@ private String getServerCertificate(String serverCertPath) throws SQLException { public static String retrieveCertificatePath() throws Exception { String serverCertificatePath = checkFileExists(System.getProperty("serverCertificatePath")); + if (serverCertificatePath == null) { + serverCertificatePath = checkFileExists(System.getenv("TEST_DB_SERVER_CERT")); + } // try local server if (serverCertificatePath == null diff --git a/src/test/java/org/mariadb/jdbc/integration/StatementTest.java b/src/test/java/org/mariadb/jdbc/integration/StatementTest.java index df9fd3873..a090d1dee 100644 --- a/src/test/java/org/mariadb/jdbc/integration/StatementTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/StatementTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -1029,4 +1029,72 @@ public void statementEnquoteNCharLiteral() throws SQLException { Statement stmt = sharedConn.createStatement(); assertEquals("N'good''one'", stmt.enquoteNCharLiteral("good'one")); } + + @Test + public void generatedKey() throws SQLException { + java.sql.Statement stmt = sharedConn.createStatement(); + stmt.execute("DROP TABLE IF EXISTS tt"); + stmt.execute("CREATE TABLE tt (id int PRIMARY KEY NOT NULL AUTO_INCREMENT, t1 varchar(10))"); + stmt.execute("INSERT INTO tt(t1) VALUES ('t1'), ('t2'), ('t3')"); + stmt.execute("FLUSH TABLES"); + + stmt.executeBatch(); + stmt.addBatch("UPDATE tt set t1 = 't-1' WHERE id = 1"); + stmt.addBatch("INSERT INTO tt(t1) VALUES ('t4')"); + stmt.addBatch("INSERT INTO tt(t1) VALUES ('t5')"); + stmt.addBatch("UPDATE tt set t1 = 't-6' WHERE id = 1"); + stmt.executeBatch(); + ResultSet rs = stmt.getGeneratedKeys(); + assertTrue(rs.next()); + assertEquals(4, rs.getInt(1)); + assertTrue(rs.next()); + assertEquals(5, rs.getInt(1)); + assertFalse(rs.next()); + + try (PreparedStatement prep = + sharedConn.prepareStatement( + "INSERT IGNORE INTO tt(id, t1) VALUES (?,?)", + java.sql.Statement.RETURN_GENERATED_KEYS)) { + prep.setInt(1, 5); + prep.setString(2, "t55"); + prep.addBatch(); + prep.setInt(1, 6); + prep.setString(2, "t6"); + prep.addBatch(); + prep.setNull(1, Types.INTEGER); + prep.setString(2, "t7"); + prep.addBatch(); + prep.executeBatch(); + + rs = prep.getGeneratedKeys(); + assertTrue(rs.next()); + assertEquals(6, rs.getInt(1)); + assertTrue(rs.next()); + assertEquals(7, rs.getInt(1)); + assertFalse(rs.next()); + } + + try (PreparedStatement prep = + sharedConnBinary.prepareStatement( + "INSERT IGNORE INTO tt(id, t1) VALUES (?,?)", + java.sql.Statement.RETURN_GENERATED_KEYS)) { + prep.setInt(1, 5); + prep.setString(2, "t55"); + prep.addBatch(); + prep.setInt(1, 8); + prep.setString(2, "t8"); + prep.addBatch(); + prep.setNull(1, Types.INTEGER); + prep.setString(2, "t9"); + prep.addBatch(); + prep.executeBatch(); + + rs = prep.getGeneratedKeys(); + assertTrue(rs.next()); + assertEquals(8, rs.getInt(1)); + assertTrue(rs.next()); + assertEquals(9, rs.getInt(1)); + assertFalse(rs.next()); + } + } } diff --git a/src/test/java/org/mariadb/jdbc/integration/UnixsocketTest.java b/src/test/java/org/mariadb/jdbc/integration/UnixsocketTest.java index 0852b340d..2e81fd1d0 100644 --- a/src/test/java/org/mariadb/jdbc/integration/UnixsocketTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/UnixsocketTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java b/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java index 4d590297c..d085829d4 100644 --- a/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; @@ -80,8 +80,8 @@ public static void beforeAll2() throws SQLException { @Test public void testNoPrimaryKey() throws Exception { Statement stmt = sharedConn.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("INSERT INTO testnoprimarykey VALUES (1, 't1'), (2, 't2')"); - try (PreparedStatement preparedStatement = sharedConn.prepareStatement( "SELECT * FROM testnoprimarykey", @@ -94,11 +94,13 @@ public void testNoPrimaryKey() throws Exception { () -> rs.updateString(1, "1"), "ResultSet cannot be updated. Cannot update rows, since no primary field is present in query"); } + sharedConn.rollback(); } @Test public void testBasicPrimaryKey() throws Exception { Statement stmt = sharedConn.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("INSERT INTO testbasicprimarykey VALUES (1, 't1'), (2, 't2')"); try (PreparedStatement preparedStatement = @@ -113,6 +115,7 @@ public void testBasicPrimaryKey() throws Exception { () -> rs.updateString(1, "val"), "ResultSet cannot be updated. Cannot update rows, since primary field id is not present in query"); } + sharedConn.rollback(); } @Test @@ -155,6 +158,7 @@ public void testMultipleTable() throws Exception { @Test public void testOneNoTable() throws Exception { Statement stmt = sharedConn.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.executeQuery("INSERT INTO testOneNoTable(t1) values ('1')"); try (PreparedStatement preparedStatement = @@ -170,11 +174,13 @@ public void testOneNoTable() throws Exception { "ResultSet cannot be updated. " + "The result-set contains fields without without any database/table information"); } + sharedConn.rollback(); } @Test public void testAutoIncrement() throws Exception { Statement stmt = sharedConn.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER PreparedStatement pstmt = sharedConn.prepareStatement("INSERT INTO testAutoIncrement(t1) values (?)"); pstmt.setString(1, "1"); @@ -191,7 +197,7 @@ public void testAutoIncrement() throws Exception { rs.updateString(2, "0-1"); rs.insertRow(); } - + stmt.execute("FLUSH TABLES"); ResultSet rs = stmt.executeQuery("SELECT * FROM testAutoIncrement"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); @@ -200,6 +206,7 @@ public void testAutoIncrement() throws Exception { assertEquals(2, rs.getInt(1)); assertEquals("0-1", rs.getString(2)); assertFalse(rs.next()); + sharedConn.rollback(); } @Test @@ -216,6 +223,8 @@ public void testMultipleDatabase() throws Exception { "CREATE TABLE testMultipleDatabase(`id1` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50) NULL,PRIMARY KEY (`id1`))"); stmt.execute( "CREATE TABLE testConnectorJ.testMultipleDatabase(`id2` INT NOT NULL AUTO_INCREMENT,`t2` VARCHAR(50) NULL,PRIMARY KEY (`id2`))"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER + stmt.executeQuery("INSERT INTO testMultipleDatabase(t1) values ('1')"); stmt.executeQuery("INSERT INTO testConnectorJ.testMultipleDatabase(t2) values ('2')"); @@ -233,6 +242,7 @@ public void testMultipleDatabase() throws Exception { () -> rs.updateString("t1", "new value"), "The result-set contains more than one database"); } + sharedConn.rollback(); } @Test @@ -292,6 +302,8 @@ public void testMeta() throws Exception { @Test public void testUpdateWhenFetch() throws Exception { Statement stmt = sharedConn.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER + PreparedStatement pstmt = sharedConn.prepareStatement("INSERT INTO testUpdateWhenFetch(t1,t2) values (?, ?)"); for (int i = 1; i < 100; i++) { @@ -373,6 +385,7 @@ public void testUpdateWhenFetch() throws Exception { assertEquals(i + "-2", rs.getString(3)); } assertFalse(rs.next()); + sharedConn.rollback(); } @Test @@ -385,6 +398,7 @@ public void testPrimaryGenerated() throws Exception { + "`t1` VARCHAR(50) NOT NULL," + "`t2` VARCHAR(50) NULL default 'default-value'," + "PRIMARY KEY (`id`))"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement preparedStatement = sharedConn.prepareStatement( @@ -419,7 +433,7 @@ public void testPrimaryGenerated() throws Exception { assertFalse(rs.next()); } - + stmt.execute("FLUSH TABLES"); ResultSet rs = stmt.executeQuery("SELECT id, t1, t2 FROM PrimaryGenerated"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); @@ -432,6 +446,7 @@ public void testPrimaryGenerated() throws Exception { assertEquals("default-value", rs.getString(3)); assertFalse(rs.next()); + sharedConn.rollback(); } @Test @@ -444,6 +459,7 @@ public void testPrimaryGeneratedDefault() throws Exception { + "`t1` VARCHAR(50) NOT NULL default 'default-value1'," + "`t2` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," + "PRIMARY KEY (`id`))"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement preparedStatement = sharedConn.prepareStatement( @@ -497,7 +513,7 @@ public void testPrimaryGeneratedDefault() throws Exception { assertNotNull(rs.getDate(3)); assertFalse(rs.next()); } - + stmt.execute("FLUSH TABLES"); ResultSet rs = stmt.executeQuery("SELECT id, t1, t2 FROM testPrimaryGeneratedDefault"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); @@ -510,6 +526,7 @@ public void testPrimaryGeneratedDefault() throws Exception { assertNotNull(rs.getDate(3)); assertFalse(rs.next()); + sharedConn.rollback(); } @Test @@ -524,6 +541,7 @@ public void testDelete() throws Exception { + "PRIMARY KEY (`id`,`id2`))"); stmt = sharedConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("INSERT INTO testDelete values (1,-1,'1'), (2,-2,'2'), (3,-3,'3')"); try (PreparedStatement preparedStatement = @@ -554,6 +572,7 @@ public void testDelete() throws Exception { rs.absolute(1); rs.deleteRow(); Common.assertThrowsContains(SQLException.class, () -> rs.getInt(1), "wrong row position"); + sharedConn.rollback(); } @Test @@ -566,6 +585,7 @@ public void testUpdateChangingMultiplePrimaryKey() throws Exception { + "`id2` INT NOT NULL," + "`t1` VARCHAR(50)," + "PRIMARY KEY (`id`,`id2`))"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute( "INSERT INTO testUpdateChangingMultiplePrimaryKey values (1,-1,'1'), (2,-2,'2'), (3,-3,'3')"); try (PreparedStatement preparedStatement = @@ -605,6 +625,7 @@ public void testUpdateChangingMultiplePrimaryKey() throws Exception { assertEquals("4", rs.getString(3)); assertFalse(rs.next()); + sharedConn.rollback(); } @Test @@ -791,7 +812,7 @@ private void refreshRow(Connection con) throws SQLException { Statement stmt = con.createStatement(); stmt.execute("DROP TABLE IF EXISTS refreshRow"); stmt.execute("CREATE TABLE refreshRow(id int not null primary key, strm text)"); - + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER java.sql.Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); st.execute("INSERT INTO refreshRow values (1, '555')"); @@ -817,6 +838,7 @@ private void refreshRow(Connection con) throws SQLException { assertFalse(rs.next()); assertThrows(SQLException.class, rs::refreshRow); + con.rollback(); } @Test @@ -941,7 +963,7 @@ private void cancelRowUpdatesTest(Connection con) throws SQLException { stmt.execute("CREATE TABLE cancelRowUpdatesTest(c text, id int primary key)"); stmt.execute("INSERT INTO cancelRowUpdatesTest(id,c) values (1,'1'), (2,'2'),(3,'3'),(4,'4')"); stmt.execute("FLUSH TABLES"); - + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement preparedStatement = con.prepareStatement( "select id,c from cancelRowUpdatesTest order by id", @@ -966,6 +988,7 @@ private void cancelRowUpdatesTest(Connection con) throws SQLException { assertTrue(rs.next()); assertEquals("2bis", rs.getString("c")); } + con.rollback(); } @Test @@ -982,6 +1005,7 @@ private void deleteRowsTest(Connection con) throws SQLException { Statement stmt = con.createStatement(); stmt.execute("DROP TABLE IF EXISTS deleteRows"); stmt.execute("CREATE TABLE deleteRows(c text, id int primary key)"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("INSERT INTO deleteRows(id,c) values (1,'1'), (2,'2'),(3,'3'),(4,'4')"); try (PreparedStatement preparedStatement = @@ -1005,6 +1029,7 @@ private void deleteRowsTest(Connection con) throws SQLException { rs.deleteRow(); assertEquals(2, rs.getInt("id")); } + con.rollback(); } @Test @@ -1012,6 +1037,7 @@ public void updatePosTest() throws SQLException { Statement stmt = sharedConn.createStatement(); stmt.execute("DROP TABLE IF EXISTS updatePosTest"); stmt.execute("CREATE TABLE updatePosTest(c text, id int primary key)"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("INSERT INTO updatePosTest(id,c) values (1,'1')"); try (PreparedStatement preparedStatement = @@ -1043,6 +1069,7 @@ public void updatePosTest() throws SQLException { Common.assertThrowsContains( SQLException.class, rs::deleteRow, "Current position is after the last row"); } + sharedConn.rollback(); } /** @@ -1056,6 +1083,7 @@ public void repeatedFieldUpdatable() throws SQLException { stmt.execute("DROP TABLE IF EXISTS repeatedFieldUpdatable"); stmt.execute( "CREATE TABLE repeatedFieldUpdatable(t1 varchar(50) NOT NULL, t2 varchar(50), PRIMARY KEY (t1))"); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("insert into repeatedFieldUpdatable values ('gg', 'hh'), ('jj', 'll')"); PreparedStatement preparedStatement = @@ -1067,11 +1095,13 @@ public void repeatedFieldUpdatable() throws SQLException { while (rs.next()) { rs.getObject(3); } + sharedConn.rollback(); } @Test public void updatableDefaultPrimaryField() throws SQLException { Assumptions.assumeTrue(isMariaDBServer() && minVersion(10, 2, 0)); + sharedConn.createStatement().execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER String sql = "SELECT t.* FROM testDefaultUUID t WHERE 1 = 2"; try (PreparedStatement pstmt = sharedConn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { @@ -1105,6 +1135,7 @@ public void updatableDefaultPrimaryField() throws SQLException { assertEquals("de6f7774-e399-11ea-aa68-c8348e0fed44", rs.getString(1)); assertEquals("x", rs.getString(2)); } + sharedConn.rollback(); } @Test @@ -1141,6 +1172,7 @@ public void expectedErrorField() throws SQLException { @Test public void addAfterDataFull() throws SQLException { Statement stmt = sharedConn.createStatement(); + sharedConn.createStatement().execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute( "INSERT INTO test_update_max(t1) value ('1'), ('2'), ('3'), ('4'), ('5'), ('6'), ('7'), ('8'), ('9'), ('10')"); try (PreparedStatement preparedStatement = @@ -1155,5 +1187,6 @@ public void addAfterDataFull() throws SQLException { for (int i = 0; i < 11; i++) rs.next(); assertEquals("11", rs.getString("t1")); } + sharedConn.rollback(); } } diff --git a/src/test/java/org/mariadb/jdbc/integration/XaTest.java b/src/test/java/org/mariadb/jdbc/integration/XaTest.java index af35bc169..586679f21 100644 --- a/src/test/java/org/mariadb/jdbc/integration/XaTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/XaTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/BinaryCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/BinaryCodecTest.java index 13b5a085d..98f104d57 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/BinaryCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/BinaryCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java index 95da615ab..5e21c319f 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/BlobCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/BlobCodecTest.java index 95ecaa4fd..0966a9266 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/BlobCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/BlobCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/CharCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/CharCodecTest.java index 78a71086d..d7bb57d67 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/CharCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/CharCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/ClobCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/ClobCodecTest.java index 81db4c956..3c1f19722 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/ClobCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/ClobCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/CommonCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/CommonCodecTest.java index 99bcad22c..582be2ff3 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/CommonCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/CommonCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/DateCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/DateCodecTest.java index 410dea67e..7325463aa 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/DateCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/DateCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java index cd9ac5e23..1fe600f50 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/DecimalCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/DecimalCodecTest.java index bd7586fee..96efaa750 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/DecimalCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/DecimalCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; @@ -776,6 +776,7 @@ public void getMetaData() throws SQLException { @Test public void setParameter() throws SQLException { + sharedConn.createStatement().execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER try (PreparedStatement prep = sharedConn.prepareStatement("INSERT INTO DecimalCodec2 VALUE (?, ?, ?, ?)")) { prep.setBigDecimal(1, new BigDecimal("789.123")); @@ -795,6 +796,7 @@ public void setParameter() throws SQLException { () -> prep.setObject(4, this), "Type org.mariadb.jdbc.integration.codec.DecimalCodecTest not supported type"); } + sharedConn.rollback(); } @Test diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/DoubleCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/DoubleCodecTest.java index b21bf15d1..d383bcdcd 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/DoubleCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/DoubleCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/EnumCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/EnumCodecTest.java index cafa8f571..c0351b130 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/EnumCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/EnumCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/FloatCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/FloatCodecTest.java index 11e98164a..925c2036a 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/FloatCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/FloatCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java index 73cd3da99..79e985871 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/IntCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/IntCodecTest.java index ea91e5b66..9b95995fc 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/IntCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/IntCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java index e7057f049..60540f711 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/LongCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/LongCodecTest.java index e71f3de79..68b465d2d 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/LongCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/LongCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MediumIntCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MediumIntCodecTest.java index 4958ba26c..4352c99ee 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/MediumIntCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/MediumIntCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java index 05e1282cb..62f84f70c 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java index 984611bcc..69120c740 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java index 05744dbde..632230d7f 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/NullCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/NullCodecTest.java index 2bea3d80b..ce116ca3f 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/NullCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/NullCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java index 75d0f2f87..be0f674da 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java index 69e738f97..6bb74431d 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; @@ -332,13 +332,16 @@ public void getObjectType(ResultSet rs) throws Exception { @Test public void getMetaData() throws SQLException { - getMetaData(sharedConn, false); + getMetaData(sharedConn, false, false); try (org.mariadb.jdbc.Connection con = createCon("geometryDefaultType=default")) { - getMetaData(con, true); + getMetaData(con, true, false); + } + try (org.mariadb.jdbc.Connection con = createCon("useCatalogTerm=Schema")) { + getMetaData(con, false, true); } } - private void getMetaData(org.mariadb.jdbc.Connection con, boolean geoDefault) + private void getMetaData(org.mariadb.jdbc.Connection con, boolean geoDefault, boolean useSchema) throws SQLException { ResultSet rs = getPrepare(con); ResultSetMetaData meta = rs.getMetaData(); @@ -347,7 +350,8 @@ private void getMetaData(org.mariadb.jdbc.Connection con, boolean geoDefault) } else { assertEquals("GEOMETRY", meta.getColumnTypeName(1)); } - assertEquals(sharedConn.getCatalog(), meta.getCatalogName(1)); + assertEquals(useSchema ? "def" : database, meta.getCatalogName(1)); + assertEquals(useSchema ? database : "", meta.getSchemaName(1)); assertEquals( (geoDefault ? (hasCapability(Capabilities.EXTENDED_TYPE_INFO) @@ -360,7 +364,6 @@ private void getMetaData(org.mariadb.jdbc.Connection con, boolean geoDefault) assertEquals(Types.VARBINARY, meta.getColumnType(1)); assertEquals(4, meta.getColumnCount()); assertEquals(0, meta.getScale(1)); - assertEquals("", meta.getSchemaName(1)); } @Test diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/SmallIntCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/SmallIntCodecTest.java index b2626680b..39b07a25a 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/SmallIntCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/SmallIntCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/TimeCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/TimeCodecTest.java index 38b493153..4b68e51ca 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/TimeCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/TimeCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/TinyIntCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/TinyIntCodecTest.java index 6b44133be..9e419ac27 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/TinyIntCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/TinyIntCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/UuidCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/UuidCodecTest.java index e94a740b3..fe1378b45 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/UuidCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/UuidCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/VarbinaryCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/VarbinaryCodecTest.java index db6a17905..3ec8b48fa 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/VarbinaryCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/VarbinaryCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/VarcharCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/VarcharCodecTest.java index 57a99420c..69ad76727 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/VarcharCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/VarcharCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; @@ -1067,9 +1067,11 @@ public void wrongUtf8String() throws SQLException { private void wrongUtf8(Connection con, String wrong) throws SQLException { java.sql.Statement stmt = con.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("INSERT INTO StringCodecWrong VALUES ('" + wrong + "')"); ResultSet rs = stmt.executeQuery("SELECT * FROM StringCodecWrong"); rs.next(); assertEquals(wrong, rs.getString(1)); + con.rollback(); } } diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/YearCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/YearCodecTest.java index 2b89776ff..614830e4a 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/YearCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/YearCodecTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.codec; diff --git a/src/test/java/org/mariadb/jdbc/integration/resultset/ReadResultSetTest.java b/src/test/java/org/mariadb/jdbc/integration/resultset/ReadResultSetTest.java index 511b65b8e..feeed687b 100644 --- a/src/test/java/org/mariadb/jdbc/integration/resultset/ReadResultSetTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/resultset/ReadResultSetTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.resultset; @@ -234,6 +234,7 @@ public void wrongIndex() throws SQLException { @Test public void isBeforeFirstFetchTest() throws SQLException { Statement stmt = sharedConn.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.setFetchSize(1); ResultSet rs = stmt.executeQuery("SELECT * FROM ResultSetTest"); assertTrue(rs.isBeforeFirst()); @@ -244,5 +245,6 @@ public void isBeforeFirstFetchTest() throws SQLException { rs.close(); Common.assertThrowsContains( SQLException.class, rs::isBeforeFirst, "Operation not permit on a closed resultSet"); + sharedConn.rollback(); } } diff --git a/src/test/java/org/mariadb/jdbc/integration/resultset/ResultSetMetadataTest.java b/src/test/java/org/mariadb/jdbc/integration/resultset/ResultSetMetadataTest.java index 91ae52f16..970642c1e 100644 --- a/src/test/java/org/mariadb/jdbc/integration/resultset/ResultSetMetadataTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/resultset/ResultSetMetadataTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.resultset; @@ -44,6 +44,7 @@ public static void beforeAll2() throws SQLException { @Test public void metaDataTest() throws SQLException { Statement stmt = sharedConn.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("insert into test_rsmd (id_col,nullable_col,unikey_col) values (null, 'hej', 9)"); ResultSet rs = stmt.executeQuery( @@ -103,6 +104,7 @@ public void metaDataTest() throws SQLException { assertTrue(rsmd2.isReadOnly(1)); assertFalse(rsmd2.isWritable(1)); assertFalse(rsmd2.isDefinitelyWritable(1)); + sharedConn.rollback(); } @Test @@ -119,6 +121,7 @@ public void conj17() throws Exception { @Test public void conj84() throws Exception { Statement stmt = sharedConn.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("INSERT INTO resultsetmetadatatest1 VALUES (1, 'foo')"); stmt.execute("INSERT INTO resultsetmetadatatest2 VALUES (2, 'bar')"); ResultSet rs = @@ -133,6 +136,7 @@ public void conj84() throws Exception { assertEquals(rs.findColumn("resultsetmetadatatest1.name"), 2); assertEquals(rs.findColumn("resultsetmetadatatest2.id"), 3); assertEquals(rs.findColumn("resultsetmetadatatest2.name"), 4); + sharedConn.rollback(); } @Test @@ -142,7 +146,7 @@ public void testAlias() throws Exception { stmt.execute("DROP TABLE IF EXISTS testAlias2"); stmt.execute("CREATE TABLE testAlias(id int, name varchar(20))"); stmt.execute("CREATE TABLE testAlias2(id2 int, name2 varchar(20))"); - + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER stmt.execute("INSERT INTO testAlias VALUES (1, 'foo')"); stmt.execute("INSERT INTO testAlias2 VALUES (2, 'bar')"); ResultSet rs = @@ -186,6 +190,7 @@ public void testAlias() throws Exception { sqle, () -> rs.findColumn("alias2.name22"), "Unknown label 'alias2.name22'"); Common.assertThrowsContains(sqle, () -> rs.findColumn(""), "Unknown label ''"); Common.assertThrowsContains(sqle, () -> rs.findColumn(null), "null is not a valid label value"); + sharedConn.rollback(); } @Test diff --git a/src/test/java/org/mariadb/jdbc/integration/resultset/RowChangeTest.java b/src/test/java/org/mariadb/jdbc/integration/resultset/RowChangeTest.java index f22c9c1e0..0f74e0c0e 100644 --- a/src/test/java/org/mariadb/jdbc/integration/resultset/RowChangeTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/resultset/RowChangeTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.resultset; @@ -43,6 +43,7 @@ public void next() throws SQLException { @Test public void isAfterLast() throws SQLException { Statement stmt = sharedConn.createStatement(); + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER ResultSet rs = stmt.executeQuery("SELECT * FROM ResultSetTest"); for (int i = 1; i < 9; i++) { assertTrue(rs.next()); @@ -52,6 +53,7 @@ public void isAfterLast() throws SQLException { assertFalse(rs.isAfterLast()); assertFalse(rs.next()); assertTrue(rs.isAfterLast()); + sharedConn.rollback(); } @Test diff --git a/src/test/java/org/mariadb/jdbc/integration/resultset/StreamingRowChangeTest.java b/src/test/java/org/mariadb/jdbc/integration/resultset/StreamingRowChangeTest.java index a83faf9ec..f4ac13ac6 100644 --- a/src/test/java/org/mariadb/jdbc/integration/resultset/StreamingRowChangeTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/resultset/StreamingRowChangeTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.resultset; @@ -96,6 +96,7 @@ public void isAfterLast() throws SQLException { } public void isAfterLast(Statement stmt) throws SQLException { + stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER ResultSet rs = stmt.executeQuery("SELECT * FROM ResultSetTest"); for (int i = 1; i < 9; i++) { assertTrue(rs.next()); @@ -110,6 +111,7 @@ public void isAfterLast(Statement stmt) throws SQLException { assertFalse(rs.isAfterLast()); assertFalse(rs.next()); assertFalse(rs.isAfterLast()); + sharedConn.rollback(); } @Test diff --git a/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxy.java b/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxy.java index 56032fd06..5cb01193d 100644 --- a/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxy.java +++ b/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxy.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.tools; diff --git a/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxySocket.java b/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxySocket.java index 33367c0b3..6e46bc941 100644 --- a/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxySocket.java +++ b/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxySocket.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.tools; diff --git a/src/test/java/org/mariadb/jdbc/integration/util/Env2CredentialPlugin.java b/src/test/java/org/mariadb/jdbc/integration/util/Env2CredentialPlugin.java index bc26e52f2..72ec03d8d 100644 --- a/src/test/java/org/mariadb/jdbc/integration/util/Env2CredentialPlugin.java +++ b/src/test/java/org/mariadb/jdbc/integration/util/Env2CredentialPlugin.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.util; diff --git a/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryBasicTest.java b/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryBasicTest.java index adc80c7d5..1ecc12b7e 100644 --- a/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryBasicTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryBasicTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.util; diff --git a/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryTest.java b/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryTest.java index 1f94f8a16..3b5a9a933 100644 --- a/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.integration.util; diff --git a/src/test/java/org/mariadb/jdbc/unit/client/HostnameVerifierTest.java b/src/test/java/org/mariadb/jdbc/unit/client/HostnameVerifierTest.java index d8b137004..0f7abf5f9 100644 --- a/src/test/java/org/mariadb/jdbc/unit/client/HostnameVerifierTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/client/HostnameVerifierTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.client; diff --git a/src/test/java/org/mariadb/jdbc/unit/client/PrepareCacheTest.java b/src/test/java/org/mariadb/jdbc/unit/client/PrepareCacheTest.java index 4f06e3426..6e5b31456 100644 --- a/src/test/java/org/mariadb/jdbc/unit/client/PrepareCacheTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/client/PrepareCacheTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.client; diff --git a/src/test/java/org/mariadb/jdbc/unit/client/ServerVersionUtilityTest.java b/src/test/java/org/mariadb/jdbc/unit/client/ServerVersionUtilityTest.java index 21075333f..717635e1f 100644 --- a/src/test/java/org/mariadb/jdbc/unit/client/ServerVersionUtilityTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/client/ServerVersionUtilityTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.client; diff --git a/src/test/java/org/mariadb/jdbc/unit/client/result/CompleteResultTest.java b/src/test/java/org/mariadb/jdbc/unit/client/result/CompleteResultTest.java index a9e615987..170910ac5 100644 --- a/src/test/java/org/mariadb/jdbc/unit/client/result/CompleteResultTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/client/result/CompleteResultTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.client.result; diff --git a/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509KeyManagerTest.java b/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509KeyManagerTest.java index b471f2aad..d4a0e315b 100644 --- a/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509KeyManagerTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509KeyManagerTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.client.tls; diff --git a/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509TrustingManagerTest.java b/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509TrustingManagerTest.java index b8dd9f596..484a62731 100644 --- a/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509TrustingManagerTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509TrustingManagerTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.client.tls; diff --git a/src/test/java/org/mariadb/jdbc/unit/export/HaModeTest.java b/src/test/java/org/mariadb/jdbc/unit/export/HaModeTest.java new file mode 100644 index 000000000..b4bb8d3b1 --- /dev/null +++ b/src/test/java/org/mariadb/jdbc/unit/export/HaModeTest.java @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (c) 2012-2014 Monty Program Ab +// Copyright (c) 2023 MariaDB Corporation Ab + +package org.mariadb.jdbc.unit.export; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import org.junit.jupiter.api.Test; +import org.mariadb.jdbc.HostAddress; +import org.mariadb.jdbc.export.HaMode; + +public class HaModeTest { + @Test + public void getAvailableHostWithoutConnectionNumber() { + getAvailableHostWithoutConnectionNumber(HaMode.REPLICATION); + getAvailableHostWithoutConnectionNumber(HaMode.LOADBALANCE); + } + + private void getAvailableHostWithoutConnectionNumber(HaMode haMode) { + List hostAddresses = new ArrayList<>(); + hostAddresses.add(HostAddress.from("prim1", 3306, true)); + hostAddresses.add(HostAddress.from("prim2", 3306, true)); + hostAddresses.add(HostAddress.from("prim3", 3306, true)); + hostAddresses.add(HostAddress.from("slave1", 3306, false)); + hostAddresses.add(HostAddress.from("slave2", 3306, false)); + hostAddresses.add(HostAddress.from("slave3", 3306, false)); + + haMode.resetLast(); + ConcurrentMap denyList = new ConcurrentHashMap<>(); + HostCounter hostCounter = new HostCounter(); + for (int i = 0; i < 100; i++) { + hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, true).get(), false); + } + assertEquals("prim1:34,prim2:33,prim3:33", hostCounter.results()); + + haMode.resetLast(); + hostCounter = new HostCounter(); + for (int i = 0; i < 100; i++) { + hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, false).get(), false); + } + assertEquals("slave1:34,slave2:33,slave3:33", hostCounter.results()); + + haMode.resetLast(); + denyList.put(hostAddresses.get(0), System.currentTimeMillis() - 100); + denyList.put(hostAddresses.get(1), System.currentTimeMillis() + 1000); + + hostCounter = new HostCounter(); + for (int i = 0; i < 100; i++) { + hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, true).get(), false); + } + assertEquals("prim1:50,prim3:50", hostCounter.results()); + + haMode.resetLast(); + denyList.clear(); + denyList.put(hostAddresses.get(3), System.currentTimeMillis() - 100); + denyList.put(hostAddresses.get(4), System.currentTimeMillis() + 1000); + hostCounter = new HostCounter(); + for (int i = 0; i < 100; i++) { + hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, false).get(), false); + } + assertEquals("slave1:50,slave3:50", hostCounter.results()); + } + + @Test + public void getAvailableHostWithConnectionNumber() { + getAvailableHostWithConnectionNumber(HaMode.LOADBALANCE); + getAvailableHostWithConnectionNumber(HaMode.REPLICATION); + } + + private void getAvailableHostWithConnectionNumber(HaMode haMode) { + List hostAddresses = new ArrayList<>(); + + HostAddress host1 = HostAddress.from("prim1", 3306, true); + HostAddress host2 = HostAddress.from("prim2", 3306, true); + HostAddress host3 = HostAddress.from("prim3", 3306, true); + host1.setThreadsConnected(200); + host2.setThreadsConnected(150); + host3.setThreadsConnected(100); + hostAddresses.add(host1); + hostAddresses.add(host2); + hostAddresses.add(host3); + HostAddress slave1 = HostAddress.from("slave1", 3306, false); + HostAddress slave2 = HostAddress.from("slave2", 3306, false); + HostAddress slave3 = HostAddress.from("slave3", 3306, false); + slave1.setThreadsConnected(200); + slave2.setThreadsConnected(150); + slave3.setThreadsConnected(100); + hostAddresses.add(slave1); + hostAddresses.add(slave2); + hostAddresses.add(slave3); + + ConcurrentMap denyList = new ConcurrentHashMap<>(); + HostCounter hostCounter = new HostCounter(); + for (int i = 0; i < 100; i++) { + hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, true).get(), true); + } + assertEquals("prim2:25,prim3:75", hostCounter.results()); + + host1.forceThreadsConnected(200, System.currentTimeMillis() - 50000); + host2.setThreadsConnected(150); + host3.setThreadsConnected(100); + hostCounter = new HostCounter(); + for (int i = 0; i < 100; i++) { + hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, true).get(), true); + } + assertEquals("prim1:34,prim2:33,prim3:33", hostCounter.results()); + + slave1.setThreadsConnected(200); + slave2.setThreadsConnected(150); + slave3.setThreadsConnected(100); + hostCounter = new HostCounter(); + for (int i = 0; i < 100; i++) { + hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, false).get(), true); + } + assertEquals("slave2:25,slave3:75", hostCounter.results()); + + denyList.put(hostAddresses.get(0), System.currentTimeMillis() - 100); + denyList.put(hostAddresses.get(1), System.currentTimeMillis() + 1000); + host1.setThreadsConnected(150); + host2.setThreadsConnected(150); + host3.setThreadsConnected(100); + hostCounter = new HostCounter(); + for (int i = 0; i < 100; i++) { + hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, true).get(), true); + } + assertEquals("prim1:25,prim3:75", hostCounter.results()); + + denyList.clear(); + denyList.put(hostAddresses.get(3), System.currentTimeMillis() - 100); + denyList.put(hostAddresses.get(4), System.currentTimeMillis() + 1000); + slave1.setThreadsConnected(150); + slave2.setThreadsConnected(150); + slave3.setThreadsConnected(100); + hostCounter = new HostCounter(); + for (int i = 0; i < 100; i++) { + hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, false).get(), true); + } + assertEquals("slave1:25,slave3:75", hostCounter.results()); + } + + private class HostCounter { + Map hosts = new HashMap<>(); + + public void add(HostAddress hostAddress, boolean increment) { + Integer counter = hosts.get(hostAddress); + if (counter == null) { + hosts.put(hostAddress, 1); + } else { + hosts.replace(hostAddress, counter + 1); + } + if (increment) { + if (hostAddress.getThreadsConnected() != null) { + hostAddress.forceThreadsConnected( + hostAddress.getThreadsConnected() + 1, hostAddress.getThreadConnectedTimeout()); + } else { + hostAddress.forceThreadsConnected(1, System.currentTimeMillis() + 1000); + } + } + } + + public String results() { + List res = new ArrayList<>(); + for (Map.Entry hostEntry : hosts.entrySet()) { + res.add(hostEntry.getKey().host + ':' + hostEntry.getValue()); + } + Collections.sort(res); + return String.join(",", res); + } + } +} diff --git a/src/test/java/org/mariadb/jdbc/unit/plugin/AuthenticationPluginLoaderTest.java b/src/test/java/org/mariadb/jdbc/unit/plugin/AuthenticationPluginLoaderTest.java index 9e58c8494..460313365 100644 --- a/src/test/java/org/mariadb/jdbc/unit/plugin/AuthenticationPluginLoaderTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/plugin/AuthenticationPluginLoaderTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.plugin; diff --git a/src/test/java/org/mariadb/jdbc/unit/plugin/TlsSocketPluginLoaderTest.java b/src/test/java/org/mariadb/jdbc/unit/plugin/TlsSocketPluginLoaderTest.java index 1b416eeab..b02b9273c 100644 --- a/src/test/java/org/mariadb/jdbc/unit/plugin/TlsSocketPluginLoaderTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/plugin/TlsSocketPluginLoaderTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.plugin; diff --git a/src/test/java/org/mariadb/jdbc/unit/type/GeometryTest.java b/src/test/java/org/mariadb/jdbc/unit/type/GeometryTest.java index fb4b88056..1a7ff792e 100644 --- a/src/test/java/org/mariadb/jdbc/unit/type/GeometryTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/type/GeometryTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.type; diff --git a/src/test/java/org/mariadb/jdbc/unit/util/ClientParserTest.java b/src/test/java/org/mariadb/jdbc/unit/util/ClientParserTest.java index 824f0d259..aa2efc3a3 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/ClientParserTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/ClientParserTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util; diff --git a/src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java b/src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java index 864cfae95..7d30b7fb1 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util; @@ -15,6 +15,7 @@ import org.mariadb.jdbc.export.HaMode; import org.mariadb.jdbc.export.SslMode; import org.mariadb.jdbc.integration.Common; +import org.mariadb.jdbc.util.constants.CatalogTerm; @SuppressWarnings("ConstantConditions") public class ConfigurationTest { @@ -828,6 +829,7 @@ public void builder() throws SQLException { .keyStore("/tmp") .keyStorePassword("MyPWD") .keyStoreType("JKS") + .trustStoreType("JKS") .geometryDefaultType("default") .registerJmxPool(false) .tcpKeepCount(50) @@ -838,18 +840,34 @@ public void builder() throws SQLException { .useReadAheadInput(true) .cachePrepStmts(false) .serverSslCert("mycertPath") + .useLocalSessionState(true) .serverRsaPublicKeyFile("RSAPath") .allowPublicKeyRetrieval(true) .createDatabaseIfNotExist(true) .disablePipeline(true) .maxAllowedPacket(8000) .initSql("SET @@a='10'") + .useCatalogTerm("schema") .build(); assertEquals( - "jdbc:mariadb://host1:3305,address=(host=host2)(port=3307)(type=replica)/db?user=me&password=***&timezone=UTC&autocommit=false&createDatabaseIfNotExist=true&transactionIsolation=REPEATABLE_READ&defaultFetchSize=10&maxQuerySizeToLog=100&maxAllowedPacket=8000&geometryDefaultType=default&restrictedAuth=mysql_native_password,client_ed25519&initSql=SET @@a='10'&socketFactory=someSocketFactory&connectTimeout=22&pipe=pipeName&localSocket=localSocket&uuidAsString=true&tcpKeepAlive=false&tcpKeepIdle=10&tcpKeepCount=50&tcpKeepInterval=50&tcpAbortiveClose=true&localSocketAddress=localSocketAddress&socketTimeout=1000&useReadAheadInput=true&tlsSocketType=TLStype&sslMode=TRUST&serverSslCert=mycertPath&keyStore=/tmp&keyStorePassword=MyPWD&keyStoreType=JKS&enabledSslCipherSuites=myCipher,cipher2&enabledSslProtocolSuites=TLSv1.2&allowMultiQueries=true&allowLocalInfile=false&useCompression=true&useAffectedRows=true&useBulkStmts=false&disablePipeline=true&cachePrepStmts=false&prepStmtCacheSize=2&useServerPrepStmts=true&credentialType=ENV&sessionVariables=blabla&connectionAttributes=bla=bla&servicePrincipalName=SPN&blankTableNameMeta=true&tinyInt1isBit=false&yearIsDateType=false&dumpQueriesOnException=true&includeInnodbStatusInDeadlockExceptions=true&includeThreadDumpInDeadlockExceptions=true&retriesAllDown=10&galeraAllowedState=A,B&transactionReplay=true&pool=true&poolName=myPool&maxPoolSize=16&minPoolSize=12&maxIdleTime=25000®isterJmxPool=false&poolValidMinDelay=260&useResetConnection=true&serverRsaPublicKeyFile=RSAPath&allowPublicKeyRetrieval=true", + "jdbc:mariadb://host1:3305,address=(host=host2)(port=3307)(type=replica)/db?user=me&password=***&timezone=UTC&autocommit=false&useCatalogTerm=UseSchema&createDatabaseIfNotExist=true&useLocalSessionState=true&transactionIsolation=REPEATABLE_READ&defaultFetchSize=10&maxQuerySizeToLog=100&maxAllowedPacket=8000&geometryDefaultType=default&restrictedAuth=mysql_native_password,client_ed25519&initSql=SET @@a='10'&socketFactory=someSocketFactory&connectTimeout=22&pipe=pipeName&localSocket=localSocket&uuidAsString=true&tcpKeepAlive=false&tcpKeepIdle=10&tcpKeepCount=50&tcpKeepInterval=50&tcpAbortiveClose=true&localSocketAddress=localSocketAddress&socketTimeout=1000&useReadAheadInput=true&tlsSocketType=TLStype&sslMode=TRUST&serverSslCert=mycertPath&keyStore=/tmp&keyStorePassword=MyPWD&keyStoreType=JKS&trustStoreType=JKS&enabledSslCipherSuites=myCipher,cipher2&enabledSslProtocolSuites=TLSv1.2&allowMultiQueries=true&allowLocalInfile=false&useCompression=true&useAffectedRows=true&disablePipeline=true&cachePrepStmts=false&prepStmtCacheSize=2&useServerPrepStmts=true&credentialType=ENV&sessionVariables=blabla&connectionAttributes=bla=bla&servicePrincipalName=SPN&blankTableNameMeta=true&tinyInt1isBit=false&yearIsDateType=false&dumpQueriesOnException=true&includeInnodbStatusInDeadlockExceptions=true&includeThreadDumpInDeadlockExceptions=true&retriesAllDown=10&galeraAllowedState=A,B&transactionReplay=true&pool=true&poolName=myPool&maxPoolSize=16&minPoolSize=12&maxIdleTime=25000®isterJmxPool=false&poolValidMinDelay=260&useResetConnection=true&serverRsaPublicKeyFile=RSAPath&allowPublicKeyRetrieval=true", conf.toString()); } + @Test + public void useCatalogTerm() throws SQLException { + Configuration conf = + Configuration.parse("jdbc:mariadb://localhost/test?useCatalogTerm=Catalog"); + assertEquals(conf.useCatalogTerm(), CatalogTerm.UseCatalog); + + conf = Configuration.parse("jdbc:mariadb://localhost/test?useCatalogTerm=Schema"); + assertEquals(conf.useCatalogTerm(), CatalogTerm.UseSchema); + + assertThrows( + SQLException.class, + () -> Configuration.parse("jdbc:mariadb://localhost/test?useCatalogTerm=Wrong")); + } + @Test public void equal() throws SQLException { Configuration conf = Configuration.parse("jdbc:mariadb://localhost/test"); @@ -883,4 +901,64 @@ public void useMysqlMetadata() throws SQLException { .build() .useMysqlMetadata()); } + + @Test + public void toConf() throws SQLException { + assertTrue( + Configuration.toConf("jdbc:mariadb://localhost/test") + .startsWith( + "Configuration:\n" + + " * resulting Url : jdbc:mariadb://localhost/test\n" + + "Unknown options : None\n" + + "\n" + + "Non default options : \n" + + " * database : test\n" + + "\n" + + "default options :")); + assertTrue( + Configuration.toConf( + "jdbc:mariadb:loadbalance://host1:3305,address=(host=host2)(port=3307)(type=replica)/db?nonExisting&nonExistingWithValue=tt&user=me&password=***&timezone=UTC&autocommit=false&createDatabaseIfNotExist=true&") + .startsWith( + "Configuration:\n" + + " * resulting Url : jdbc:mariadb:loadbalance://address=(host=host1)(port=3305)(type=primary),address=(host=host2)(port=3307)(type=replica)/db?user=me&password=***&nonExisting=&nonExistingWithValue=tt&timezone=UTC&autocommit=false&createDatabaseIfNotExist=true\n" + + "Unknown options : \n" + + " * nonExisting : \n" + + " * nonExistingWithValue : tt\n" + + "\n" + + "Non default options : \n" + + " * addresses : [address=(host=host1)(port=3305)(type=primary), address=(host=host2)(port=3307)(type=replica)]\n" + + " * autocommit : false\n" + + " * createDatabaseIfNotExist : true\n" + + " * database : db\n" + + " * haMode : LOADBALANCE\n" + + " * password : ***\n" + + " * timezone : UTC\n" + + " * user : me\n" + + "\n" + + "default options :\n" + + " * allowLocalInfile : true\n" + + " * allowMultiQueries : false\n" + + " * allowPublicKeyRetrieval : false")); + + assertTrue( + Configuration.toConf( + "jdbc:mariadb://localhost/test?user=root&sslMode=verify-ca&serverSslCert=/tmp/t.pem&trustStoreType=JKS&keyStore=/tmp/keystore&keyStorePassword=kspass") + .startsWith( + "Configuration:\n" + + " * resulting Url : jdbc:mariadb://localhost/test?user=root&sslMode=VERIFY_CA&serverSslCert=/tmp/t.pem&keyStore=/tmp/keystore&keyStorePassword=kspass&trustStoreType=JKS\n" + + "Unknown options : None\n" + + "\n" + + "Non default options : \n" + + " * database : test\n" + + " * keyStore : /tmp/keystore\n" + + " * keyStorePassword : kspass\n" + + " * serverSslCert : /tmp/t.pem\n" + + " * sslMode : VERIFY_CA\n" + + " * trustStoreType : JKS\n" + + " * user : root\n" + + "\n" + + "default options :\n" + + " * addresses : [address=(host=localhost)(port=3306)(type=primary)]\n" + + " * allowLocalInfile : true")); + } } diff --git a/src/test/java/org/mariadb/jdbc/unit/util/ParameterListTest.java b/src/test/java/org/mariadb/jdbc/unit/util/ParameterListTest.java index a2aa2f966..12f2ea6f9 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/ParameterListTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/ParameterListTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util; diff --git a/src/test/java/org/mariadb/jdbc/unit/util/SecurityTest.java b/src/test/java/org/mariadb/jdbc/unit/util/SecurityTest.java index 049583409..d89c27407 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/SecurityTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/SecurityTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util; diff --git a/src/test/java/org/mariadb/jdbc/unit/util/VersionTest.java b/src/test/java/org/mariadb/jdbc/unit/util/VersionTest.java index 8ff38169d..7f6b5802f 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/VersionTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/VersionTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util; diff --git a/src/test/java/org/mariadb/jdbc/unit/util/constant/HaModeTest.java b/src/test/java/org/mariadb/jdbc/unit/util/constant/HaModeTest.java index d72c79cb2..c451ac1ad 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/constant/HaModeTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/constant/HaModeTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util.constant; diff --git a/src/test/java/org/mariadb/jdbc/unit/util/log/ConsoleLoggerTest.java b/src/test/java/org/mariadb/jdbc/unit/util/log/ConsoleLoggerTest.java index a2e287010..ce4ac25a7 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/log/ConsoleLoggerTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/log/ConsoleLoggerTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util.log; diff --git a/src/test/java/org/mariadb/jdbc/unit/util/log/JdkLoggerTest.java b/src/test/java/org/mariadb/jdbc/unit/util/log/JdkLoggerTest.java index 9bbaa4b3e..83277820a 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/log/JdkLoggerTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/log/JdkLoggerTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util.log; diff --git a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerFactoryTest.java b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerFactoryTest.java index d359fbf0b..b7f27bb31 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerFactoryTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerFactoryTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util.log; diff --git a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerHelperTest.java b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerHelperTest.java index af94bfab5..119bafdd4 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerHelperTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerHelperTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util.log; diff --git a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggersTest.java b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggersTest.java index 42cb7b575..e26b17ed8 100644 --- a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggersTest.java +++ b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggersTest.java @@ -1,6 +1,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (c) 2012-2014 Monty Program Ab -// Copyright (c) 2015-2021 MariaDB Corporation Ab +// Copyright (c) 2015-2023 MariaDB Corporation Ab package org.mariadb.jdbc.unit.util.log;