Kevin Lloyd wrote:
> I'm having a problem with 'data truncation' and
> timestamp fields.
>
> The fields in question have a default value of
> CURRENT_TIMESTAMP. It appears the drivers are
> attempting to insert this value into the database
> when I use the ResultSet.insertRow() method (and
> the field isn't actually updated). When they do,
> I get the (new) data truncation
> warning/exception.
>
> I've managed to replicate the issue by calling
> updateString("CURRENT_TIMESTAMP") on the field.
>
> Am I missing some driver or database option here?
>
> Kevin Lloyd
>
> MySQL 4.1.10
> MySQL-AB JDBC Driver mysql-connector-java-3.1.7
It seems the issue is that the driver can't distinguish from the information given by the server the difference between CURRENT_TIMESTAMP and 'CURRENT_TIMESTAMP', so it sends 'CURRENT_TIMESTAMP'...We'll have to add a fix to look if the default value is CURRENT_TIMESTAMP and the column is a timestamp type, and if so, not send it as a string:
mysql> create table tsFoo(field1 TIMESTAMP NOT NULL, field2 VARCHAR(32) DEFAULT 'abcd');
Query OK, 0 rows affected (0.01 sec)
mysql> show columns from tsFoo;
+--------+-------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+-------------------+-------+
| field1 | timestamp | YES | | CURRENT_TIMESTAMP | |
| field2 | varchar(32) | YES | | abcd | |
+--------+-------------+------+-----+-------------------+-------+
2 rows in set (0.00 sec)
mysql>
We'll put a workaround in 3.1.8, but I filed this as a server bug:
http://bugs.mysql.com/bug.php?id=9098
-Mark
Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools
Oracle
http://www.mysql.com/products/enterprise/monitor.html