Commit 015165ad authored by unknown's avatar unknown

Fix parsing of dates with 'T' between date and time, as in ISO-8601

date format. (Bug #7308)


mysql-test/r/type_datetime.result:
  Add new results
mysql-test/t/type_datetime.test:
  Add new test
sql-common/my_time.c:
  Fix handling of field_length for each field in date, especially
  for dates not in the internal_format.
parent 3202508b
...@@ -153,3 +153,13 @@ dt ...@@ -153,3 +153,13 @@ dt
0000-00-00 00:00:00 0000-00-00 00:00:00
0000-00-00 00:00:00 0000-00-00 00:00:00
drop table t1; drop table t1;
create table t1 (dt datetime);
insert into t1 values ("20010101T010101");
insert into t1 values ("2001-01-01T01:01:01");
insert into t1 values ("2001-1-1T1:01:01");
select * from t1;
dt
2001-01-01 01:01:01
2001-01-01 01:01:01
2001-01-01 01:01:01
drop table t1;
...@@ -102,4 +102,14 @@ insert into t1 values ("00-00-00"), ("00-00-00 00:00:00"); ...@@ -102,4 +102,14 @@ insert into t1 values ("00-00-00"), ("00-00-00 00:00:00");
select * from t1; select * from t1;
drop table t1; drop table t1;
#
# Bug #7308: ISO-8601 date format not handled correctly
#
create table t1 (dt datetime);
insert into t1 values ("20010101T010101");
insert into t1 values ("2001-01-01T01:01:01");
insert into t1 values ("2001-1-1T1:01:01");
select * from t1;
drop table t1;
# End of 4.1 tests # End of 4.1 tests
...@@ -147,7 +147,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, ...@@ -147,7 +147,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
{ {
/* Found date in internal format (only numbers like YYYYMMDD) */ /* Found date in internal format (only numbers like YYYYMMDD) */
year_length= (digits == 4 || digits == 8 || digits >= 14) ? 4 : 2; year_length= (digits == 4 || digits == 8 || digits >= 14) ? 4 : 2;
field_length=year_length-1; field_length= year_length;
is_internal_format= 1; is_internal_format= 1;
format_position= internal_format_positions; format_position= internal_format_positions;
} }
...@@ -177,6 +177,8 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, ...@@ -177,6 +177,8 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
start_loop= 5; /* Start with first date part */ start_loop= 5; /* Start with first date part */
} }
} }
field_length= format_position[0] == 0 ? 4 : 2;
} }
/* /*
...@@ -201,7 +203,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, ...@@ -201,7 +203,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
const char *start= str; const char *start= str;
ulong tmp_value= (uint) (uchar) (*str++ - '0'); ulong tmp_value= (uint) (uchar) (*str++ - '0');
while (str != end && my_isdigit(&my_charset_latin1,str[0]) && while (str != end && my_isdigit(&my_charset_latin1,str[0]) &&
(!is_internal_format || field_length--)) --field_length)
{ {
tmp_value=tmp_value*10 + (ulong) (uchar) (*str - '0'); tmp_value=tmp_value*10 + (ulong) (uchar) (*str - '0');
str++; str++;
...@@ -215,8 +217,8 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, ...@@ -215,8 +217,8 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
date[i]=tmp_value; date[i]=tmp_value;
not_zero_date|= tmp_value; not_zero_date|= tmp_value;
/* Length-1 of next field */ /* Length of next field */
field_length= format_position[i+1] == 0 ? 3 : 1; field_length= format_position[i+1] == 0 ? 4 : 2;
if ((last_field_pos= str) == end) if ((last_field_pos= str) == end)
{ {
...@@ -234,7 +236,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, ...@@ -234,7 +236,7 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
if (*str == '.') /* Followed by part seconds */ if (*str == '.') /* Followed by part seconds */
{ {
str++; str++;
field_length= 5; /* 5 digits after first (=6) */ field_length= 6; /* 6 digits */
} }
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment