From: Date: March 28 2005 9:36pm Subject: bk commit into 4.0 tree (dlenev:1.2077) BUG#8894 List-Archive: http://lists.mysql.com/internals/23417 X-Bug: 8894 Message-Id: <20050328193628.3EB151379C4@brandersnatch.localdomain> Below is the list of changes that have just been committed into a local 4.0 repository of dlenev. When dlenev does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2077 05/03/28 23:36:25 dlenev@stripped +4 -0 Fix for bug #8894 "TIMESTAMP values scrambled/misaligned when using --new". Fixed Field_timestamp::val_int() so now it works correctly in --new mode (or for TIMESTAMP(19) columns). Also removed unused Field_timestamp::fill_and_store() method. sql/field.h 1.60 05/03/28 23:36:22 dlenev@stripped +0 -1 Removed unused Field_timestamp::fill_and_store() method. sql/field.cc 1.96 05/03/28 23:36:22 dlenev@stripped +4 -31 Field_timestamp::fill_and_store() Removed unused method. Field_timestamp::val_int() Even in --new mode integer representation of TIMESTAMP value should not exceed 14 digits. mysql-test/t/type_timestamp.test 1.13 05/03/28 23:36:22 dlenev@stripped +13 -0 Added test for bug #8894 "TIMESTAMP values scrambled/misaligned when using --new". mysql-test/r/type_timestamp.result 1.15 05/03/28 23:36:22 dlenev@stripped +9 -0 Added test for bug #8894 "TIMESTAMP values scrambled/misaligned when using --new". # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: dlenev # Host: brandersnatch.localdomain # Root: /home/dlenev/src/mysql-4.0-bg8894 --- 1.95/sql/field.cc Mon Sep 27 00:49:58 2004 +++ 1.96/sql/field.cc Mon Mar 28 23:36:22 2005 @@ -2505,34 +2505,6 @@ longstore(ptr,tmp); } -void Field_timestamp::fill_and_store(char *from,uint len) -{ - uint res_length; - if (len <= field_length) - res_length=field_length; - else if (len <= 12) - res_length=12; /* purecov: inspected */ - else if (len <= 14) - res_length=14; /* purecov: inspected */ - else - res_length=(len+1)/2*2; // must be even - if (res_length != len) - { - bmove_upp(from+res_length,from+len,len); - bfill(from,res_length-len,'0'); - len=res_length; - } - long tmp=(long) str_to_timestamp(from,len); -#ifdef WORDS_BIGENDIAN - if (table->db_low_byte_first) - { - int4store(ptr,tmp); - } - else -#endif - longstore(ptr,tmp); -} - void Field_timestamp::store(double nr) { @@ -2644,7 +2616,7 @@ longlong Field_timestamp::val_int(void) { - uint len,pos; + uint len, pos, max_int_rep_len; int part_time; uint32 temp; time_t time_arg; @@ -2665,7 +2637,8 @@ localtime_r(&time_arg,&tm_tmp); l_time=&tm_tmp; res=(longlong) 0; - for (pos=len=0; len+1 < (uint) field_length ; len+=2,pos++) + max_int_rep_len= min(field_length, 14); + for (pos= len= 0; len+1 < max_int_rep_len ; len+= 2,pos++) { bool year_flag=0; switch (dayord.pos[pos]) { @@ -2677,7 +2650,7 @@ case 5: part_time=l_time->tm_sec; break; default: part_time=0; break; /* purecov: deadcode */ } - if (year_flag && (field_length == 8 || field_length == 14)) + if (year_flag && (max_int_rep_len == 8 || max_int_rep_len == 14)) { res=res*(longlong) 10000+(part_time+ ((part_time < YY_PART_YEAR) ? 2000 : 1900)); --- 1.59/sql/field.h Tue Jan 18 17:04:14 2005 +++ 1.60/sql/field.h Mon Mar 28 23:36:22 2005 @@ -591,7 +591,6 @@ longget(tmp,ptr); return tmp; } - void fill_and_store(char *from,uint len); bool get_date(TIME *ltime,bool fuzzydate); bool get_time(TIME *ltime); --- 1.14/mysql-test/r/type_timestamp.result Mon Sep 27 00:49:58 2004 +++ 1.15/mysql-test/r/type_timestamp.result Mon Mar 28 23:36:22 2005 @@ -221,3 +221,12 @@ 20040101000000 20040101010000 drop table t1; +create table t1 (ts timestamp); +set TIMESTAMP=1000000000; +insert into t1 values (); +set new=1; +select ts+0 from t1; +ts+0 +20010909044640 +set new=0; +drop table t1; --- 1.12/mysql-test/t/type_timestamp.test Mon Sep 27 00:49:58 2004 +++ 1.13/mysql-test/t/type_timestamp.test Mon Mar 28 23:36:22 2005 @@ -148,3 +148,16 @@ set new=0; select * from t1; drop table t1; + +# +# Test for bug #8894 "TIMESTAMP values scrambled/misaligned when using +# --new". TIMESTAMP columns should have correct values when they are used in +# integer context in --new mode. +# +create table t1 (ts timestamp); +set TIMESTAMP=1000000000; +insert into t1 values (); +set new=1; +select ts+0 from t1; +set new=0; +drop table t1;