Commit a7088b3c authored by unknown's avatar unknown

Bug #20987: str_to_date doesn't accept user variable for specification

str_to_date() would sometimes render NULL if %D was used as rule other than last.
since this was due to two pointers getting mixed up in the server, this behaviour
seemed somewhat non-deterministic at SQL level.


mysql-test/r/func_time.result:
  Bug #20987: str_to_date doesn't accept user variable for specification
  
  show we can do the usual str_to_date() conversions without triggering the bug.
mysql-test/t/func_time.test:
  Bug #20987: str_to_date doesn't accept user variable for specification
  
  show we can do the usual str_to_date() conversions without triggering the bug.
sql/item_timefunc.cc:
  Bug #20987: str_to_date doesn't accept user variable for specification
  
  str_to_date() used a wrong pointer in %D conversions which could lead to the
  input being cut off after the token matching %D; if the rule required further
  tokens, the conversion would fail and render NULL.
parent d2aa274a
......@@ -695,3 +695,37 @@ t1 CREATE TABLE `t1` (
`from_unixtime(1) + 0` double(23,6) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
SET @df:="%M %D, %Y";
SELECT DATE_FORMAT('2005-10-31', "%M %D, %Y");
DATE_FORMAT('2005-10-31', "%M %D, %Y")
October 31st, 2005
SELECT DATE_FORMAT('2005-10-31', @df);
DATE_FORMAT('2005-10-31', @df)
October 31st, 2005
SELECT STR_TO_DATE('October 31st, 2005', "%M %D, %Y");
STR_TO_DATE('October 31st, 2005', "%M %D, %Y")
2005-10-31
SELECT STR_TO_DATE('October 31st, 2005', @df);
STR_TO_DATE('October 31st, 2005', @df)
2005-10-31
CREATE TABLE `dt` (
d datetime,
ds char(30)
);
INSERT INTO `dt` (d) VALUES ('2005-10-31'), ('2005-11-30');
SET @df:="%M %D, %Y";
UPDATE dt SET ds = DATE_FORMAT(d, @df);
SELECT * FROM dt;
d ds
2005-10-31 00:00:00 October 31st, 2005
2005-11-30 00:00:00 November 30th, 2005
SELECT d, ds, STR_TO_DATE(ds, @df) FROM dt;
d ds STR_TO_DATE(ds, @df)
2005-10-31 00:00:00 October 31st, 2005 2005-10-31
2005-11-30 00:00:00 November 30th, 2005 2005-11-30
SELECT d, ds, STR_TO_DATE(ds, "%M %D, %Y") FROM dt;
d ds STR_TO_DATE(ds, "%M %D, %Y")
2005-10-31 00:00:00 October 31st, 2005 2005-10-31
2005-11-30 00:00:00 November 30th, 2005 2005-11-30
DROP TABLE `dt`;
End of 4.1 tests
......@@ -368,4 +368,34 @@ create table t1 select now() - now(), curtime() - curtime(),
show create table t1;
drop table t1;
# End of 4.1 tests
#
# Bug #20987: str_to_date doesn't accept user variable for specification
#
SET @df:="%M %D, %Y";
SELECT DATE_FORMAT('2005-10-31', "%M %D, %Y");
SELECT DATE_FORMAT('2005-10-31', @df);
SELECT STR_TO_DATE('October 31st, 2005', "%M %D, %Y");
SELECT STR_TO_DATE('October 31st, 2005', @df);
CREATE TABLE `dt` (
d datetime,
ds char(30)
);
INSERT INTO `dt` (d) VALUES ('2005-10-31'), ('2005-11-30');
SET @df:="%M %D, %Y";
UPDATE dt SET ds = DATE_FORMAT(d, @df);
SELECT * FROM dt;
SELECT d, ds, STR_TO_DATE(ds, @df) FROM dt;
SELECT d, ds, STR_TO_DATE(ds, "%M %D, %Y") FROM dt;
DROP TABLE `dt`;
--echo End of 4.1 tests
......@@ -223,7 +223,7 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
tmp= (char*) val + min(2, val_len);
l_time->day= (int) my_strtoll10(val, &tmp, &error);
/* Skip 'st, 'nd, 'th .. */
val= tmp + min((int) (end-tmp), 2);
val= tmp + min((int) (val_end-tmp), 2);
break;
/* Hour */
......
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