2 messages in com.mysql.lists.bugsTimestamp inadvertently modified when...
FromSent OnAttachments
Stephen Cuppett13 Jan 2002 20:11 
Sinisa Milivojevic14 Jan 2002 05:19 
Subject:Timestamp inadvertently modified when issuing update
From:Stephen Cuppett (scup@webmastersinc.org)
Date:01/13/2002 08:11:18 PM
List:com.mysql.lists.bugs

In this example I have constructed a very simple table which creates an error when running on MySQL servers 3.23.45 through 3.23.47. I haven't checked it on any earlier versions or 4.0. This problem appears to be platform independent. I have reproduced it on Mandrake Linux 8.1 running 3.23.46, WinNT 4.0 running 3.23.45 and 3.23.47 and WinXP running 3.23.47..

From the script below, you can see that I simply update an ENUM field and on every modified row in the query, the unmentioned timestamp field gets modified to Now() inadvertently regardless of it's previous value. I hope that what I have included is helpful, if you need anything else from me, just let me know. I also noticed that I declare the timestamp field as NULL, but then in the table description is isn't, but I'm not sure if it should or if that isn't a feature of timestamp fields.

Thank you,

Stephen Cuppett WebMasters, Inc. http://www.webmastersinc.org scup@webmastersinc.org

How-To-Repeat:

Run the commands from the sample script below on any table and you will receive the output identical to the one below if you redirect it to a file.

Sample Usage on a default installation: mysql test < sample.txt > output.txt

SAMPLE SCRIPT

--------------------------------------------------------------

CREATE TABLE timecards(timecardid BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, EmployeeID MEDIUMINT NOT NULL, DateEntered timestamp NOT NULL, Locked enum('N', 'Y') NOT NULL DEFAULT 'N'); DESCRIBE timecards; INSERT INTO timecards(employeeid, dateentered) VALUES (1, '2001-01-01'); select * from timecards; INSERT INTO timecards(employeeid, dateentered) VALUES (1, '2001-01-02'); select * from timecards; UPDATE timecards SET locked='Y' WHERE employeeid=1 AND timecardid!=2; select * from timecards;

OUTPUT

--------------------------------------------------------------

Field Type Null Key Default Extra timecardid bigint(20) PRI NULL auto_increment EmployeeID mediumint(9) 0 DateEntered timestamp(14) YES NULL Locked enum('N','Y') N timecardid EmployeeID DateEntered Locked 1 1 20010101000000 N timecardid EmployeeID DateEntered Locked 1 1 20010101000000 N 2 1 20010102000000 N timecardid EmployeeID DateEntered Locked 1 1 20020113181836 Y 2 1 20010102000000 N