Commit 89a4a3e9 authored by unknown's avatar unknown

Fix for bug #22029: str_to_date returning NULL, while date_format works using identical format.

The problem appears when we have a space followed by a non-format symbol.

Fix: properly skip spaces.


mysql-test/r/date_formats.result:
  Fix for bug #22029: str_to_date returning NULL, while date_format works using identical format.
    - test result.
mysql-test/t/date_formats.test:
  Fix for bug #22029: str_to_date returning NULL, while date_format works using identical format.
    - test case.
sql/item_timefunc.cc:
  Fix for bug #22029: str_to_date returning NULL, while date_format works using identical format.
    - skipping pre-spaces between each argument moved.
parent 78f47b1b
...@@ -530,4 +530,13 @@ DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896) ...@@ -530,4 +530,13 @@ DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896)
NULL NULL
Warnings: Warnings:
Warning 1292 Truncated incorrect datetime value: '%Y-%m-%d %H:%i:%s' Warning 1292 Truncated incorrect datetime value: '%Y-%m-%d %H:%i:%s'
select str_to_date('04 /30/2004', '%m /%d/%Y');
str_to_date('04 /30/2004', '%m /%d/%Y')
2004-04-30
select str_to_date('04/30 /2004', '%m /%d /%Y');
str_to_date('04/30 /2004', '%m /%d /%Y')
2004-04-30
select str_to_date('04/30/2004 ', '%m/%d/%Y ');
str_to_date('04/30/2004 ', '%m/%d/%Y ')
2004-04-30
"End of 4.1 tests" "End of 4.1 tests"
...@@ -317,4 +317,12 @@ SELECT TIME_FORMAT("25:00:00", '%l %p'); ...@@ -317,4 +317,12 @@ SELECT TIME_FORMAT("25:00:00", '%l %p');
# #
SELECT DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896); SELECT DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896);
#
# Bug #22029: str_to_date returning NULL
#
select str_to_date('04 /30/2004', '%m /%d/%Y');
select str_to_date('04/30 /2004', '%m /%d /%Y');
select str_to_date('04/30/2004 ', '%m/%d/%Y ');
--echo "End of 4.1 tests" --echo "End of 4.1 tests"
...@@ -171,15 +171,15 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, ...@@ -171,15 +171,15 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
for (; ptr != end && val != val_end; ptr++) for (; ptr != end && val != val_end; ptr++)
{ {
/* Skip pre-space between each argument */
while (val != val_end && my_isspace(cs, *val))
val++;
if (*ptr == '%' && ptr+1 != end) if (*ptr == '%' && ptr+1 != end)
{ {
int val_len; int val_len;
char *tmp; char *tmp;
/* Skip pre-space between each argument */
while (val != val_end && my_isspace(cs, *val))
val++;
val_len= (uint) (val_end - val); val_len= (uint) (val_end - val);
switch (*++ptr) { switch (*++ptr) {
/* Year */ /* Year */
......
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