Commit 1360ca09 authored by Gleb Shchepa's avatar Gleb Shchepa

Backport of fix to bug #33629 into mysql-next-mr-bugfixing.

Bug #33629: last_day function can return null, but has 'not null' flag set for result

LAST_DAY and MAKEDATE functions are documented as
returning NULL value, but actually they was implemented
as returning NOT NULL typed values.

That caused a confusing error "ERROR 1048 (23000): Column
'...' cannot be null" on queries like: 

  SELECT 1 FROM (SELECT LAST_DAY('0')) a;


mysql-test/r/func_sapdb.result:
    Updated test case for bug #33629.
mysql-test/r/func_time.result:
    Updated test case for bug #33629.
mysql-test/r/type_date.result:
    Added test case for bug #33629.
mysql-test/t/type_date.test:
    Added test case for bug #33629.
sql/item_timefunc.h:
    Bug #33629: last_day function can return null, but has 'not null' flag set for result
    
    1. The Item_func_makedate::fix_length_and_dec method
       has been modified to declare MAKEDATE() as a function
       returning nullable value.
    2. The Item_func_last_day::fix_length_and_dec method
       has been overloaded for the same purpose.
parent 94f7761d
......@@ -194,7 +194,7 @@ date("1997-12-31 23:59:59.000001") as f8,
time("1997-12-31 23:59:59.000001") as f9;
describe t1;
Field Type Null Key Default Extra
f1 date NO 0000-00-00
f1 date YES NULL
f2 datetime YES NULL
f3 time YES NULL
f4 time YES NULL
......
......@@ -814,7 +814,7 @@ create table t1 select last_day('2000-02-05') as a,
from_days(to_days("960101")) as b;
describe t1;
Field Type Null Key Default Extra
a date NO 0000-00-00
a date YES NULL
b date YES NULL
select * from t1;
a b
......
......@@ -276,3 +276,25 @@ a
0000-00-01
drop table t1;
End of 5.1 tests
#
# Bug #33629: last_day function can return null, but has 'not null'
# flag set for result
#
SELECT 1 FROM (SELECT LAST_DAY('0')) a;
1
1
Warnings:
Warning 1292 Incorrect datetime value: '0'
SELECT 1 FROM (SELECT MAKEDATE(2011,0)) a;
1
1
CREATE TABLE t1 AS
SELECT LAST_DAY('1970-01-01') AS f1,
MAKEDATE(1970, 1) AS f2;
DESCRIBE t1;
Field Type Null Key Default Extra
f1 date YES NULL
f2 date YES NULL
DROP TABLE t1;
#
End of 6.0 tests
......@@ -247,3 +247,21 @@ select * from t1 where a between '0000-00-01' and '0000-00-02';
drop table t1;
--echo End of 5.1 tests
--echo #
--echo # Bug #33629: last_day function can return null, but has 'not null'
--echo # flag set for result
--echo #
SELECT 1 FROM (SELECT LAST_DAY('0')) a;
SELECT 1 FROM (SELECT MAKEDATE(2011,0)) a;
CREATE TABLE t1 AS
SELECT LAST_DAY('1970-01-01') AS f1,
MAKEDATE(1970, 1) AS f2;
DESCRIBE t1;
DROP TABLE t1;
--echo #
--echo End of 6.0 tests
......@@ -871,6 +871,7 @@ class Item_func_makedate :public Item_date_func
{
decimals=0;
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null= 1;
}
longlong val_int();
};
......@@ -1025,4 +1026,9 @@ class Item_func_last_day :public Item_date
Item_func_last_day(Item *a) :Item_date(a) {}
const char *func_name() const { return "last_day"; }
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
void fix_length_and_dec()
{
Item_date::fix_length_and_dec();
maybe_null= 1;
}
};
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