From: Date: July 18 2006 8:01pm Subject: Connector/J commit: r5526 - in branches: branch_3_1/connector-j branch_3_1/connector-j/src/com/mysql/jdbc branch_3_1/connector-j/src/testsuite/regression branch_5_0/connector-j branch_5_0/connector-j/src/com/mysql/jdbc branch_5_0/connector-j/src/testsuite/regression branch_5_1/connector-j branch_5_1/connector-j/src/com/mysql/jdbc branch_5_1/connector-j/src/testsuite/regression List-Archive: http://lists.mysql.com/commits/9289 X-Bug: 18880 Message-Id: <200607181801.k6II1Ssr032549@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/branch_3_1/connector-j/CHANGES branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java branches/branch_3_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java branches/branch_5_0/connector-j/CHANGES branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java branches/branch_5_1/connector-j/CHANGES branches/branch_5_1/connector-j/src/com/mysql/jdbc/ResultSet.java branches/branch_5_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java Log: Fixed BUG#18880 - ResultSet.getFloatFromString() can't retrieve values near Float.MIN/MAX_VALUE. Modified: branches/branch_3_1/connector-j/CHANGES =================================================================== --- branches/branch_3_1/connector-j/CHANGES 2006-07-18 16:49:10 UTC (rev 5525) +++ branches/branch_3_1/connector-j/CHANGES 2006-07-18 18:01:22 UTC (rev 5526) @@ -24,6 +24,9 @@ raised when re-using them. - Fixed BUG#21062 - ResultSet.getSomeInteger() doesn't work for BIT(>1). + + - Fixed BUG#18880 - ResultSet.getFloatFromString() can't retrieve + values near Float.MIN/MAX_VALUE. 05-26-06 - Version 3.1.13 Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java =================================================================== --- branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-07-18 16:49:10 UTC (rev 5525) +++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-07-18 18:01:22 UTC (rev 5526) @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2004 MySQL AB + Copyright (C) 2002-2006 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as @@ -114,6 +114,19 @@ * @see java.sql.ResultSet */ public class ResultSet implements java.sql.ResultSet { + + /** + * Epsillon between Float.MIN_VALUE and the double representation of said value. + */ + protected static final double MIN_DIFF_PREC = Float.parseFloat(Float.toString(Float.MIN_VALUE)) + - Double.parseDouble(Float.toString(Float.MIN_VALUE)); + + /** + * Epsillon between Float.MAX_VALUE and the double representation of said value. + */ + protected static final double MAX_DIFF_PREC = Float.parseFloat(Float.toString(Float.MAX_VALUE)) + - Double.parseDouble(Float.toString(Float.MAX_VALUE)); + /** Counter used to generate IDs for profiling. */ protected static int resultCounter = 1; @@ -2291,19 +2304,13 @@ // Straight comparison is not reliable when at // absolute endpoints of Float.MIN_VALUE or - // Float.MAX_VALUE, so use epsillons + // Float.MAX_VALUE, so use epsillons with DOUBLEs - if (valAsDouble < Float.MIN_VALUE) { - if (Math.abs(valAsDouble - Float.MIN_VALUE) > .0001) { - throwRangeException(String.valueOf(valAsDouble), - columnIndex, Types.FLOAT); - } - } else if (valAsDouble > Float.MAX_VALUE) { - if (Math.abs(valAsDouble - Float.MAX_VALUE) > .0001) { - throwRangeException(String.valueOf(valAsDouble), - columnIndex, Types.FLOAT); - } - } + if ((valAsDouble < Float.MIN_VALUE - MIN_DIFF_PREC) + || (valAsDouble > Float.MAX_VALUE - MAX_DIFF_PREC)) { + throwRangeException(String.valueOf(valAsDouble), columnIndex, + Types.FLOAT); + } } } Modified: branches/branch_3_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java =================================================================== --- branches/branch_3_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-07-18 16:49:10 UTC (rev 5525) +++ branches/branch_3_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-07-18 18:01:22 UTC (rev 5526) @@ -2354,6 +2354,23 @@ checkResult17450(); } } + + /** + * Tests fix for BUG#18880 - ResultSet.getFloatFromString() can't retrieve + * values near Float.MIN/MAX_VALUE. + * + * @throws Exception if the test fails. + */ + public void testBug18880() throws Exception { + try { + this.rs = this.stmt.executeQuery("SELECT 3.4E38,1.4E-45"); + this.rs.next(); + this.rs.getFloat(1); + this.rs.getFloat(2); + } finally { + closeMemberJDBCResources(); + } + } /** * Tests fix for BUG#19282 - ResultSet.wasNull() returns Modified: branches/branch_5_0/connector-j/CHANGES =================================================================== --- branches/branch_5_0/connector-j/CHANGES 2006-07-18 16:49:10 UTC (rev 5525) +++ branches/branch_5_0/connector-j/CHANGES 2006-07-18 18:01:22 UTC (rev 5526) @@ -191,7 +191,10 @@ raised when re-using them. - Fixed BUG#21062 - ResultSet.getSomeInteger() doesn't work for BIT(>1). - + + - Fixed BUG#18880 - ResultSet.getFloatFromString() can't retrieve + values near Float.MIN/MAX_VALUE. + 05-26-06 - Version 3.1.13 - Fixed BUG#15464 - INOUT parameter does not store IN value. Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-07-18 16:49:10 UTC (rev 5525) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-07-18 18:01:22 UTC (rev 5526) @@ -116,6 +116,19 @@ * @see java.sql.ResultSet */ public class ResultSet implements java.sql.ResultSet { + + /** + * Epsillon between Float.MIN_VALUE and the double representation of said value. + */ + protected static final double MIN_DIFF_PREC = Float.parseFloat(Float.toString(Float.MIN_VALUE)) + - Double.parseDouble(Float.toString(Float.MIN_VALUE)); + + /** + * Epsillon between Float.MAX_VALUE and the double representation of said value. + */ + protected static final double MAX_DIFF_PREC = Float.parseFloat(Float.toString(Float.MAX_VALUE)) + - Double.parseDouble(Float.toString(Float.MAX_VALUE)); + /** Counter used to generate IDs for profiling. */ protected static int resultCounter = 1; @@ -2297,17 +2310,17 @@ if (this.connection.getJdbcCompliantTruncationForReads()) { if (f == Float.MIN_VALUE || f == Float.MAX_VALUE) { + double valAsDouble = Double.parseDouble(val); - Double valueAsDouble = new Double(val); - - float valueAsFloat = valueAsDouble.floatValue(); - - if (this.connection.getJdbcCompliantTruncationForReads() && - valueAsFloat == Float.NEGATIVE_INFINITY || - valueAsFloat == Float.POSITIVE_INFINITY) { - throwRangeException(valueAsDouble.toString(), - columnIndex, Types.FLOAT); - } + // Straight comparison is not reliable when at + // absolute endpoints of Float.MIN_VALUE or + // Float.MAX_VALUE, so use epsillons with DOUBLEs + + if ((valAsDouble < Float.MIN_VALUE - MIN_DIFF_PREC) + || (valAsDouble > Float.MAX_VALUE - MAX_DIFF_PREC)) { + throwRangeException(String.valueOf(valAsDouble), columnIndex, + Types.FLOAT); + } } } Modified: branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java =================================================================== --- branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-07-18 16:49:10 UTC (rev 5525) +++ branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-07-18 18:01:22 UTC (rev 5526) @@ -3447,4 +3447,21 @@ assertEquals(4095, this.rs.getLong(3)); } } + + /** + * Tests fix for BUG#18880 - ResultSet.getFloatFromString() can't retrieve + * values near Float.MIN/MAX_VALUE. + * + * @throws Exception if the test fails. + */ + public void testBug18880() throws Exception { + try { + this.rs = this.stmt.executeQuery("SELECT 3.4E38,1.4E-45"); + this.rs.next(); + this.rs.getFloat(1); + this.rs.getFloat(2); + } finally { + closeMemberJDBCResources(); + } + } } Modified: branches/branch_5_1/connector-j/CHANGES =================================================================== --- branches/branch_5_1/connector-j/CHANGES 2006-07-18 16:49:10 UTC (rev 5525) +++ branches/branch_5_1/connector-j/CHANGES 2006-07-18 18:01:22 UTC (rev 5526) @@ -163,7 +163,12 @@ - Fixed BUG#20687 - Can't pool server-side prepared statements, exception raised when re-using them. - + + - Fixed BUG#21062 - ResultSet.getSomeInteger() doesn't work for BIT(>1). + + - Fixed BUG#18880 - ResultSet.getFloatFromString() can't retrieve + values near Float.MIN/MAX_VALUE. + 05-26-06 - Version 3.1.13 - Fixed BUG#15464 - INOUT parameter does not store IN value. Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/ResultSet.java =================================================================== --- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-07-18 16:49:10 UTC (rev 5525) +++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-07-18 18:01:22 UTC (rev 5526) @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2004 MySQL AB + Copyright (C) 2002-2006 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as @@ -121,6 +121,19 @@ * @see java.sql.ResultSet */ public class ResultSet implements java.sql.ResultSet { + + /** + * Epsillon between Float.MIN_VALUE and the double representation of said value. + */ + protected static final double MIN_DIFF_PREC = Float.parseFloat(Float.toString(Float.MIN_VALUE)) + - Double.parseDouble(Float.toString(Float.MIN_VALUE)); + + /** + * Epsillon between Float.MAX_VALUE and the double representation of said value. + */ + protected static final double MAX_DIFF_PREC = Float.parseFloat(Float.toString(Float.MAX_VALUE)) + - Double.parseDouble(Float.toString(Float.MAX_VALUE)); + /** Counter used to generate IDs for profiling. */ protected static int resultCounter = 1; @@ -2309,15 +2322,19 @@ float f = Float.parseFloat(val); - if (this.connection.getJdbcCompliantTruncation()) { + if (this.connection.getJdbcCompliantTruncationForReads()) { if (f == Float.MIN_VALUE || f == Float.MAX_VALUE) { double valAsDouble = Double.parseDouble(val); - if (valAsDouble < Float.MIN_VALUE - || valAsDouble > Float.MAX_VALUE) { - throwRangeException(String.valueOf(valAsDouble), - columnIndex, Types.FLOAT); - } + // Straight comparison is not reliable when at + // absolute endpoints of Float.MIN_VALUE or + // Float.MAX_VALUE, so use epsillons with DOUBLEs + + if ((valAsDouble < Float.MIN_VALUE - MIN_DIFF_PREC) + || (valAsDouble > Float.MAX_VALUE - MAX_DIFF_PREC)) { + throwRangeException(String.valueOf(valAsDouble), columnIndex, + Types.FLOAT); + } } } Modified: branches/branch_5_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java =================================================================== --- branches/branch_5_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-07-18 16:49:10 UTC (rev 5525) +++ branches/branch_5_1/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2006-07-18 18:01:22 UTC (rev 5526) @@ -3113,4 +3113,53 @@ assertEquals(133.0, this.rs.getDouble(2), 0); assertEquals(133, this.rs.getBigDecimal(2).intValue()); } + + /** + * Tests fix for BUG#21062 - ResultSet.getSomeInteger() doesn't work for BIT(>1) + * + * @throws Exception if the test fails. + */ + public void testBug21062() throws Exception { + if (versionMeetsMinimum(5, 0, 5)) { + createTable("testBug21062", "(bit_7_field BIT(7), bit_31_field BIT(31), bit_12_field BIT(12))"); + + int max7Bits = 127; + long max31Bits = 2147483647L; + int max12Bits = 4095; + + this.stmt.executeUpdate("INSERT INTO testBug21062 VALUES (" + max7Bits + "," + max31Bits + "," + max12Bits + ")"); + + this.rs = this.stmt.executeQuery("SELECT * FROM testBug21062"); + + this.rs.next(); + + assertEquals(127, this.rs.getInt(1)); + assertEquals(127, this.rs.getShort(1)); + assertEquals(127, this.rs.getLong(1)); + + assertEquals(2147483647, this.rs.getInt(2)); + assertEquals(2147483647, this.rs.getLong(2)); + + assertEquals(4095, this.rs.getInt(3)); + assertEquals(4095, this.rs.getShort(3)); + assertEquals(4095, this.rs.getLong(3)); + } + } + + /** + * Tests fix for BUG#18880 - ResultSet.getFloatFromString() can't retrieve + * values near Float.MIN/MAX_VALUE. + * + * @throws Exception if the test fails. + */ + public void testBug18880() throws Exception { + try { + this.rs = this.stmt.executeQuery("SELECT 3.4E38,1.4E-45"); + this.rs.next(); + this.rs.getFloat(1); + this.rs.getFloat(2); + } finally { + closeMemberJDBCResources(); + } + } }