Skip to content
Commits on Source (6)
......@@ -22,10 +22,9 @@ Tracker link <a href="https://jira.mariadb.org/projects/CONJ/issues/">https://ji
| Java version | current version |
|:------------:|:-------------------------:|
| 6 | 1.7.2 |
| 7 | 1.7.2 |
| 8 | 2.2.4 |
| 9 | 2.2.4 |
| 6 | 1.7.4 |
| 7 | 1.7.4 |
| 8+ | 2.3.0 |
The driver (jar) can be downloaded from [mariadb connector download](https://mariadb.com/products/connectors-plugins)
or maven :
......@@ -33,7 +32,7 @@ or maven :
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.2.4</version>
<version>2.3.0</version>
</dependency>
```
......@@ -51,7 +50,7 @@ Development snapshot are available on sonatype nexus repository
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</dependency>
</dependencies>
```
......
version: '{build}'
environment:
matrix:
- DB: '10.2.14'
- DB: '10.2.16'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
JAVA_HOME: C:\Program Files\Java\jdk1.8.0
- DB: '10.3.6'
- DB: '10.3.8'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
JAVA_HOME: C:\Program Files\Java\jdk1.8.0
- DB: '10.1.32'
- DB: '10.1.34'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
JAVA_HOME: C:\Program Files\Java\jdk1.8.0
......@@ -31,7 +31,7 @@ install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\maven" )) {
(new-object System.Net.WebClient).DownloadFile('http://www.us.apache.org/dist/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.zip', 'C:\maven-bin.zip')
(new-object System.Net.WebClient).DownloadFile('http://www.us.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.zip', 'C:\maven-bin.zip')
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
# Prepend Java entry, remove Ruby entry (C:\Ruby193\bin;) from PATH
......@@ -39,10 +39,10 @@ install:
- ps: Start-FileDownload $Env:FILE -FileName server.msi -Timeout 900000
- cmd: msiexec /i server.msi INSTALLDIR=c:\projects\server SERVICENAME=mariadb ALLOWREMOTEROOTACCESS=true /qn
- cmd: "\"c:\\projects\\server\\bin\\mysql.exe\" -e \"create database testj\" --user=root"
- cmd: SET PATH=C:\maven\apache-maven-3.5.3\bin;%JAVA_HOME%\bin;%PATH:C:\Ruby193\bin;=%;
- cmd: SET PATH=C:\maven\apache-maven-3.5.4\bin;%JAVA_HOME%\bin;%PATH:C:\Ruby193\bin;=%;
- cmd: SET MAVEN_OPTS=-Xms512m -Xms768m
- cmd: SET JAVA_OPTS=-Xms512m -Xmx768m
- cmd: SET M2_HOME=C:\maven\apache-maven-3.5.3
- cmd: SET M2_HOME=C:\maven\apache-maven-3.5.4
- cmd: SET M
- cmd: cd c:\projects\mariadb-connector-j
- cmd: mvn --version
......
mariadb-connector-java (2.3.0-1) unstable; urgency=medium
* New upstream release
- Refreshed the patch
* Standards-Version updated to 4.2.1
-- Emmanuel Bourg <ebourg@apache.org> Thu, 20 Sep 2018 16:39:34 +0200
mariadb-connector-java (2.2.5-1) unstable; urgency=medium
* Initial release (Closes: #901576)
......
......@@ -10,7 +10,7 @@ Build-Depends:
libjna-platform-java,
libreplacer-java,
maven-debian-helper (>= 2.1)
Standards-Version: 4.1.4
Standards-Version: 4.2.1
Vcs-Git: https://salsa.debian.org/java-team/mariadb-connector-java.git
Vcs-Browser: https://salsa.debian.org/java-team/mariadb-connector-java
Homepage: https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/
......
......@@ -13,21 +13,25 @@ Forwarded: not-needed
</configuration>
</plugin>
--- a/src/main/java/org/mariadb/jdbc/internal/com/send/SendGssApiAuthPacket.java
+++ b/src/main/java/org/mariadb/jdbc/internal/com/send/SendGssApiAuthPacket.java
@@ -57,7 +57,6 @@
import org.mariadb.jdbc.internal.com.read.ErrorPacket;
import org.mariadb.jdbc.internal.com.send.gssapi.GssapiAuth;
import org.mariadb.jdbc.internal.com.send.gssapi.StandardGssapiAuthentication;
-import org.mariadb.jdbc.internal.com.send.gssapi.WindowsNativeSspiAuthentication;
import org.mariadb.jdbc.internal.io.input.PacketInputStream;
import org.mariadb.jdbc.internal.io.output.PacketOutputStream;
@@ -119,7 +118,6 @@
if (Platform.isWindows()) {
try {
Class.forName("waffle.windows.auth.impl.WindowsAuthProviderImpl");
- return new WindowsNativeSspiAuthentication(reader, packSeq);
} catch (ClassNotFoundException cle) {
//waffle not in the classpath
--- a/src/main/java/org/mariadb/jdbc/internal/com/send/gssapi/GssUtility.java
+++ b/src/main/java/org/mariadb/jdbc/internal/com/send/gssapi/GssUtility.java
@@ -13,19 +13,6 @@
* @return authentication method
*/
public static BiFunction<PacketInputStream, Integer, GssapiAuth> getAuthenticationMethod() {
- try {
- //Waffle-jna has jna as dependency, so if not available on classpath, just use standard authentication
- if (Platform.isWindows()) {
- try {
- Class.forName("waffle.windows.auth.impl.WindowsAuthProviderImpl");
- return (reader, packSeq) -> new WindowsNativeSspiAuthentication(reader, packSeq);
- } catch (ClassNotFoundException cle) {
- //waffle not in the classpath
- }
- }
- } catch (Throwable cle) {
- //jna jar's are not in classpath
- }
return (reader, packSeq) -> new StandardGssapiAuthentication(reader, packSeq);
}
= Changelog
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#224|2.2.5]] Released on 29 may 2018
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#230|2.3.0]] Released on 06 Sep. 2018
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#226|2.2.6]] Released on 19 Jul 2018
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#225|2.2.5]] Released on 29 may 2018
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#224|2.2.4]] Released on 04 may 2018
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#223|2.2.3]] Released on 09 mar. 2018
* [[https://github.com/MariaDB/mariadb-connector-j/documentation/changelog.creole#222|2.2.2]] Released on 20 feb. 2018
......@@ -34,59 +36,109 @@
---
== 2.3.0
==== [CONJ-398] Improve deadlock debugging capabilities
MariaDB has now 2 new options to permit identifying deadlock :
New options
|=includeInnodbStatusInDeadlockExceptions|add "SHOW ENGINE INNODB STATUS" result to exception trace when having a deadlock exception.\\//Default: false//
|=includeThreadDumpInDeadlockExceptions|add thread dump to exception trace when having a deadlock exception.\\//Default: false//
==== [CONJ-639] the option "enabledSslProtocolSuites" now include TLSv1.2 by default
previous default value was "TLSv1, TLSv1.1", disabling TLSv1.2 by default, due to a corrected issue (MDEV-12190) with servers using YaSSL - not openSSL. Server error was .
Now, the default value is "TLSv1, TLSv1.1, TLSv1.2". So TLSv1.2 can be use directly.
Connecting MySQL community server use YaSSL without correction, and connection might result in SSLException: "Unsupported record version Unknown-0.0".
==== [CONJ-642] disable the option "useBulkStmts" by default
Using useBulkStmts permit faster batch, but cause one major issue : Batch return -1 = SUCCESS_NO_INFO
Different option use this information for optimistic update, and cannot confirm if update succeed or not.
This option still makes sense, since for big batch is way more faster, but will not be activated by default.
=== Minor change:
* [CONJ-628] optimization to read metadata faster
* [CONJ-637] java.sql.Driver class implement DriverPropertyInfo[] getPropertyInfo, permitting listing options on querying tools
* [CONJ-639] enabledSslProtocolSuites does not include TLSv1.2 by default
* [CONJ-641] update maven test dependencies for java 10 compatibility
* [CONJ-643] PreparedStatement::getParameterMetaData always returns VARSTRING as type resulting in downstream libraries interpreting values wrongly
=== Bug correction:
* [CONJ-616] correction on possible NPE on getConnection when using failover configuration and master is down, not throwing a proper exception
* [CONJ-636] Error in batch might throw a NPE and not the proper Exception
== 2.2.6
minor change:
* [CONJ-623] Increase connection logging when Primary node connection fails
* [CONJ-384] Permit knowing affected rows number, not only real changed rows
New options
|=useAffectedRows|default correspond to the JDBC standard, reporting real affected rows. if enable, will report "affected" rows. example : if enable, an update command that doesn't change a row value will still be "affected", then report.\\//Default: false. Since 2.2.6//
Bug correction:
* [CONJ-624] MariaDbPoolDataSource possible NPE on configuration getter
* [CONJ-623] Increase connection logging when Primary node connection fails
* [CONJ-622] The option "connectTimeout" must take in account DriverManager.getLoginTimeout() when set
* [CONJ-621] wrong escaping when having curly bracket in table/field name
* [CONJ-618] Client preparestatement parsing error on escaped ' / " in query
== 2.2.5
minor change:
[CONJ-602] Add server hostname to connection packet for proxy
[CONJ-604] handle support for mysql 8.0 tx_isolation replacement by transaction_isolation
* [CONJ-602] Add server hostname to connection packet for proxy
* [CONJ-604] handle support for mysql 8.0 tx_isolation replacement by transaction_isolation
Bug correction:
[CONJ-613] Connection using "replication" Parameters fail when no slave is available
[CONJ-595] Create option to configure DONOR/DESYNCED Galera nodes to be unavailable for load-balancing
[CONJ-605] Newlines where breaking calling stored procedures
[CONJ-609] Using getDate with function DATE_ADD() with parameter using string format where return wrong result using binary protocol
[CONJ-610] Option "allowMasterDownConnection" improvement on connection validation and Exceptions on master down
* [CONJ-613] Connection using "replication" Parameters fail when no slave is available
* [CONJ-595] Create option to configure DONOR/DESYNCED Galera nodes to be unavailable for load-balancing
* [CONJ-605] Newlines where breaking calling stored procedures
* [CONJ-609] Using getDate with function DATE_ADD() with parameter using string format where return wrong result using binary protocol
* [CONJ-610] Option "allowMasterDownConnection" improvement on connection validation and Exceptions on master down
== 2.2.4
Minor changes:
[CONJ-580] Some options are missing in documentation like default 'autocommit' value
[CONJ-597] Internal exchanges send utf8mb4 with server even if default server collation is not utf8/utf8mb4
[CONJ-600] Upgrading non mandatory Waffle dependency to 1.9.0 (windows GSSAPI authentication)
[CONJ-575] test addition to ensure YaSSL downgrade TLSv1.2 protocol to TLSv1.1
* [CONJ-580] Some options are missing in documentation like default 'autocommit' value
* [CONJ-597] Internal exchanges send utf8mb4 with server even if default server collation is not utf8/utf8mb4
* [CONJ-600] Upgrading non mandatory Waffle dependency to 1.9.0 (windows GSSAPI authentication)
* [CONJ-575] test addition to ensure YaSSL downgrade TLSv1.2 protocol to TLSv1.1
== 2.2.3
Bug correction:
[CONJ-583] possible hang indefinitely using master/slave configuration and failover occur
[CONJ-586] erroneous transaction state when first command result as error
[CONJ-587] using allowMasterDownConnection option can lead to NPE when using setReadOnly()
[CONJ-588] using option 'allowMasterDownConnection' won't permit to connect if master is down
[CONJ-534] Connection.isValid() must be routed to Master and Slave connections to avoid any server timeout
* [CONJ-583] possible hang indefinitely using master/slave configuration and failover occur
* [CONJ-586] erroneous transaction state when first command result as error
* [CONJ-587] using allowMasterDownConnection option can lead to NPE when using setReadOnly()
* [CONJ-588] using option 'allowMasterDownConnection' won't permit to connect if master is down
* [CONJ-534] Connection.isValid() must be routed to Master and Slave connections to avoid any server timeout
== 2.2.2
Bug correction:
[CONJ-564] Never ever throw an instance of java.lang.Error
[CONJ-579] Keywords missing from DatabaseMetaData.getSQLKeywords()
[CONJ-567] UrlParser.initialUrl gets overwritten
[CONJ-571] Permit java 9 serialization filtering
[CONJ-574] forcing using toLowerCase/toUpperCase with Locale.ROOT
[CONJ-560] Automatic module name for java 9
[CONJ-578] windows testing using all mariadb server
[CONJ-570] Add tests for 10.3.3 INVISIBLE column
* [CONJ-564] Never ever throw an instance of java.lang.Error
* [CONJ-579] Keywords missing from DatabaseMetaData.getSQLKeywords()
* [CONJ-567] UrlParser.initialUrl gets overwritten
* [CONJ-571] Permit java 9 serialization filtering
* [CONJ-574] forcing using toLowerCase/toUpperCase with Locale.ROOT
* [CONJ-560] Automatic module name for java 9
* [CONJ-578] windows testing using all mariadb server
* [CONJ-570] Add tests for 10.3.3 INVISIBLE column
== 2.2.1
[CONJ-501] provide support for authentication plugin ed25519
* [CONJ-501] provide support for authentication plugin ed25519
Bug correction:
[CONJ-529] failover : the driver will pause for 250ms if no servers are available before attempting to reconnect another time
[CONJ-548] don't use COM_STMT_BULK_EXECUTE for INSERT ... SELECT statements
[CONJ-549] correction on connection reset when using MariaDbPoolDataSource with options useServerPrepStmts and useResetConnection enabled
[CONJ-555] failover caused by client timeout must not reuse connection
[CONJ-558] removing extra ".0" to resultset.getString() value for FLOAT/DOUBLE fields
[CONJ-550] fetching state correction when reusing statement without having read all results
[CONJ-553] RejectedExecutionException was thrown when having large amount of concurrent batches
* [CONJ-529] failover : the driver will pause for 250ms if no servers are available before attempting to reconnect another time
* [CONJ-548] don't use COM_STMT_BULK_EXECUTE for INSERT ... SELECT statements
* [CONJ-549] correction on connection reset when using MariaDbPoolDataSource with options useServerPrepStmts and useResetConnection enabled
* [CONJ-555] failover caused by client timeout must not reuse connection
* [CONJ-558] removing extra ".0" to resultset.getString() value for FLOAT/DOUBLE fields
* [CONJ-550] fetching state correction when reusing statement without having read all results
* [CONJ-553] RejectedExecutionException was thrown when having large amount of concurrent batches
......
......@@ -106,7 +106,7 @@ The following options are currently supported.
|=user|Database user name. \\//since 1.0.0//|
|=password|Password of database user.\\//since 1.0.0//|
|=rewriteBatchedStatements| For insert queries, rewrite batchedStatement to execute in a single executeQuery.\\example:\\{{{insert into ab (i) values (?)}}} with first batch values = 1, second = 2 will be rewritten\\{{{insert into ab (i) values (1), (2)}}}. \\\\If query cannot be rewriten in "multi-values", rewrite will use multi-queries : {{{INSERT INTO TABLE(col1) VALUES (?) ON DUPLICATE KEY UPDATE col2=?}}} with values [1,2] and [2,3]" will be rewritten\\{{{INSERT INTO TABLE(col1) VALUES (1) ON DUPLICATE KEY UPDATE col2=2;INSERT INTO TABLE(col1) VALUES (3) ON DUPLICATE KEY UPDATE col2=4}}}\\\\when active, the useServerPrepStmts option is set to false\\//Default: false. Since 1.1.8//|
|=connectTimeout| The connect timeout value, in milliseconds, or zero for no timeout.\\//Default: 0. Since 1.1.8//|
|=connectTimeout| The connect timeout value, in milliseconds.\\//Default: DriverManager.getLoginTimeout() value if set or 30s. Since 1.1.8//|
|=useServerPrepStmts|Queries are prepared on the server side before executing, permitting faster execution next time. \\if rewriteBatchedStatements is set to true, this option will be set to false.\\//Default: true. Since 1.3.0//|
|=useBatchMultiSend|*Not compatible with aurora* Driver will can send queries by batch. \\If disable, queries are send one by one, waiting for result before sending next one. \\If enable, queries will be send by batch corresponding to option useBatchMultiSendNumber value (default 100) or according to server variable @@max_allowed_packet if packet size cannot permit to send as many queries. Results will be read afterwhile, avoiding a lot of network latency when client and server aren't on same host. \\\\ There is 2 differents use case : JDBC executeBatch() and when option useServerPrepStmts is enable and MariaDB server >= 10.2.1, PREPARE commands will be delayed, to send PREPARE + EXECUTE in the same packet. This option if mainly effective when client is distant from server. [[./use-batch-multi-send-description.creole|more information]]\\//Default: true (false if using aurora failover). Since 1.5.0//|
\\
......@@ -137,7 +137,7 @@ See [[use-mariadb-connector-j-driver.creole#using-pooling|using pooling]] for mo
|=keyPassword|Password for the private key in client certificate keyStore. (only needed if private key password differ from keyStore password).\\//Since 1.5.3//|
|=trustStore|File path of the trustStore file (similar to java System property "javax.net.ssl.trustStore"). (legacy alias trustCertificateKeyStoreUrl)\\Use the specified file for trusted root certificates.\\When set, overrides serverSslCert.\\//Since 1.3.4//|
|=trustStorePassword|Password for the trusted root certificate file (similar to java System property "javax.net.ssl.trustStorePassword").\\(legacy alias trustCertificateKeyStorePassword).\\//Since 1.3.4//|
|=enabledSslProtocolSuites|Force TLS/SSL protocol to a specific set of TLS versions (comma separated list). \\Example : "TLSv1, TLSv1.1, TLSv1.2"\\//Default: TLSv1, TLSv1.1. Since 1.5.0//|
|=enabledSslProtocolSuites|Force TLS/SSL protocol to a specific set of TLS versions (comma separated list). \\Example : "TLSv1, TLSv1.1, TLSv1.2"\\//Default: TLSv1, TLSv1.1" before 2.3.0, "TLSv1, TLSv1.1, TLSv1.2" since v2.3.0". Since 1.5.0//|
|=enabledSslCipherSuites|Force TLS/SSL cipher (comma separated list).\\ Example : "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384"\\//Default: use JRE ciphers. Since 1.5.0//|
\\
......@@ -183,6 +183,10 @@ See [[use-mariadb-connector-j-driver.creole#using-pooling|using pooling]] for mo
|=continueBatchOnError| When executing batch queries, must batch continue on error and throw exception when ended, or stop immediately \\//Default: true. Since 1.4.0//
|=disableSslHostnameVerification| When using ssl, driver check hostname against the server's identity as presented in the server's Certificate (checking alternative names or certificate CN) to prevent man-in-the-middle attack. This option permit to deactivate this validation.\\//Default: false. Since 2.1.0//
|=autocommit|Set default autocommit value.\\//Default: true. Since 2.2.0//
|=galeraAllowedState|Usually, Connection.isValid just send an empty packet to server, and server send a small response to ensure connectivity. When this option is set, connector will ensure Galera server state "wsrep_local_state" correspond to allowed values (separated by comma). example "4,5", recommended is "4". see [galera state](http://galeracluster.com/documentation-webpages/nodestates.html#node-state-changes) to know more..\\//Default: empty. Since 2.2.5//
|=useAffectedRows|default correspond to the JDBC standard, reporting real affected rows. if enable, will report "affected" rows. example : if enable, an update command that doesn't change a row value will still be "affected", then report.\\//Default: false. Since 2.2.6//
|=includeInnodbStatusInDeadlockExceptions|add "SHOW ENGINE INNODB STATUS" result to exception trace when having a deadlock exception\\//Default: false. Since 2.3.0//
|=includeThreadDumpInDeadlockExceptions|add thread dump to exception trace when having a deadlock exception\\//Default: false. Since 2.3.0//
\\\\
== Failover/High availability URL parameters
......
......@@ -58,7 +58,7 @@
<artifactId>mariadb-java-client</artifactId>
<packaging>jar</packaging>
<name>mariadb-java-client</name>
<version>2.2.5</version>
<version>2.3.0</version>
<description>JDBC driver for MariaDB and MySQL</description>
<url>https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/</url>
......@@ -67,11 +67,11 @@
<jna.version>4.2.1</jna.version>
<version.template.file>src/main/resources/Version.java.template</version.template.file>
<version.file>src/main/java/org/mariadb/jdbc/internal/util/constant/Version.java</version.file>
<checkstyleVersion>6.11.2</checkstyleVersion>
<checkstyle.plugin.version>2.16</checkstyle.plugin.version>
<checkstyleVersion>8.12</checkstyleVersion>
<checkstyle.plugin.version>2.17</checkstyle.plugin.version>
<driver.version.major>2</driver.version.major>
<driver.version.minor>2</driver.version.minor>
<driver.version.patch>5</driver.version.patch>
<driver.version.minor>3</driver.version.minor>
<driver.version.patch>0</driver.version.patch>
<driver.version.qualifier></driver.version.qualifier>
</properties>
......
......@@ -60,8 +60,8 @@ import java.io.OutputStream;
*/
class BlobOutputStream extends OutputStream {
private int pos;
private final MariaDbBlob blob;
private int pos;
public BlobOutputStream(MariaDbBlob blob, int pos) {
this.blob = blob;
......
......@@ -53,24 +53,40 @@
package org.mariadb.jdbc;
import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.ParameterMetaData;
import java.sql.Ref;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLType;
import java.sql.SQLXML;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Calendar;
import java.util.Map;
import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
public abstract class CallableFunctionStatement extends MariaDbPreparedStatementClient implements
CallableStatement {
public abstract class CallableFunctionStatement extends MariaDbPreparedStatementClient implements CallableStatement {
protected CallableParameterMetaData parameterMetadata;
/**
* Information about parameters, merely from registerOutputParameter() and setXXX() calls.
*/
private CallParameter[] params;
protected CallableParameterMetaData parameterMetadata;
/**
* Constructor for getter/setter of callableStatement.
......@@ -80,7 +96,8 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
* @param resultSetType a result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
* @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code>
* or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @throws SQLException if clientPrepareStatement creation throw an exception
*/
......@@ -96,7 +113,8 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
* @return Cloned .
* @throws CloneNotSupportedException if any error occur.
*/
public CallableFunctionStatement clone(MariaDbConnection connection) throws CloneNotSupportedException {
public CallableFunctionStatement clone(MariaDbConnection connection)
throws CloneNotSupportedException {
CallableFunctionStatement clone = (CallableFunctionStatement) super.clone(connection);
clone.params = params;
clone.parameterMetadata = parameterMetadata;
......@@ -350,7 +368,8 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
@Override
public Object getObject(int parameterIndex) throws SQLException {
Class<?> classType = ColumnType.classFromJavaType(getParameter(parameterIndex).getOutputSqlType());
Class<?> classType = ColumnType
.classFromJavaType(getParameter(parameterIndex).getOutputSqlType());
if (classType != null) {
return getResult().getObject(indexToOutputIndex(parameterIndex), classType);
}
......@@ -501,44 +520,36 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
/**
* <p>Registers the designated output parameter.
* This version of
* the method <code>registerOutParameter</code>
* should be used for a user-defined or <code>REF</code> output parameter. Examples
* of user-defined types include: <code>STRUCT</code>, <code>DISTINCT</code>,
* This version of the method <code>registerOutParameter</code> should be used for a user-defined
* or <code>REF</code> output parameter. Examples of user-defined types include:
* <code>STRUCT</code>, <code>DISTINCT</code>,
* <code>JAVA_OBJECT</code>, and named array types.</p>
* <p>All OUT parameters must be registered
* before a stored procedure is executed.</p>
* <p> For a user-defined parameter, the fully-qualified SQL
* type name of the parameter should also be given, while a <code>REF</code>
* parameter requires that the fully-qualified type name of the
* referenced type be given. A JDBC driver that does not need the
* type code and type name information may ignore it. To be portable,
* however, applications should always provide these values for
* user-defined and <code>REF</code> parameters.</p>
* type name of the parameter should also be given, while a <code>REF</code> parameter requires
* that the fully-qualified type name of the referenced type be given. A JDBC driver that does
* not need the type code and type name information may ignore it. To be portable, however,
* applications should always provide these values for user-defined and <code>REF</code>
* parameters.</p>
* <p>Although it is intended for user-defined and <code>REF</code> parameters,
* this method may be used to register a parameter of any JDBC type.
* If the parameter does not have a user-defined or <code>REF</code> type, the
* this method may be used to register a parameter of any JDBC type. If the parameter does not
* have a user-defined or <code>REF</code> type, the
* <i>typeName</i> parameter is ignored.</p>
* <p><B>Note:</B> When reading the value of an out parameter, you
* must use the getter method whose Java type corresponds to the
* parameter's registered SQL type.</p>
* must use the getter method whose Java type corresponds to the parameter's registered SQL
* type.</p>
*
* @param parameterIndex the first parameter is 1, the second is 2,...
* @param sqlType a value from {@link Types}
* @param typeName the fully-qualified name of an SQL structured type
* @throws SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @throws SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @throws SQLException if the parameterIndex is not valid; if a database
* access error occurs or this method is called on a
* closed <code>CallableStatement</code>
* @see Types
*/
public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
public void registerOutParameter(int parameterIndex, int sqlType, String typeName)
throws SQLException {
CallParameter callParameter = getParameter(parameterIndex);
callParameter.setOutputSqlType(sqlType);
callParameter.setTypeName(typeName);
......@@ -556,27 +567,18 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
* <code>sqlType</code>. All OUT parameters must be registered
* before a stored procedure is executed.</p>
* <p>The JDBC type specified by <code>sqlType</code> for an OUT
* parameter determines the Java type that must be used
* in the <code>get</code> method to read the value of that parameter.</p>
* parameter determines the Java type that must be used in the <code>get</code> method to read the
* value of that parameter.</p>
* <p>This version of <code>registerOutParameter</code> should be
* used when the parameter is of JDBC type <code>NUMERIC</code>
* or <code>DECIMAL</code>.</p>
* used when the parameter is of JDBC type <code>NUMERIC</code> or <code>DECIMAL</code>.</p>
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param parameterIndex the first parameter is 1, the second is 2, and so on
* @param sqlType the SQL type code defined by <code>java.sql.Types</code>.
* @param scale the desired number of digits to the right of the
* decimal point. It must be greater than or equal to zero.
* @throws SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @throws SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @param scale the desired number of digits to the right of the decimal point. It must
* be greater than or equal to zero.
* @throws SQLException if the parameterIndex is not valid; if a database
* access error occurs or this method is called on a
* closed <code>CallableStatement</code>
* @see Types
*/
@Override
......@@ -593,13 +595,15 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
public void registerOutParameter(String parameterName, int sqlType, int scale)
throws SQLException {
registerOutParameter(nameToIndex(parameterName), sqlType, scale);
}
@Override
public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
public void registerOutParameter(String parameterName, int sqlType, String typeName)
throws SQLException {
registerOutParameter(nameToIndex(parameterName), sqlType, typeName);
}
......@@ -609,12 +613,14 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void registerOutParameter(int parameterIndex, SQLType sqlType, int scale) throws SQLException {
public void registerOutParameter(int parameterIndex, SQLType sqlType, int scale)
throws SQLException {
registerOutParameter(parameterIndex, sqlType.getVendorTypeNumber(), scale);
}
@Override
public void registerOutParameter(int parameterIndex, SQLType sqlType, String typeName) throws SQLException {
public void registerOutParameter(int parameterIndex, SQLType sqlType, String typeName)
throws SQLException {
registerOutParameter(parameterIndex, sqlType.getVendorTypeNumber(), typeName);
}
......@@ -624,12 +630,14 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void registerOutParameter(String parameterName, SQLType sqlType, int scale) throws SQLException {
public void registerOutParameter(String parameterName, SQLType sqlType, int scale)
throws SQLException {
registerOutParameter(parameterName, sqlType.getVendorTypeNumber(), scale);
}
@Override
public void registerOutParameter(String parameterName, SQLType sqlType, String typeName) throws SQLException {
public void registerOutParameter(String parameterName, SQLType sqlType, String typeName)
throws SQLException {
registerOutParameter(parameterName, sqlType.getVendorTypeNumber(), typeName);
}
......@@ -656,7 +664,8 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void setNCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
public void setNCharacterStream(String parameterName, Reader reader, long length)
throws SQLException {
setCharacterStream(nameToIndex(parameterName), reader, length);
}
......@@ -696,7 +705,8 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {
public void setBlob(String parameterName, InputStream inputStream, long length)
throws SQLException {
setBlob(nameToIndex(parameterName), inputStream, length);
}
......@@ -711,12 +721,14 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void setAsciiStream(String parameterName, InputStream inputStream, long length) throws SQLException {
public void setAsciiStream(String parameterName, InputStream inputStream, long length)
throws SQLException {
setAsciiStream(nameToIndex(parameterName), inputStream, length);
}
@Override
public void setAsciiStream(String parameterName, InputStream inputStream, int length) throws SQLException {
public void setAsciiStream(String parameterName, InputStream inputStream, int length)
throws SQLException {
setAsciiStream(nameToIndex(parameterName), inputStream, length);
}
......@@ -726,7 +738,8 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void setBinaryStream(String parameterName, InputStream inputStream, long length) throws SQLException {
public void setBinaryStream(String parameterName, InputStream inputStream, long length)
throws SQLException {
setBinaryStream(nameToIndex(parameterName), inputStream, length);
}
......@@ -737,12 +750,14 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void setBinaryStream(String parameterName, InputStream inputStream, int length) throws SQLException {
public void setBinaryStream(String parameterName, InputStream inputStream, int length)
throws SQLException {
setBinaryStream(nameToIndex(parameterName), inputStream, length);
}
@Override
public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
public void setCharacterStream(String parameterName, Reader reader, long length)
throws SQLException {
setCharacterStream(nameToIndex(parameterName), reader, length);
}
......@@ -752,7 +767,8 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
public void setCharacterStream(String parameterName, Reader reader, int length)
throws SQLException {
setCharacterStream(nameToIndex(parameterName), reader, length);
}
......@@ -848,13 +864,15 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void setTimestamp(String parameterName, Timestamp timestamp, Calendar cal) throws SQLException {
public void setTimestamp(String parameterName, Timestamp timestamp, Calendar cal)
throws SQLException {
setTimestamp(nameToIndex(parameterName), timestamp, cal);
}
@Override
public void setObject(String parameterName, Object obj, int targetSqlType, int scale) throws SQLException {
public void setObject(String parameterName, Object obj, int targetSqlType, int scale)
throws SQLException {
setObject(nameToIndex(parameterName), obj, targetSqlType, scale);
}
......@@ -869,12 +887,14 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
}
@Override
public void setObject(String parameterName, Object obj, SQLType targetSqlType, int scaleOrLength) throws SQLException {
public void setObject(String parameterName, Object obj, SQLType targetSqlType, int scaleOrLength)
throws SQLException {
setObject(nameToIndex(parameterName), obj, targetSqlType.getVendorTypeNumber(), scaleOrLength);
}
@Override
public void setObject(String parameterName, Object obj, SQLType targetSqlType) throws SQLException {
public void setObject(String parameterName, Object obj, SQLType targetSqlType)
throws SQLException {
setObject(nameToIndex(parameterName), obj, targetSqlType.getVendorTypeNumber());
}
......
......@@ -52,8 +52,12 @@
package org.mariadb.jdbc;
import java.sql.*;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
......@@ -63,14 +67,16 @@ import java.util.regex.Pattern;
public class CallableParameterMetaData implements ParameterMetaData {
private static final Pattern PARAMETER_PATTERN =
Pattern.compile("\\s*(IN\\s+|OUT\\s+|INOUT\\s+)?([\\w\\d]+)\\s+(UNSIGNED\\s+)?(\\w+)\\s*(\\([\\d,]+\\))?\\s*",
Pattern.compile(
"\\s*(IN\\s+|OUT\\s+|INOUT\\s+)?([\\w\\d]+)\\s+(UNSIGNED\\s+)?(\\w+)\\s*(\\([\\d,]+\\))?\\s*",
Pattern.CASE_INSENSITIVE);
private static final Pattern RETURN_PATTERN =
Pattern.compile("\\s*(UNSIGNED\\s+)?(\\w+)\\s*(\\([\\d,]+\\))?\\s*(CHARSET\\s+)?(\\w+)?\\s*", Pattern.CASE_INSENSITIVE);
private List<CallParameter> params;
Pattern.compile("\\s*(UNSIGNED\\s+)?(\\w+)\\s*(\\([\\d,]+\\))?\\s*(CHARSET\\s+)?(\\w+)?\\s*",
Pattern.CASE_INSENSITIVE);
private final MariaDbConnection con;
private String database;
private final String name;
private List<CallParameter> params;
private String database;
private boolean valid;
private boolean isFunction;
......@@ -82,7 +88,8 @@ public class CallableParameterMetaData implements ParameterMetaData {
* @param name procedure/function name
* @param isFunction is it a function
*/
public CallableParameterMetaData(MariaDbConnection con, String database, String name, boolean isFunction) {
public CallableParameterMetaData(MariaDbConnection con, String database, String name,
boolean isFunction) {
this.params = null;
this.con = con;
if (database != null) {
......@@ -190,11 +197,14 @@ public class CallableParameterMetaData implements ParameterMetaData {
+ (database != null ? "?" : "DATABASE()"))) {
preparedStatement.setString(1, name);
if (database != null) preparedStatement.setString(2, database);
if (database != null) {
preparedStatement.setString(2, database);
}
try (ResultSet rs = preparedStatement.executeQuery()) {
if (!rs.next()) {
throw new SQLException((isFunction ? "function" : "procedure") + " `" + name + "` does not exist");
throw new SQLException(
(isFunction ? "function" : "procedure") + " `" + name + "` does not exist");
}
paramList = rs.getString(1);
functionReturn = rs.getString(2);
......@@ -204,7 +214,8 @@ public class CallableParameterMetaData implements ParameterMetaData {
}
} catch (SQLSyntaxErrorException sqlSyntaxErrorException) {
throw new SQLException("Access to metaData informations not granted for current user. Consider grant select access to mysql.proc "
throw new SQLException(
"Access to metaData informations not granted for current user. Consider grant select access to mysql.proc "
+ " or avoid using parameter by name", sqlSyntaxErrorException);
}
......@@ -257,7 +268,8 @@ public class CallableParameterMetaData implements ParameterMetaData {
callParameter.setInput(true);
callParameter.setOutput(true);
} else {
throw new SQLException("unknown parameter direction " + direction + "for " + callParameter.getName());
throw new SQLException(
"unknown parameter direction " + direction + "for " + callParameter.getName());
}
callParameter.setSqlType(mapMariaDbTypeToJdbc(callParameter.getTypeName()));
......
......@@ -53,20 +53,35 @@
package org.mariadb.jdbc;
import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.ParameterMetaData;
import java.sql.Ref;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLType;
import java.sql.SQLXML;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
public abstract class CallableProcedureStatement extends MariaDbPreparedStatementServer implements CallableStatement, Cloneable {
public abstract class CallableProcedureStatement extends MariaDbPreparedStatementServer implements
CallableStatement, Cloneable {
/**
* Information about parameters, merely from registerOutputParameter() and setXXX() calls.
......@@ -81,13 +96,17 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
*
* @param connection current connection
* @param sql query
* @param resultSetScrollType one of the following <code>ResultSet</code> constants: <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
* @param resultSetScrollType one of the following <code>ResultSet</code> constants:
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code>
* or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @throws SQLException is prepareStatement connection throw any error
*/
public CallableProcedureStatement(MariaDbConnection connection, String sql, int resultSetScrollType, int resultSetConcurrency)
public CallableProcedureStatement(MariaDbConnection connection, String sql,
int resultSetScrollType, int resultSetConcurrency)
throws SQLException {
super(connection, sql, resultSetScrollType, resultSetConcurrency, Statement.NO_GENERATED_KEYS);
}
......@@ -99,7 +118,8 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
* @return Cloned .
* @throws CloneNotSupportedException if any error occur.
*/
public CallableProcedureStatement clone(MariaDbConnection connection) throws CloneNotSupportedException {
public CallableProcedureStatement clone(MariaDbConnection connection)
throws CloneNotSupportedException {
CallableProcedureStatement clone = (CallableProcedureStatement) super.clone(connection);
clone.params = params;
clone.parameterMetadata = parameterMetadata;
......@@ -374,7 +394,8 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
@Override
public Object getObject(int parameterIndex) throws SQLException {
Class<?> classType = ColumnType.classFromJavaType(getParameter(parameterIndex).getOutputSqlType());
Class<?> classType = ColumnType
.classFromJavaType(getParameter(parameterIndex).getOutputSqlType());
if (classType != null) {
return getOutputResult().getObject(indexToOutputIndex(parameterIndex), classType);
}
......@@ -520,44 +541,36 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
/**
* <p>Registers the designated output parameter.
* This version of
* the method <code>registerOutParameter</code>
* should be used for a user-defined or <code>REF</code> output parameter. Examples
* of user-defined types include: <code>STRUCT</code>, <code>DISTINCT</code>,
* This version of the method <code>registerOutParameter</code> should be used for a user-defined
* or <code>REF</code> output parameter. Examples of user-defined types include:
* <code>STRUCT</code>, <code>DISTINCT</code>,
* <code>JAVA_OBJECT</code>, and named array types.</p>
* <p>All OUT parameters must be registered
* before a stored procedure is executed.</p>
* <p> For a user-defined parameter, the fully-qualified SQL
* type name of the parameter should also be given, while a <code>REF</code>
* parameter requires that the fully-qualified type name of the
* referenced type be given. A JDBC driver that does not need the
* type code and type name information may ignore it. To be portable,
* however, applications should always provide these values for
* user-defined and <code>REF</code> parameters.</p>
* type name of the parameter should also be given, while a <code>REF</code> parameter requires
* that the fully-qualified type name of the referenced type be given. A JDBC driver that does
* not need the type code and type name information may ignore it. To be portable, however,
* applications should always provide these values for user-defined and <code>REF</code>
* parameters.</p>
* <p>Although it is intended for user-defined and <code>REF</code> parameters,
* this method may be used to register a parameter of any JDBC type.
* If the parameter does not have a user-defined or <code>REF</code> type, the
* this method may be used to register a parameter of any JDBC type. If the parameter does not
* have a user-defined or <code>REF</code> type, the
* <i>typeName</i> parameter is ignored.</p>
* <p><B>Note:</B> When reading the value of an out parameter, you
* must use the getter method whose Java type corresponds to the
* parameter's registered SQL type.</p>
* must use the getter method whose Java type corresponds to the parameter's registered SQL
* type.</p>
*
* @param parameterIndex the first parameter is 1, the second is 2,...
* @param sqlType a value from {@link Types}
* @param typeName the fully-qualified name of an SQL structured type
* @throws SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @throws SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @throws SQLException if the parameterIndex is not valid; if a database
* access error occurs or this method is called on a
* closed <code>CallableStatement</code>
* @see Types
*/
public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
public void registerOutParameter(int parameterIndex, int sqlType, String typeName)
throws SQLException {
CallParameter callParameter = getParameter(parameterIndex);
callParameter.setOutputSqlType(sqlType);
callParameter.setTypeName(typeName);
......@@ -575,27 +588,18 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
* <code>sqlType</code>. All OUT parameters must be registered
* before a stored procedure is executed.</p>
* <p>The JDBC type specified by <code>sqlType</code> for an OUT
* parameter determines the Java type that must be used
* in the <code>get</code> method to read the value of that parameter.</p>
* parameter determines the Java type that must be used in the <code>get</code> method to read the
* value of that parameter.</p>
* <p>This version of <code>registerOutParameter</code> should be
* used when the parameter is of JDBC type <code>NUMERIC</code>
* or <code>DECIMAL</code>.</p>
* used when the parameter is of JDBC type <code>NUMERIC</code> or <code>DECIMAL</code>.</p>
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param parameterIndex the first parameter is 1, the second is 2, and so on
* @param sqlType the SQL type code defined by <code>java.sql.Types</code>.
* @param scale the desired number of digits to the right of the
* decimal point. It must be greater than or equal to zero.
* @throws SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @throws SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @param scale the desired number of digits to the right of the decimal point. It must
* be greater than or equal to zero.
* @throws SQLException if the parameterIndex is not valid; if a database
* access error occurs or this method is called on a
* closed <code>CallableStatement</code>
* @see Types
*/
@Override
......@@ -612,13 +616,15 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
public void registerOutParameter(String parameterName, int sqlType, int scale)
throws SQLException {
registerOutParameter(nameToIndex(parameterName), sqlType, scale);
}
@Override
public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
public void registerOutParameter(String parameterName, int sqlType, String typeName)
throws SQLException {
registerOutParameter(nameToIndex(parameterName), sqlType, typeName);
}
......@@ -629,12 +635,14 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void registerOutParameter(int parameterIndex, SQLType sqlType, int scale) throws SQLException {
public void registerOutParameter(int parameterIndex, SQLType sqlType, int scale)
throws SQLException {
registerOutParameter(parameterIndex, sqlType.getVendorTypeNumber(), scale);
}
@Override
public void registerOutParameter(int parameterIndex, SQLType sqlType, String typeName) throws SQLException {
public void registerOutParameter(int parameterIndex, SQLType sqlType, String typeName)
throws SQLException {
registerOutParameter(parameterIndex, sqlType.getVendorTypeNumber(), typeName);
}
......@@ -644,12 +652,14 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void registerOutParameter(String parameterName, SQLType sqlType, int scale) throws SQLException {
public void registerOutParameter(String parameterName, SQLType sqlType, int scale)
throws SQLException {
registerOutParameter(parameterName, sqlType.getVendorTypeNumber(), scale);
}
@Override
public void registerOutParameter(String parameterName, SQLType sqlType, String typeName) throws SQLException {
public void registerOutParameter(String parameterName, SQLType sqlType, String typeName)
throws SQLException {
registerOutParameter(parameterName, sqlType.getVendorTypeNumber(), typeName);
}
......@@ -676,7 +686,8 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {
public void setNCharacterStream(String parameterName, Reader value, long length)
throws SQLException {
setCharacterStream(nameToIndex(parameterName), value, length);
}
......@@ -716,7 +727,8 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {
public void setBlob(String parameterName, InputStream inputStream, long length)
throws SQLException {
setBlob(nameToIndex(parameterName), inputStream, length);
}
......@@ -731,12 +743,14 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void setAsciiStream(String parameterName, InputStream inputStream, long length) throws SQLException {
public void setAsciiStream(String parameterName, InputStream inputStream, long length)
throws SQLException {
setAsciiStream(nameToIndex(parameterName), inputStream, length);
}
@Override
public void setAsciiStream(String parameterName, InputStream inputStream, int length) throws SQLException {
public void setAsciiStream(String parameterName, InputStream inputStream, int length)
throws SQLException {
setAsciiStream(nameToIndex(parameterName), inputStream, length);
}
......@@ -746,7 +760,8 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void setBinaryStream(String parameterName, InputStream inputStream, long length) throws SQLException {
public void setBinaryStream(String parameterName, InputStream inputStream, long length)
throws SQLException {
setBinaryStream(nameToIndex(parameterName), inputStream, length);
}
......@@ -757,12 +772,14 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void setBinaryStream(String parameterName, InputStream inputStream, int length) throws SQLException {
public void setBinaryStream(String parameterName, InputStream inputStream, int length)
throws SQLException {
setBinaryStream(nameToIndex(parameterName), inputStream, length);
}
@Override
public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
public void setCharacterStream(String parameterName, Reader reader, long length)
throws SQLException {
setCharacterStream(nameToIndex(parameterName), reader, length);
}
......@@ -772,7 +789,8 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
public void setCharacterStream(String parameterName, Reader reader, int length)
throws SQLException {
setCharacterStream(nameToIndex(parameterName), reader, length);
}
......@@ -868,13 +886,15 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void setTimestamp(String parameterName, Timestamp timestamp, Calendar cal) throws SQLException {
public void setTimestamp(String parameterName, Timestamp timestamp, Calendar cal)
throws SQLException {
setTimestamp(nameToIndex(parameterName), timestamp, cal);
}
@Override
public void setObject(String parameterName, Object obj, int targetSqlType, int scale) throws SQLException {
public void setObject(String parameterName, Object obj, int targetSqlType, int scale)
throws SQLException {
setObject(nameToIndex(parameterName), obj, targetSqlType, scale);
}
......@@ -889,12 +909,14 @@ public abstract class CallableProcedureStatement extends MariaDbPreparedStatemen
}
@Override
public void setObject(String parameterName, Object obj, SQLType targetSqlType, int scaleOrLength) throws SQLException {
public void setObject(String parameterName, Object obj, SQLType targetSqlType, int scaleOrLength)
throws SQLException {
setObject(nameToIndex(parameterName), obj, targetSqlType.getVendorTypeNumber(), scaleOrLength);
}
@Override
public void setObject(String parameterName, Object obj, SQLType targetSqlType) throws SQLException {
public void setObject(String parameterName, Object obj, SQLType targetSqlType)
throws SQLException {
setObject(nameToIndex(parameterName), obj, targetSqlType.getVendorTypeNumber());
}
......
......@@ -52,10 +52,18 @@
package org.mariadb.jdbc;
import org.mariadb.jdbc.internal.util.constant.Version;
import java.sql.*;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.mariadb.jdbc.internal.util.DefaultOptions;
import org.mariadb.jdbc.internal.util.Options;
import org.mariadb.jdbc.internal.util.constant.Version;
public final class Driver implements java.sql.Driver {
......@@ -70,8 +78,6 @@ public final class Driver implements java.sql.Driver {
/**
* Connect to the given connection string.
* <p>
* the properties are currently ignored
*
* @param url the url to connect to
* @return a connection
......@@ -100,7 +106,7 @@ public final class Driver implements java.sql.Driver {
}
/**
* get the property info. TODO: not implemented!
* Get the property info.
*
* @param url the url to get properties for
* @param info the info props
......@@ -110,6 +116,29 @@ public final class Driver implements java.sql.Driver {
public DriverPropertyInfo[] getPropertyInfo(String url,
Properties info)
throws SQLException {
if (url != null) {
UrlParser urlParser = UrlParser.parse(url, info);
if (urlParser == null || urlParser.getOptions() == null) {
return new DriverPropertyInfo[0];
}
List<DriverPropertyInfo> props = new ArrayList<>();
for (DefaultOptions o : DefaultOptions.values()) {
try {
Field field = Options.class.getField(o.getOptionName());
Object value = field.get(urlParser.getOptions());
DriverPropertyInfo propertyInfo = new DriverPropertyInfo(field.getName(),
value == null ? null : value.toString());
propertyInfo.description = o.getDescription();
propertyInfo.required = o.isRequired();
props.add(propertyInfo);
} catch (NoSuchFieldException | IllegalAccessException e) {
//eat error
}
}
return props.toArray(new DriverPropertyInfo[props.size()]);
}
return new DriverPropertyInfo[0];
}
......
......@@ -52,17 +52,17 @@
package org.mariadb.jdbc;
import org.mariadb.jdbc.internal.logging.Logger;
import org.mariadb.jdbc.internal.logging.LoggerFactory;
import org.mariadb.jdbc.internal.util.constant.HaMode;
import org.mariadb.jdbc.internal.util.constant.ParameterConstant;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.mariadb.jdbc.internal.logging.Logger;
import org.mariadb.jdbc.internal.logging.LoggerFactory;
import org.mariadb.jdbc.internal.util.constant.HaMode;
import org.mariadb.jdbc.internal.util.constant.ParameterConstant;
public class HostAddress {
private static final Logger logger = LoggerFactory.getLogger(HostAddress.class);
public String host;
......@@ -99,11 +99,10 @@ public class HostAddress {
}
/**
* parse - parse server addresses from the URL fragment
* parse - parse server addresses from the URL fragment.
*
* @param spec - list of endpoints in one of the forms
* 1 - host1,....,hostN:port (missing port default to MySQL default 3306
* 2 - host:port,...,host:port
* @param spec list of endpoints in one of the forms 1 - host1,....,hostN:port (missing port
* default to MySQL default 3306 2 - host:port,...,host:port
* @param haMode High availability mode
* @return parsed endpoints
*/
......@@ -120,7 +119,9 @@ public class HostAddress {
// Aurora using cluster end point mustn't have any other host
if (haMode == HaMode.AURORA) {
Pattern clusterPattern = Pattern.compile("(.+)\\.cluster-([a-z0-9]+\\.[a-z0-9\\-]+\\.rds\\.amazonaws\\.com)", Pattern.CASE_INSENSITIVE);
Pattern clusterPattern = Pattern
.compile("(.+)\\.cluster-([a-z0-9]+\\.[a-z0-9\\-]+\\.rds\\.amazonaws\\.com)",
Pattern.CASE_INSENSITIVE);
Matcher matcher = clusterPattern.matcher(spec);
if (!matcher.find()) {
......@@ -186,7 +187,8 @@ public class HostAddress {
for (int i = 1; i < array.length; i++) {
String[] token = array[i].replace("(", "").replace(")", "").trim().split("=");
if (token.length != 2) {
throw new IllegalArgumentException("Invalid connection URL, expected key=value pairs, found " + array[i]);
throw new IllegalArgumentException(
"Invalid connection URL, expected key=value pairs, found " + array[i]);
}
String key = token[0].toLowerCase();
String value = token[1].toLowerCase();
......@@ -195,7 +197,8 @@ public class HostAddress {
} else if ("port".equals(key)) {
result.port = getPort(value);
} else if ("type".equals(key)
&& (value.equals(ParameterConstant.TYPE_MASTER) || value.equals(ParameterConstant.TYPE_SLAVE))) {
&& (value.equals(ParameterConstant.TYPE_MASTER) || value
.equals(ParameterConstant.TYPE_SLAVE))) {
result.type = value;
}
}
......
......@@ -52,12 +52,17 @@
package org.mariadb.jdbc;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.Arrays;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
public class MariaDbBlob implements Blob, Serializable {
......@@ -124,7 +129,8 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* Returns the number of bytes in the <code>BLOB</code> value designated by this <code>Blob</code> object.
* Returns the number of bytes in the <code>BLOB</code> value designated by this <code>Blob</code>
* object.
*
* @return length of the <code>BLOB</code> in bytes
* @throws SQLException if there is an error accessing the length of the <code>BLOB</code>
......@@ -134,17 +140,20 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* Retrieves all or part of the <code>BLOB</code> value that this <code>Blob</code> object represents, as an array
* of bytes. This <code>byte</code> array contains up to <code>length</code> consecutive bytes starting at position
* Retrieves all or part of the <code>BLOB</code> value that this <code>Blob</code> object
* represents, as an array of bytes. This <code>byte</code> array contains up to
* <code>length</code> consecutive bytes starting at position
* <code>pos</code>.
*
* @param pos the ordinal position of the first byte in the <code>BLOB</code> value to be extracted; the first
* byte is at position 1
* @param length the number of consecutive bytes to be copied; the value for length must be 0 or greater
* @return a byte array containing up to <code>length</code> consecutive bytes from the <code>BLOB</code> value
* designated by this <code>Blob</code> object, starting with the byte at position <code>pos</code>
* @throws SQLException if there is an error accessing the <code>BLOB</code> value; if pos is less than 1
* or length is less than 0
* @param pos the ordinal position of the first byte in the <code>BLOB</code> value to be
* extracted; the first byte is at position 1
* @param length the number of consecutive bytes to be copied; the value for length must be 0 or
* greater
* @return a byte array containing up to <code>length</code> consecutive bytes from the
* <code>BLOB</code> value designated by this <code>Blob</code> object, starting with the
* byte at position <code>pos</code>
* @throws SQLException if there is an error accessing the <code>BLOB</code> value; if pos is less
* than 1 or length is less than 0
* @see #setBytes
* @since 1.2
*/
......@@ -159,7 +168,8 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* Retrieves the <code>BLOB</code> value designated by this <code>Blob</code> instance as a stream.
* Retrieves the <code>BLOB</code> value designated by this <code>Blob</code> instance as a
* stream.
*
* @return a stream containing the <code>BLOB</code> data
* @throws SQLException if something went wrong
......@@ -170,15 +180,18 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* Returns an <code>InputStream</code> object that contains a partial <code>Blob</code> value, starting with the
* byte specified by pos, which is length bytes in length.
* Returns an <code>InputStream</code> object that contains a partial <code>Blob</code> value,
* starting with the byte specified by pos, which is length bytes in length.
*
* @param pos the offset to the first byte of the partial value to be retrieved. The first byte in the
* @param pos the offset to the first byte of the partial value to be retrieved. The first byte
* in the
* <code>Blob</code> is at position 1
* @param length the length in bytes of the partial value to be retrieved
* @return <code>InputStream</code> through which the partial <code>Blob</code> value can be read.
* @throws SQLException if pos is less than 1 or if pos is greater than the number of bytes in the
* <code>Blob</code> or if pos + length is greater than the number of bytes in the
* @throws SQLException if pos is less than 1 or if pos is greater than the number of bytes in
* the
* <code>Blob</code> or if pos + length is greater than the number of bytes
* in the
* <code>Blob</code>
*/
public InputStream getBinaryStream(final long pos, final long length) throws SQLException {
......@@ -196,8 +209,10 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* Retrieves the byte position at which the specified byte array <code>pattern</code> begins within the
* <code>BLOB</code> value that this <code>Blob</code> object represents. The search for <code>pattern</code>
* Retrieves the byte position at which the specified byte array <code>pattern</code> begins
* within the
* <code>BLOB</code> value that this <code>Blob</code> object represents. The search for
* <code>pattern</code>
* begins at position <code>start</code>.
*
* @param pattern the byte array for which to search
......@@ -232,11 +247,14 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* Retrieves the byte position in the <code>BLOB</code> value designated by this <code>Blob</code> object at which
* Retrieves the byte position in the <code>BLOB</code> value designated by this <code>Blob</code>
* object at which
* <code>pattern</code> begins. The search begins at position <code>start</code>.
*
* @param pattern the <code>Blob</code> object designating the <code>BLOB</code> value for which to search
* @param start the position in the <code>BLOB</code> value at which to begin searching; the first position is 1
* @param pattern the <code>Blob</code> object designating the <code>BLOB</code> value for which
* to search
* @param start the position in the <code>BLOB</code> value at which to begin searching; the
* first position is 1
* @return the position at which the pattern begins, else -1
*/
public long position(final Blob pattern, final long start) throws SQLException {
......@@ -244,15 +262,18 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* Writes the given array of bytes to the <code>BLOB</code> value that this <code>Blob</code> object represents,
* starting at position <code>pos</code>, and returns the number of bytes written. The array of bytes will overwrite
* the existing bytes in the <code>Blob</code> object starting at the position <code>pos</code>. If the end of the
* <code>Blob</code> value is reached while writing the array of bytes, then the length of the <code>Blob</code>
* Writes the given array of bytes to the <code>BLOB</code> value that this <code>Blob</code>
* object represents, starting at position <code>pos</code>, and returns the number of bytes
* written. The array of bytes will overwrite the existing bytes in the <code>Blob</code> object
* starting at the position <code>pos</code>. If the end of the
* <code>Blob</code> value is reached while writing the array of bytes, then the length of the
* <code>Blob</code>
* value will be increased to accommodate the extra bytes.
*
* @param pos the position in the <code>BLOB</code> object at which to start writing; the first position is 1
* @param bytes the array of bytes to be written to the <code>BLOB</code> value that this <code>Blob</code> object
* represents
* @param pos the position in the <code>BLOB</code> object at which to start writing; the first
* position is 1
* @param bytes the array of bytes to be written to the <code>BLOB</code> value that this
* <code>Blob</code> object represents
* @return the number of bytes written
* @see #getBytes
*/
......@@ -283,25 +304,33 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* Writes all or part of the given <code>byte</code> array to the <code>BLOB</code> value that this
* <code>Blob</code> object represents and returns the number of bytes written. Writing starts at position
* <code>pos</code> in the <code>BLOB</code> value; <code>len</code> bytes from the given byte array are written.
* The array of bytes will overwrite the existing bytes in the <code>Blob</code> object starting at the position
* <code>pos</code>. If the end of the <code>Blob</code> value is reached while writing the array of bytes, then
* the length of the <code>Blob</code> value will be increased to accommodate the extra bytes.
* <p>
* <b>Note:</b> If the value specified for <code>pos</code> is greater then the length+1 of the <code>BLOB</code>
* value then the behavior is undefined. Some JDBC drivers may throw a <code>SQLException</code> while other drivers
* may support this operation.
* Writes all or part of the given <code>byte</code> array to the <code>BLOB</code> value that
* this
* <code>Blob</code> object represents and returns the number of bytes written. Writing starts at
* position
* <code>pos</code> in the <code>BLOB</code> value; <code>len</code> bytes from the given byte
* array are written. The array of bytes will overwrite the existing bytes in the
* <code>Blob</code> object starting at the position
* <code>pos</code>. If the end of the <code>Blob</code> value is reached while writing the
* array of bytes, then the length of the <code>Blob</code> value will be increased to accommodate
* the extra bytes.
*
* @param pos the position in the <code>BLOB</code> object at which to start writing; the first position is 1
* <p><b>Note:</b> If the value specified for <code>pos</code> is greater then the length+1 of the
* <code>BLOB</code>
* value then the behavior is undefined. Some JDBC drivers may throw a <code>SQLException</code>
* while other drivers may support this operation.</p>
*
* @param pos the position in the <code>BLOB</code> object at which to start writing; the first
* position is 1
* @param bytes the array of bytes to be written to this <code>BLOB</code> object
* @param offset the offset into the array <code>bytes</code> at which to start reading the bytes to be set
* @param len the number of bytes to be written to the <code>BLOB</code> value from the array of bytes
* @param offset the offset into the array <code>bytes</code> at which to start reading the bytes
* to be set
* @param len the number of bytes to be written to the <code>BLOB</code> value from the array
* of bytes
* <code>bytes</code>
* @return the number of bytes written
* @throws SQLException if there is an error accessing the <code>BLOB</code> value or if pos is less than
* 1
* @throws SQLException if there is an error accessing the <code>BLOB</code> value or if pos is
* less than 1
* @see #getBytes
*/
public int setBytes(final long pos,
......@@ -336,20 +365,24 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* Retrieves a stream that can be used to write to the <code>BLOB</code> value that this <code>Blob</code> object
* represents. The stream begins at position <code>pos</code>. The bytes written to the stream will overwrite the
* existing bytes in the <code>Blob</code> object starting at the position <code>pos</code>. If the end of the
* <code>Blob</code> value is reached while writing to the stream, then the length of the <code>Blob</code> value
* Retrieves a stream that can be used to write to the <code>BLOB</code> value that this
* <code>Blob</code> object represents. The stream begins at position <code>pos</code>. The
* bytes written to the stream will overwrite the existing bytes in the <code>Blob</code> object
* starting at the position <code>pos</code>. If the end of the
* <code>Blob</code> value is reached while writing to the stream, then the length of the
* <code>Blob</code> value
* will be increased to accommodate the extra bytes.
* <p>
* <b>Note:</b> If the value specified for <code>pos</code> is greater then the length+1 of the <code>BLOB</code>
* value then the behavior is undefined. Some JDBC drivers may throw a <code>SQLException</code> while other drivers
* may support this operation.
*
* @param pos the position in the <code>BLOB</code> value at which to start writing; the first position is 1
* <p><b>Note:</b> If the value specified for <code>pos</code> is greater then the length+1 of the
* <code>BLOB</code>
* value then the behavior is undefined. Some JDBC drivers may throw a <code>SQLException</code>
* while other drivers may support this operation.</p>
*
* @param pos the position in the <code>BLOB</code> value at which to start writing; the first
* position is 1
* @return a <code>java.io.OutputStream</code> object to which data can be written
* @throws SQLException if there is an error accessing the <code>BLOB</code> value or if pos is less than
* 1
* @throws SQLException if there is an error accessing the <code>BLOB</code> value or if pos is
* less than 1
* @see #getBinaryStream
* @since 1.4
*/
......@@ -367,13 +400,13 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* Truncates the <code>BLOB</code> value that this <code>Blob</code> object represents to be <code>len</code> bytes
* in length.
* Truncates the <code>BLOB</code> value that this <code>Blob</code> object represents to be
* <code>len</code> bytes in length.
*
* @param len the length, in bytes, to which the <code>BLOB</code> value that this <code>Blob</code> object
* represents should be truncated
* @throws SQLException if there is an error accessing the <code>BLOB</code> value or if len is less than
* 0
* @param len the length, in bytes, to which the <code>BLOB</code> value that this
* <code>Blob</code> object represents should be truncated
* @throws SQLException if there is an error accessing the <code>BLOB</code> value or if len is
* less than 0
*/
public void truncate(final long len) throws SQLException {
if (len >= 0 && len < this.length) {
......@@ -382,12 +415,13 @@ public class MariaDbBlob implements Blob, Serializable {
}
/**
* This method frees the <code>Blob</code> object and releases the resources that it holds. The object is invalid
* once the <code>free</code> method is called.
* <p>
* After <code>free</code> has been called, any attempt to invoke a method other than <code>free</code> will result
* in a <code>SQLException</code> being thrown. If <code>free</code> is called multiple times, the subsequent calls
* to <code>free</code> are treated as a no-op.
* This method frees the <code>Blob</code> object and releases the resources that it holds. The
* object is invalid once the <code>free</code> method is called.
*
* <p>After <code>free</code> has been called, any attempt to invoke a method other than
* <code>free</code> will result in a <code>SQLException</code> being thrown. If
* <code>free</code> is called multiple times, the subsequent calls to <code>free</code> are
* treated as a no-op.</p>
*/
public void free() {
this.data = new byte[0];
......
......@@ -52,14 +52,20 @@
package org.mariadb.jdbc;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
import java.io.*;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Serializable;
import java.io.StringReader;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.StandardCharsets;
import java.sql.Clob;
import java.sql.NClob;
import java.sql.SQLException;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
public class MariaDbClob extends MariaDbBlob implements Clob, NClob, Serializable {
......@@ -132,20 +138,22 @@ public class MariaDbClob extends MariaDbBlob implements Clob, NClob, Serializabl
}
/**
* Returns a Reader object that contains a partial Clob value, starting with the character specified by pos, which
* is length characters in length.
* Returns a Reader object that contains a partial Clob value, starting with the character
* specified by pos, which is length characters in length.
*
* @param pos the offset to the first character of the partial value to be retrieved. The first character in the
* Clob is at position 1.
* @param pos the offset to the first character of the partial value to be retrieved. The first
* character in the Clob is at position 1.
* @param length the length in characters of the partial value to be retrieved.
* @return Reader through which the partial Clob value can be read.
* @throws SQLException if pos is less than 1 or if pos is greater than the number of characters in the Clob or
* if pos + length is greater than the number of characters in the Clob
* @throws SQLException if pos is less than 1 or if pos is greater than the number of characters
* in the Clob or if pos + length is greater than the number of characters in
* the Clob
*/
public Reader getCharacterStream(long pos, long length) throws SQLException {
String val = toString();
if (val.length() < (int) pos - 1 + length) {
throw ExceptionMapper.getSqlException("pos + length is greater than the number of characters in the Clob");
throw ExceptionMapper
.getSqlException("pos + length is greater than the number of characters in the Clob");
}
String sub = val.substring((int) pos - 1, (int) pos - 1 + (int) length);
return new StringReader(sub);
......