From 2bd1c73e3db37b0dde4c7aed9a5ddff846fe610c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Oct 2006 16:00:44 +0500 Subject: [PATCH 1/5] Fix for bug #21789: DATETIME with 0000-00-00 11:22:33 should be invalid, but is accepted Reject '0000-00-00 01:01:01' dates. mysql-test/r/date_formats.result: Fix for bug #21789: DATETIME with 0000-00-00 11:22:33 should be invalid, but is accepted - test results adjusted. sql-common/my_time.c: Fix for bug #21789: DATETIME with 0000-00-00 11:22:33 should be invalid, but is accepted - don't allow dates with NULL date part and not NULL time part. --- mysql-test/r/date_formats.result | 57 ++++++++++++++++++++++---------- sql-common/my_time.c | 5 ++- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index 035d98d2b74..0baecb34583 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -181,12 +181,12 @@ date format datetime 2003-01-02 02:11:12.12345AM %Y-%m-%d %h:%i:%S.%f %p 2003-01-02 02:11:12.123450 2003-01-02 12:11:12.12345 am %Y-%m-%d %h:%i:%S.%f%p 2003-01-02 00:11:12.123450 2003-01-02 11:11:12Pm %Y-%m-%d %h:%i:%S%p 2003-01-02 23:11:12 -10:20:10 %H:%i:%s 0000-00-00 10:20:10 -10:20:10 %h:%i:%s.%f 0000-00-00 10:20:10 -10:20:10 %T 0000-00-00 10:20:10 -10:20:10AM %h:%i:%s%p 0000-00-00 10:20:10 -10:20:10AM %r 0000-00-00 10:20:10 -10:20:10.44AM %h:%i:%s.%f%p 0000-00-00 10:20:10.440000 +10:20:10 %H:%i:%s 0000-00-00 00:00:00 +10:20:10 %h:%i:%s.%f 0000-00-00 00:00:00 +10:20:10 %T 0000-00-00 00:00:00 +10:20:10AM %h:%i:%s%p 0000-00-00 00:00:00 +10:20:10AM %r 0000-00-00 00:00:00 +10:20:10.44AM %h:%i:%s.%f%p 0000-00-00 00:00:00 15-01-2001 12:59:58 %d-%m-%Y %H:%i:%S 2001-01-15 12:59:58 15 September 2001 %d %M %Y 2001-09-15 00:00:00 15 SEPTEMB 2001 %d %M %Y 2001-09-15 00:00:00 @@ -203,6 +203,13 @@ Tuesday 52 2001 %W %V %X 2002-01-01 00:00:00 15-01-2001 %d-%m-%Y %H:%i:%S 2001-01-15 00:00:00 15-01-20 %d-%m-%y 2020-01-15 00:00:00 15-2001-1 %d-%Y-%c 2001-01-15 00:00:00 +Warnings: +Warning 1292 Truncated incorrect datetime value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect datetime value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect datetime value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect datetime value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect datetime value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect datetime value: '0000-00-00 10:20:10.440000' select date,format,DATE(str_to_date(date, format)) as date2 from t1; date format date2 2003-01-02 10:11:12 %Y-%m-%d %H:%i:%S 2003-01-02 @@ -243,12 +250,12 @@ date format time 2003-01-02 02:11:12.12345AM %Y-%m-%d %h:%i:%S.%f %p 02:11:12.123450 2003-01-02 12:11:12.12345 am %Y-%m-%d %h:%i:%S.%f%p 00:11:12.123450 2003-01-02 11:11:12Pm %Y-%m-%d %h:%i:%S%p 23:11:12 -10:20:10 %H:%i:%s 10:20:10 -10:20:10 %h:%i:%s.%f 10:20:10 -10:20:10 %T 10:20:10 -10:20:10AM %h:%i:%s%p 10:20:10 -10:20:10AM %r 10:20:10 -10:20:10.44AM %h:%i:%s.%f%p 10:20:10.440000 +10:20:10 %H:%i:%s NULL +10:20:10 %h:%i:%s.%f NULL +10:20:10 %T NULL +10:20:10AM %h:%i:%s%p NULL +10:20:10AM %r NULL +10:20:10.44AM %h:%i:%s.%f%p NULL 15-01-2001 12:59:58 %d-%m-%Y %H:%i:%S 12:59:58 15 September 2001 %d %M %Y 00:00:00 15 SEPTEMB 2001 %d %M %Y 00:00:00 @@ -265,6 +272,13 @@ Tuesday 52 2001 %W %V %X 00:00:00 15-01-2001 %d-%m-%Y %H:%i:%S 00:00:00 15-01-20 %d-%m-%y 00:00:00 15-2001-1 %d-%Y-%c 00:00:00 +Warnings: +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10.440000' select date,format,concat(TIME(str_to_date(date, format))) as time2 from t1; date format time2 2003-01-02 10:11:12 %Y-%m-%d %H:%i:%S 10:11:12 @@ -274,12 +288,12 @@ date format time2 2003-01-02 02:11:12.12345AM %Y-%m-%d %h:%i:%S.%f %p 02:11:12.123450 2003-01-02 12:11:12.12345 am %Y-%m-%d %h:%i:%S.%f%p 00:11:12.123450 2003-01-02 11:11:12Pm %Y-%m-%d %h:%i:%S%p 23:11:12 -10:20:10 %H:%i:%s 10:20:10 -10:20:10 %h:%i:%s.%f 10:20:10 -10:20:10 %T 10:20:10 -10:20:10AM %h:%i:%s%p 10:20:10 -10:20:10AM %r 10:20:10 -10:20:10.44AM %h:%i:%s.%f%p 10:20:10.440000 +10:20:10 %H:%i:%s NULL +10:20:10 %h:%i:%s.%f NULL +10:20:10 %T NULL +10:20:10AM %h:%i:%s%p NULL +10:20:10AM %r NULL +10:20:10.44AM %h:%i:%s.%f%p NULL 15-01-2001 12:59:58 %d-%m-%Y %H:%i:%S 12:59:58 15 September 2001 %d %M %Y 00:00:00 15 SEPTEMB 2001 %d %M %Y 00:00:00 @@ -296,6 +310,13 @@ Tuesday 52 2001 %W %V %X 00:00:00 15-01-2001 %d-%m-%Y %H:%i:%S 00:00:00 15-01-20 %d-%m-%y 00:00:00 15-2001-1 %d-%Y-%c 00:00:00 +Warnings: +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10' +Warning 1292 Truncated incorrect time value: '0000-00-00 10:20:10.440000' select concat('',str_to_date('8:11:2.123456 03-01-02','%H:%i:%S.%f %y-%m-%d')); concat('',str_to_date('8:11:2.123456 03-01-02','%H:%i:%S.%f %y-%m-%d')) 2003-01-02 08:11:02.123456 diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 3c46a944ba9..e98831ecace 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -350,7 +350,10 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, l_time->year > 9999 || l_time->month > 12 || l_time->day > 31 || l_time->hour > 23 || l_time->minute > 59 || l_time->second > 59 || - (!(flags & TIME_FUZZY_DATE) && (l_time->month == 0 || l_time->day == 0))) + (!(flags & TIME_FUZZY_DATE) && + (l_time->month == 0 || l_time->day == 0)) || + (l_time->year == 0 && l_time->month == 0 && l_time->day == 0 && + (l_time->hour != 0 || l_time->minute != 0 || l_time->second != 0))) { /* Only give warning for a zero date if there is some garbage after */ if (!not_zero_date) /* If zero date */ From 89a4a3e92c91a403740f1f2cdd057ab63afeef46 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Oct 2006 15:29:00 +0500 Subject: [PATCH 2/5] 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. --- mysql-test/r/date_formats.result | 9 +++++++++ mysql-test/t/date_formats.test | 8 ++++++++ sql/item_timefunc.cc | 8 ++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index 035d98d2b74..07cc37fe6bc 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -530,4 +530,13 @@ DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896) NULL Warnings: 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" diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test index 922d047eac8..7e74c128dee 100644 --- a/mysql-test/t/date_formats.test +++ b/mysql-test/t/date_formats.test @@ -317,4 +317,12 @@ SELECT TIME_FORMAT("25:00:00", '%l %p'); # 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" diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 2da0e8956c2..b2036999d88 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -171,15 +171,15 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, 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) { int val_len; char *tmp; - /* Skip pre-space between each argument */ - while (val != val_end && my_isspace(cs, *val)) - val++; - val_len= (uint) (val_end - val); switch (*++ptr) { /* Year */ From 0c7d10bde7378e101e6ce4c0caa818fb0688f3db Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Nov 2006 21:10:02 -0500 Subject: [PATCH 3/5] Bug#19799 delimiter command not working correctly when sourcing a sql file - Client side readline functions unconditionally search for Unix '\n' line endings. In this case, the delimiter statement was set to '//\r' instead of the intended '//'. When removing the '\n' check for and remove preceeding '\r' character as well. client/readline.cc: Bug#19799 delimiter command not working correctly when sourcing a sql file - When removing the '\n' character, check for and remove preceeding '\r' character as well. mysql-test/r/mysql.result: Bug#19799 delimiter command not working correctly when sourcing a sql file - Added Results. mysql-test/t/mysql_delimiter.sql: Bug#19799 delimiter command not working correctly when sourcing a sql file - Added Tests. mysql-test/t/mysql_delimiter_19799.sql: Bug#19799 delimiter command not working correctly when sourcing a sql file - File containing delimiter statement followed by '\r\n' line ending. --- client/readline.cc | 3 ++- mysql-test/r/mysql.result | 4 ++++ mysql-test/t/mysql_delimiter.sql | 9 +++++++++ mysql-test/t/mysql_delimiter_19799.sql | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100755 mysql-test/t/mysql_delimiter_19799.sql diff --git a/client/readline.cc b/client/readline.cc index 3d524633d69..52abe1045b7 100644 --- a/client/readline.cc +++ b/client/readline.cc @@ -51,7 +51,8 @@ char *batch_readline(LINE_BUFFER *line_buff) if (!(pos=intern_read_line(line_buff,&out_length))) return 0; if (out_length && pos[out_length-1] == '\n') - out_length--; /* Remove '\n' */ + if (--out_length && pos[out_length-1] == '\r') /* Remove '\n' */ + out_length--; /* Remove '\r' */ line_buff->read_length=out_length; pos[out_length]=0; return pos; diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index 14267afc27e..b76b2c1e3b7 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -36,6 +36,10 @@ Tables_in_test t1 t2 t3 +Database +information_schema +mysql +test _ Test delimiter : from command line a diff --git a/mysql-test/t/mysql_delimiter.sql b/mysql-test/t/mysql_delimiter.sql index fa80c980b29..67075091c01 100644 --- a/mysql-test/t/mysql_delimiter.sql +++ b/mysql-test/t/mysql_delimiter.sql @@ -49,3 +49,12 @@ delimiter ; # Reset delimiter # Bug #11523: \d works differently than delimiter # source t/mysql_delimiter_source.sql +delimiter ; # Reset delimiter + +# +# Bug #19799: delimiter command not working correctly when sourcing a sql file +# with Windows style line endings. +# +source t/mysql_delimiter_19799.sql +show databases// +delimiter ; # Reset delimiter diff --git a/mysql-test/t/mysql_delimiter_19799.sql b/mysql-test/t/mysql_delimiter_19799.sql new file mode 100755 index 00000000000..2a3d4378492 --- /dev/null +++ b/mysql-test/t/mysql_delimiter_19799.sql @@ -0,0 +1 @@ +delimiter // From bd82fb526aaf8afd3d47822c3ad37b49f8e3da68 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Nov 2006 00:52:32 -0500 Subject: [PATCH 4/5] Bug#19799 delimiter command not working correctly when sourcing a sql file - Post Merge Fix. mysql-test/r/mysql.result: Bug#19799 delimiter command not working correctly when sourcing a sql file - Post merge fix. --- mysql-test/r/mysql.result | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index b76b2c1e3b7..deade31233f 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -38,6 +38,7 @@ t2 t3 Database information_schema +cluster mysql test _ From 1b3f04caa4de376fcdf6d2ba4bb9bca2d78c241f Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Nov 2006 01:27:06 -0500 Subject: [PATCH 5/5] Bug#19799 delimiter command not working correctly when sourcing a sql file - Use more appropriate test case. mysql-test/r/mysql.result: Bug#19799 delimiter command not working correctly when sourcing a sql file - Alt. Result. mysql-test/t/mysql_delimiter.sql: Bug#19799 delimiter command not working correctly when sourcing a sql file - Alt. Test --- mysql-test/r/mysql.result | 7 ++----- mysql-test/t/mysql_delimiter.sql | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index deade31233f..7fd55351880 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -36,11 +36,8 @@ Tables_in_test t1 t2 t3 -Database -information_schema -cluster -mysql -test +Tables_in_test +t1 _ Test delimiter : from command line a diff --git a/mysql-test/t/mysql_delimiter.sql b/mysql-test/t/mysql_delimiter.sql index 67075091c01..db679c3b06b 100644 --- a/mysql-test/t/mysql_delimiter.sql +++ b/mysql-test/t/mysql_delimiter.sql @@ -56,5 +56,6 @@ delimiter ; # Reset delimiter # with Windows style line endings. # source t/mysql_delimiter_19799.sql -show databases// +use test// +show tables// delimiter ; # Reset delimiter