Bug #22774 | Incorrectly reported data truncation with server prepared statements | ||
---|---|---|---|
Submitted: | 28 Sep 2006 10:24 | Modified: | 22 Jan 2014 20:02 |
Reporter: | Alexander Hristov (Candidate Quality Contributor) | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Prepared statements | Severity: | S2 (Serious) |
Version: | 5.0.24a | OS: | Linux (Fedora Core 5 and Windows XP) |
Assigned to: | CPU Architecture: | Any | |
Tags: | data truncation, decimal, floating, numeric, prepared statement |
[28 Sep 2006 10:24]
Alexander Hristov
[28 Sep 2006 12:07]
Alexander Hristov
Fixed category from "Server" to the more specific "Prepared Statements"
[28 Sep 2006 12:34]
Valeriy Kravchuk
Thank you for a preoblem report. I was not able to repeat the behaviour described with 5.0.26-BK on Linux using mysql comand line client, as follows: mysql> Create table foo (cost decimal(6,2) NOT NULL) ENGINE=InnoDB DEFAULT CHAR SET=utf8; Query OK, 0 rows affected (0.08 sec) mysql> prepare stmt from 'insert into foo values(?)'; Query OK, 0 rows affected (0.02 sec) Statement prepared mysql> set @@sql_mode=strict_trans_tables; Query OK, 0 rows affected (0.01 sec) mysql> set @a=-855.2; Query OK, 0 rows affected (0.02 sec) mysql> set @b=8517.45; Query OK, 0 rows affected (0.00 sec) mysql> execute stmt using @a; Query OK, 1 row affected (0.00 sec) mysql> execute stmt using @b; Query OK, 1 row affected (0.00 sec) mysql> select * from foo; +---------+ | cost | +---------+ | -855.20 | | 8517.45 | | -855.20 | | 8517.45 | +---------+ 4 rows in set (0.01 sec) Please, run this test and inform about the results.
[28 Sep 2006 19:13]
Alexander Hristov
Works fine, and SHOW WARNINGS doesn't report any data truncation after each of the executes
[29 Sep 2006 8:00]
Valeriy Kravchuk
OK. Do you have a complete C API (or Connector/J) test case that demonstrates this behaviour?
[29 Sep 2006 8:24]
Alexander Hristov
Yes, but the Connector/J couldn't reproduce the bug. Here it is, anyway: import java.sql.*; import java.util.Properties; public class Test { public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Properties p = new Properties(); p.setProperty("user","..."); p.setProperty("password","..."); p.setProperty("useServerPrepStmts","true"); Connection con = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/test",p); Statement sql = con.createStatement(); sql.executeUpdate("drop table if exists foo "); sql.executeUpdate("Create table foo (`cost` decimal(6,2) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8"); double value= 8517.42; PreparedStatement ps = con.prepareStatement("insert into foo values (?)"); ps.setDouble(1,value); ps.executeUpdate(); } }
[29 Sep 2006 8:25]
Alexander Hristov
In the comment above, I meant to say that "the Connector/J _team_ couldn't reproduce the bug". In my setup fails always, on both platforms.
[29 Sep 2006 8:27]
Alexander Hristov
Sorry, the line above should be double value= 8517.45; as for double value= 8517.42; it doesn't fail. I forgot that I had been making some aditional tests.
[17 Oct 2006 20:17]
Alexander Hristov
Hi. I've downloaded and compiled for Windows the mysql-5.0.27-nightly-20061009 version, and it fails on it too. If I can do anything to help you track the bug, now that I have a compilable version with source which exhibits this behaviour, don't hesitate to ask.
[20 Oct 2006 10:47]
Alexander Hristov
Hi Valeriy. I believe this bug is *in essence* unfixable. Please see the results of my investigations here http://www.ahristov.com/tutorial/Blog/MySQL-and-Data-Truncation-%3A-A-descent-into-IEEE-he... What *can* be fixed, however, is the way floats are compared in Field_new_decimal::store(double nr)
[25 Nov 2006 11:26]
Valeriy Kravchuk
Thank you for a great article, http://www.ahristov.com/tutorial/Blog/MySQL-and-Data-Truncation-%3A-A-descent-into-IEEE-he.... I think that string '8517.44' should be just converted to DECIMAL without float/double in the middle. See bug #23260 for a related discussion.