Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-496

Driver not dealing with non zero decimal values

Details

    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.

      Attachments

        Activity

          krisiyer Kris Iyer created issue -
          krisiyer Kris Iyer made changes -
          Field Original Value New Value
          Summary Driver not dealing with Float values as integer. Driver not dealing with Float/Double values as integer.
          krisiyer Kris Iyer made changes -
          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. 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 mariajdbc.JDBCCallableStatementOUTParameterExample.testSQL(JDBCCallableStatementOUTParameterExample.java:56)
          at mariajdbc.JDBCCallableStatementOUTParameterExample.main(JDBCCallableStatementOUTParameterExample.java:24)
          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)
          at mariajdbc.JDBCCallableStatementOUTParameterExample.testSQL(JDBCCallableStatementOUTParameterExample.java:52)
          ... 1 more

          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.
          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. 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.
          krisiyer Kris Iyer made changes -
          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. 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.
          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.
          krisiyer Kris Iyer made changes -
          Component/s JDBC 4.2 compatibility [ 14001 ]
          krisiyer Kris Iyer added a comment - - edited

          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();
                      }
                  }
          

          krisiyer Kris Iyer added a comment - - edited 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(); } }
          krisiyer Kris Iyer made changes -
          Summary Driver not dealing with Float/Double values as integer. Driver not dealing with non zero decimal values
          krisiyer Kris Iyer made changes -
          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.
          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 an Exception.
          krisiyer Kris Iyer made changes -
          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 an Exception.
          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.
          krisiyer Kris Iyer added a comment - - edited

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

          Thanks!

          krisiyer Kris Iyer added a comment - - edited Submitted a fix for this issue - https://github.com/MariaDB/mariadb-connector-j/pull/108 Thanks!
          diego dupin Diego Dupin made changes -
          Fix Version/s 2.0.3 [ 22559 ]
          Fix Version/s 1.6.2 [ 22560 ]
          diego dupin Diego Dupin made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          diego dupin Diego Dupin made changes -
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          krisiyer Kris Iyer added a comment -

          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.

          krisiyer Kris Iyer added a comment - 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.
          diego dupin Diego Dupin added a comment -

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

          diego dupin Diego Dupin added a comment - réopen issue, i've confused pull request 107 and 108.
          diego dupin Diego Dupin made changes -
          Resolution Fixed [ 1 ]
          Status Closed [ 6 ] Stalled [ 10000 ]
          diego dupin Diego Dupin made changes -
          Fix Version/s 1.6.4 [ 22561 ]
          Fix Version/s 2.1.0 [ 22528 ]
          Fix Version/s 2.0.3 [ 22559 ]
          Fix Version/s 1.6.2 [ 22560 ]
          diego dupin Diego Dupin added a comment -

          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>
          

          diego dupin Diego Dupin added a comment - 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>
          krisiyer Kris Iyer added a comment -

          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.

          krisiyer Kris Iyer added a comment - 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.
          diego dupin Diego Dupin added a comment -

          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)

          diego dupin Diego Dupin added a comment - 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 )
          diego dupin Diego Dupin made changes -
          Fix Version/s 1.6.3 [ 22562 ]
          Fix Version/s 1.6.4 [ 22561 ]
          krisiyer Kris Iyer added a comment -

          Thanks for the update and providing 1.6.3-SNAPSHOT!

          krisiyer Kris Iyer added a comment - Thanks for the update and providing 1.6.3-SNAPSHOT!
          jfdignard JF D added a comment - - edited

          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.
          

          jfdignard JF D added a comment - - edited 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.
          krisiyer Kris Iyer added a comment -

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

          krisiyer Kris Iyer added a comment - Thanks for catching that. I have a Pull Request into develop to update that.
          krisiyer Kris Iyer made changes -
          Affects Version/s 1.6.2 [ 22560 ]
          krisiyer Kris Iyer made changes -
          Affects Version/s 2.0.3 [ 22559 ]
          diego dupin Diego Dupin added a comment -

          yes, PR merged.

          diego dupin Diego Dupin added a comment - yes, PR merged.
          diego dupin Diego Dupin made changes -
          Resolution Fixed [ 1 ]
          Status Stalled [ 10000 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 81322 ] MariaDB v4 [ 134996 ]

          People

            diego dupin Diego Dupin
            krisiyer Kris Iyer
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.