Loading include/my_time.h +3 −2 Original line number Diff line number Diff line Loading @@ -58,14 +58,15 @@ void init_time(void); my_time_t my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, bool *in_dst_time_gap); void set_zero_time(MYSQL_TIME *tm); void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type); /* Required buffer length for my_time_to_str, my_date_to_str, my_datetime_to_str and TIME_to_string functions. Note, that the caller is still responsible to check that given TIME structure has values in valid ranges, otherwise size of the buffer could be not enough. be not enough. We also rely on the fact that even wrong values sent using binary protocol fit in this buffer. */ #define MAX_DATE_STRING_REP_LENGTH 30 Loading include/mysql_time.h +12 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,18 @@ enum enum_mysql_timestamp_type }; /* Structure which is used to represent datetime values inside MySQL. We assume that values in this structure are normalized, i.e. year <= 9999, month <= 12, day <= 31, hour <= 23, hour <= 59, hour <= 59. Many functions in server such as my_system_gmt_sec() or make_time() family of functions rely on this (actually now usage of make_*() family relies on a bit weaker restriction). Also functions that produce MYSQL_TIME as result ensure this. There is one exception to this rule though if this structure holds time value (time_type == MYSQL_TIMESTAMP_TIME) days and hour member can hold bigger values. */ typedef struct st_mysql_time { unsigned int year, month, day, hour, minute, second; Loading libmysql/libmysql.c +7 −6 Original line number Diff line number Diff line Loading @@ -3257,11 +3257,12 @@ static void read_binary_time(MYSQL_TIME *tm, uchar **pos) tm->hour+= tm->day*24; tm->day= 0; } tm->time_type= MYSQL_TIMESTAMP_TIME; *pos+= length; } else set_zero_time(tm); tm->time_type= MYSQL_TIMESTAMP_TIME; set_zero_time(tm, MYSQL_TIMESTAMP_TIME); } static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos) Loading @@ -3286,12 +3287,12 @@ static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos) else tm->hour= tm->minute= tm->second= 0; tm->second_part= (length > 7) ? (ulong) sint4korr(to+7) : 0; tm->time_type= MYSQL_TIMESTAMP_DATETIME; *pos+= length; } else set_zero_time(tm); tm->time_type= MYSQL_TIMESTAMP_DATETIME; set_zero_time(tm, MYSQL_TIMESTAMP_DATETIME); } static void read_binary_date(MYSQL_TIME *tm, uchar **pos) Loading @@ -3308,12 +3309,12 @@ static void read_binary_date(MYSQL_TIME *tm, uchar **pos) tm->hour= tm->minute= tm->second= 0; tm->second_part= 0; tm->neg= 0; tm->time_type= MYSQL_TIMESTAMP_DATE; *pos+= length; } else set_zero_time(tm); tm->time_type= MYSQL_TIMESTAMP_DATE; set_zero_time(tm, MYSQL_TIMESTAMP_DATE); } Loading mysql-test/r/type_datetime.result +9 −2 Original line number Diff line number Diff line Loading @@ -97,13 +97,15 @@ select * from t1 where a is null or b is null; a b drop table t1; create table t1 (t datetime); insert into t1 values (20030102030460),(20030102036301),(20030102240401),(20030132030401),(20031302030460); insert into t1 values (20030102030460),(20030102036301),(20030102240401), (20030132030401),(20031302030401),(100001202030401); Warnings: Warning 1265 Data truncated for column 't' at row 1 Warning 1265 Data truncated for column 't' at row 2 Warning 1265 Data truncated for column 't' at row 3 Warning 1265 Data truncated for column 't' at row 4 Warning 1265 Data truncated for column 't' at row 5 Warning 1265 Data truncated for column 't' at row 6 select * from t1; t 0000-00-00 00:00:00 Loading @@ -111,14 +113,18 @@ t 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 delete from t1; insert into t1 values ("20030102030460"),("20030102036301"),("20030102240401"),("20030132030401"),("20031302030460"); insert into t1 values ("2003-01-02 03:04:60"),("2003-01-02 03:63:01"),("2003-01-02 24:04:01"), ("2003-01-32 03:04:01"),("2003-13-02 03:04:01"), ("10000-12-02 03:04:00"); Warnings: Warning 1264 Data truncated; out of range for column 't' at row 1 Warning 1264 Data truncated; out of range for column 't' at row 2 Warning 1264 Data truncated; out of range for column 't' at row 3 Warning 1264 Data truncated; out of range for column 't' at row 4 Warning 1264 Data truncated; out of range for column 't' at row 5 Warning 1264 Data truncated; out of range for column 't' at row 6 select * from t1; t 0000-00-00 00:00:00 Loading @@ -126,6 +132,7 @@ t 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 delete from t1; insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer"); Warnings: Loading mysql-test/t/type_datetime.test +5 −2 Original line number Diff line number Diff line Loading @@ -77,10 +77,13 @@ drop table t1; # warnings (for both strings and numbers) # create table t1 (t datetime); insert into t1 values (20030102030460),(20030102036301),(20030102240401),(20030132030401),(20031302030460); insert into t1 values (20030102030460),(20030102036301),(20030102240401), (20030132030401),(20031302030401),(100001202030401); select * from t1; delete from t1; insert into t1 values ("20030102030460"),("20030102036301"),("20030102240401"),("20030132030401"),("20031302030460"); insert into t1 values ("2003-01-02 03:04:60"),("2003-01-02 03:63:01"),("2003-01-02 24:04:01"), ("2003-01-32 03:04:01"),("2003-13-02 03:04:01"), ("10000-12-02 03:04:00"); select * from t1; delete from t1; insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer"); Loading Loading
include/my_time.h +3 −2 Original line number Diff line number Diff line Loading @@ -58,14 +58,15 @@ void init_time(void); my_time_t my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, bool *in_dst_time_gap); void set_zero_time(MYSQL_TIME *tm); void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type); /* Required buffer length for my_time_to_str, my_date_to_str, my_datetime_to_str and TIME_to_string functions. Note, that the caller is still responsible to check that given TIME structure has values in valid ranges, otherwise size of the buffer could be not enough. be not enough. We also rely on the fact that even wrong values sent using binary protocol fit in this buffer. */ #define MAX_DATE_STRING_REP_LENGTH 30 Loading
include/mysql_time.h +12 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,18 @@ enum enum_mysql_timestamp_type }; /* Structure which is used to represent datetime values inside MySQL. We assume that values in this structure are normalized, i.e. year <= 9999, month <= 12, day <= 31, hour <= 23, hour <= 59, hour <= 59. Many functions in server such as my_system_gmt_sec() or make_time() family of functions rely on this (actually now usage of make_*() family relies on a bit weaker restriction). Also functions that produce MYSQL_TIME as result ensure this. There is one exception to this rule though if this structure holds time value (time_type == MYSQL_TIMESTAMP_TIME) days and hour member can hold bigger values. */ typedef struct st_mysql_time { unsigned int year, month, day, hour, minute, second; Loading
libmysql/libmysql.c +7 −6 Original line number Diff line number Diff line Loading @@ -3257,11 +3257,12 @@ static void read_binary_time(MYSQL_TIME *tm, uchar **pos) tm->hour+= tm->day*24; tm->day= 0; } tm->time_type= MYSQL_TIMESTAMP_TIME; *pos+= length; } else set_zero_time(tm); tm->time_type= MYSQL_TIMESTAMP_TIME; set_zero_time(tm, MYSQL_TIMESTAMP_TIME); } static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos) Loading @@ -3286,12 +3287,12 @@ static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos) else tm->hour= tm->minute= tm->second= 0; tm->second_part= (length > 7) ? (ulong) sint4korr(to+7) : 0; tm->time_type= MYSQL_TIMESTAMP_DATETIME; *pos+= length; } else set_zero_time(tm); tm->time_type= MYSQL_TIMESTAMP_DATETIME; set_zero_time(tm, MYSQL_TIMESTAMP_DATETIME); } static void read_binary_date(MYSQL_TIME *tm, uchar **pos) Loading @@ -3308,12 +3309,12 @@ static void read_binary_date(MYSQL_TIME *tm, uchar **pos) tm->hour= tm->minute= tm->second= 0; tm->second_part= 0; tm->neg= 0; tm->time_type= MYSQL_TIMESTAMP_DATE; *pos+= length; } else set_zero_time(tm); tm->time_type= MYSQL_TIMESTAMP_DATE; set_zero_time(tm, MYSQL_TIMESTAMP_DATE); } Loading
mysql-test/r/type_datetime.result +9 −2 Original line number Diff line number Diff line Loading @@ -97,13 +97,15 @@ select * from t1 where a is null or b is null; a b drop table t1; create table t1 (t datetime); insert into t1 values (20030102030460),(20030102036301),(20030102240401),(20030132030401),(20031302030460); insert into t1 values (20030102030460),(20030102036301),(20030102240401), (20030132030401),(20031302030401),(100001202030401); Warnings: Warning 1265 Data truncated for column 't' at row 1 Warning 1265 Data truncated for column 't' at row 2 Warning 1265 Data truncated for column 't' at row 3 Warning 1265 Data truncated for column 't' at row 4 Warning 1265 Data truncated for column 't' at row 5 Warning 1265 Data truncated for column 't' at row 6 select * from t1; t 0000-00-00 00:00:00 Loading @@ -111,14 +113,18 @@ t 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 delete from t1; insert into t1 values ("20030102030460"),("20030102036301"),("20030102240401"),("20030132030401"),("20031302030460"); insert into t1 values ("2003-01-02 03:04:60"),("2003-01-02 03:63:01"),("2003-01-02 24:04:01"), ("2003-01-32 03:04:01"),("2003-13-02 03:04:01"), ("10000-12-02 03:04:00"); Warnings: Warning 1264 Data truncated; out of range for column 't' at row 1 Warning 1264 Data truncated; out of range for column 't' at row 2 Warning 1264 Data truncated; out of range for column 't' at row 3 Warning 1264 Data truncated; out of range for column 't' at row 4 Warning 1264 Data truncated; out of range for column 't' at row 5 Warning 1264 Data truncated; out of range for column 't' at row 6 select * from t1; t 0000-00-00 00:00:00 Loading @@ -126,6 +132,7 @@ t 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 delete from t1; insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer"); Warnings: Loading
mysql-test/t/type_datetime.test +5 −2 Original line number Diff line number Diff line Loading @@ -77,10 +77,13 @@ drop table t1; # warnings (for both strings and numbers) # create table t1 (t datetime); insert into t1 values (20030102030460),(20030102036301),(20030102240401),(20030132030401),(20031302030460); insert into t1 values (20030102030460),(20030102036301),(20030102240401), (20030132030401),(20031302030401),(100001202030401); select * from t1; delete from t1; insert into t1 values ("20030102030460"),("20030102036301"),("20030102240401"),("20030132030401"),("20031302030460"); insert into t1 values ("2003-01-02 03:04:60"),("2003-01-02 03:63:01"),("2003-01-02 24:04:01"), ("2003-01-32 03:04:01"),("2003-13-02 03:04:01"), ("10000-12-02 03:04:00"); select * from t1; delete from t1; insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer"); Loading