[CONJ-496] Driver not dealing with non zero decimal values Created: 2017-06-21  Updated: 2017-07-06  Resolved: 2017-07-06

Status: Closed
Project: MariaDB Connector/J
Component/s: JDBC 4.2 compatibility
Affects Version/s: 1.4.4, 1.5.9, 1.6.1, 2.0.3, 1.6.2
Fix Version/s: 2.1.0, 1.6.3

Type: Bug Priority: Critical
Reporter: Kris Iyer Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None


 Description   

We have an environment where we are upgrading the driver from v1.1.8 to 1.6.1 where we are running into issues where a decimal value coming back on the result set does not get parsed as an integer on v1.6.1 (getInt). The previous behavior on 1.x was that the value would get rounded and be a valid integer.

For instance:

mysql> select 100/3 as test;
---------

test

---------

33.3333

---------
1 row in set (0.00 sec)

When run through the Driver v1.6.1:
Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: Out of range value for column 'test' : value 33.3333 is not in Integer range
at ::
Caused by: java.sql.SQLException: Out of range value for column 'test' : value 33.3333 is not in Integer range
at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.parseInt(SelectResultSet.java:3440)
at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.getInternalInt(SelectResultSet.java:1075)
at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.getInt(SelectResultSet.java:1054)
at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.getInt(SelectResultSet.java:1061)

When run on Driver 1.x:
Results: 33.

Tested this on multiple versions > 1.x and it seems to be consistent with 1.6.1. The workaround i figured is to parse as Double or Float. However we have a lot of code to refactor if thats what is desired moving forward.

Note: This also affects getByte, getShort and getInt behavior. For instance a getByte against 1.0 = 1, whereas a getByte against 1.1 will be a similar out of range Exception for the byte range.



 Comments   
Comment by Kris Iyer [ 2017-06-21 ]

If it helps this seems to have been introduced in v1.3.3. v1.3.2 and lower seem to give you the same behavior as 1.x (which is getInt() rounds off decimals).

v1.3.2 dealt with NFE and returned the value as a BigDecimal:

if (!this.isBinaryEncoded) {
            try {
                return Integer.valueOf(new String(rawBytes, StandardCharsets.UTF_8));
            } catch (NumberFormatException nfe) {
                BigDecimal value = new BigDecimal(new String(rawBytes, StandardCharsets.UTF_8));
                if (value.compareTo(BigDecimal.valueOf(Integer.MIN_VALUE)) < 0) {
                    return Integer.MIN_VALUE;
                }
                if (value.compareTo(BigDecimal.valueOf(Integer.MAX_VALUE)) > 0) {
                    return Integer.MAX_VALUE;
                }
                return value.intValue();
            }
        }

Comment by Kris Iyer [ 2017-06-22 ]

Submitted a fix for this issue - https://github.com/MariaDB/mariadb-connector-j/pull/108

Thanks!

Comment by Kris Iyer [ 2017-06-27 ]

These fixes have not made it into 1.6.2 or 2.0.3 - atleast by looking at what was released today. The submitted Pull Request for the fix is also open.

Comment by Diego Dupin [ 2017-06-27 ]

réopen issue, i've confused pull request 107 and 108.

Comment by Diego Dupin [ 2017-06-27 ]

This will be corrected in 2.1.0 version.

correction is available using 2.1.0 snapshot :

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>
 
<dependencies>
    <dependency>
        <groupId>org.mariadb.jdbc</groupId>
        <artifactId>mariadb-java-client</artifactId>
        <version>2.1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

Comment by Kris Iyer [ 2017-06-27 ]

Thanks for the update. Would it also be possible to get a 1.6.4-SNAPSHOT as well? Will help to use a Java 7 compatible version to unblock teams on this. Also if i could get an ETA for the releases that will be great.

Comment by Diego Dupin [ 2017-06-28 ]

Snapshot for version 1.6 : (1.6.3-SNAPSHOT) now available with this correction :

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>
 
<dependencies>
    <dependency>
        <groupId>org.mariadb.jdbc</groupId>
        <artifactId>mariadb-java-client</artifactId>
        <version>1.6.3-SNAPSHOT</version>
    </dependency>
</dependencies>

1.6.3 and 2.1.0 release date is 2017-07-31 (https://jira.mariadb.org/plugins/servlet/project-config/CONJ/administer-versions?&status=unreleased)

Comment by Kris Iyer [ 2017-06-28 ]

Thanks for the update and providing 1.6.3-SNAPSHOT!

Comment by JF D [ 2017-07-05 ]

Comment at line 3519 is no longer valid in org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet:

            //if this is a decimal with only "0" in decimal, like "1.0000" (can be the case if trying to getInt with a database decimal value
            //retrying without the decimal part.

Comment by Kris Iyer [ 2017-07-05 ]

Thanks for catching that. I have a Pull Request into develop to update that.

Comment by Diego Dupin [ 2017-07-06 ]

yes, PR merged.

Generated at Thu Feb 08 03:16:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.