From 3ca1852cbaac852f778af0e70278cf3a010f4403 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Apr 2006 14:34:19 +0500 Subject: [PATCH 1/2] Fix for bug #18501: Server crashes with monthname(). mysql-test/r/func_time.result: Fix for bug #18501: Server crashes with monthname(). - test case mysql-test/t/func_time.test: Fix for bug #18501: Server crashes with monthname(). - test case sql/item_timefunc.cc: Fix for bug #18501: Server crashes with monthname(). - check null_value as well. --- mysql-test/r/func_time.result | 4 ++++ mysql-test/t/func_time.test | 7 +++++++ sql/item_timefunc.cc | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index fc872285acb..02f3d2f7273 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -626,3 +626,7 @@ last_day('2005-01-00') NULL Warnings: Warning 1292 Truncated incorrect datetime value: '2005-01-00' +select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')), +monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m')); +monthname(str_to_date(null, '%m')) monthname(str_to_date(null, '%m')) monthname(str_to_date(1, '%m')) monthname(str_to_date(0, '%m')) +NULL NULL January NULL diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 68a33afd85c..01e4e47d318 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -315,4 +315,11 @@ select last_day('2005-00-00'); select last_day('2005-00-01'); select last_day('2005-01-00'); +# +# Bug #18501: monthname and NULLs +# + +select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')), + monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m')); + # End of 4.1 tests diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index f3d6858755c..ffd8c79dca8 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -905,9 +905,9 @@ String* Item_func_monthname::val_str(String* str) { DBUG_ASSERT(fixed == 1); const char *month_name; - uint month=(uint) Item_func_month::val_int(); + uint month= (uint) val_int(); - if (!month) // This is also true for NULL + if (null_value || !month) { null_value=1; return (String*) 0; From 2e72ae3d818cef271dc348ba4ba781f66d4c1ec3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 9 May 2006 22:35:51 -0400 Subject: [PATCH 2/2] Bug#19564: mysql displays NULL instead of space Correct a bug (that I introduced, after using Oracle's database software for too many years) where the length of the database-sent data is incorrectly used to infer NULLness. client/mysql.cc: No longer use the length of the data to infer whether it is NULL or not. mysql-test/r/mysql.result: Add result and version marker, and correct previous result. mysql-test/t/mysql.test: Add test and version marker --- client/mysql.cc | 2 +- mysql-test/r/mysql.result | 12 ++++++++++-- mysql-test/t/mysql.test | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index 7b46aaf67ce..50e5569a0ec 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2319,7 +2319,7 @@ print_table_data(MYSQL_RES *result) uint extra_padding; /* If this column may have a null value, use "NULL" for empty. */ - if (! not_null_flag[off] && (lengths[off] == 0)) + if (! not_null_flag[off] && (cur[off] == NULL)) { buffer= "NULL"; data_length= 4; diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index a067d3ad0f8..4b7084e813c 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -74,7 +74,7 @@ c_cp932 +----------------------+------------+--------+ | >a < | b | 123421 | | >a < | 0123456789 | 4 | -| >abcd< | NULL | 4 | +| >abcd< | | 4 | +----------------------+------------+--------+ +------+------+---------------------------+ | i | j | k | @@ -94,6 +94,14 @@ c_cp932 | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | i | int(11) | YES | | NULL | | -| j | int(11) | NO | | NULL | | +| j | int(11) | NO | | | | | k | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ ++------+------+ +| i | s1 | ++------+------+ +| 1 | x | +| 2 | NULL | +| 3 | | ++------+------+ +End of 5.0 tests diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index e76553f42e7..ac4c323f51e 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -72,3 +72,11 @@ drop table t1; # --exec $MYSQL -t --default-character-set utf8 test -e "create table t1 (i int, j int not null, k int); insert into t1 values (null, 1, null); select * from t1; describe t1; drop table t1;" +# +# Bug#19564: mysql displays NULL instead of space +# +--exec $MYSQL -t test -e "create table b19564 (i int, s1 char(1)); insert into b19564 values (1, 'x'); insert into b19564 values (2, NULL); insert into b19564 values (3, ' '); select * from b19564 order by i; drop table b19564;" + +--echo End of 5.0 tests + +