Skip to content

Commit 9dc1353

Browse files
author
Gleb Shchepa
committed
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; --BZR-- revision-id: [email protected] property-branch-nick: mysql-next-mr-bugfixing property-file-info: ld7:file_id70:sp1f-func_sapdb.result-20030623075631-kd3o45rwsfzikxjuk7r2deumuhaphbn77:message36: Updated test case for bug #33629. property-file-info: 4:path30:mysql-test/r/func_sapdb.resulted7:file_id69:sp1f-func_time.result-20001228015633-voo54ouzgwctcbmk22zwazoev5os5o4x7:message36: Updated test case for bug #33629. property-file-info: 4:path29:mysql-test/r/func_time.resulted7:file_id69:sp1f-type_date.result-20001228015634-drbo6443s5wzxlf3enjz3qt43ttjf6ik7:message34: Added test case for bug #33629. property-file-info: 4:path29:mysql-test/r/type_date.resulted7:file_id67:sp1f-type_date.test-20001228015637-6hhkz7fj6xpjxak4s3sq7ohgddycrhvz7:message34: Added test case for bug #33629. property-file-info: 4:path27:mysql-test/t/type_date.tested7:file_id68:sp1f-item_timefunc.h-19700101030959-o34ypz6ggolzqmhgsjnqh6inkvgugi467:message338: Bug #33629: last_day function can return null, but has 'not null' flag set for result property-file-info: property-file-info: 1. The Item_func_makedate::fix_length_and_dec method property-file-info: has been modified to declare MAKEDATE() as a function property-file-info: returning nullable value. property-file-info: 2. The Item_func_last_day::fix_length_and_dec method property-file-info: has been overloaded for the same purpose. property-file-info: 4:path19:sql/item_timefunc.hee testament3-sha1: 00121556ee1f79e071021de9bac326477a1f7392
1 parent e13305b commit 9dc1353

5 files changed

Lines changed: 48 additions & 2 deletions

File tree

mysql-test/r/func_sapdb.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ date("1997-12-31 23:59:59.000001") as f8,
194194
time("1997-12-31 23:59:59.000001") as f9;
195195
describe t1;
196196
Field Type Null Key Default Extra
197-
f1 date NO 0000-00-00
197+
f1 date YES NULL
198198
f2 datetime YES NULL
199199
f3 time YES NULL
200200
f4 time YES NULL

mysql-test/r/func_time.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ create table t1 select last_day('2000-02-05') as a,
814814
from_days(to_days("960101")) as b;
815815
describe t1;
816816
Field Type Null Key Default Extra
817-
a date NO 0000-00-00
817+
a date YES NULL
818818
b date YES NULL
819819
select * from t1;
820820
a b

mysql-test/r/type_date.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,25 @@ a
276276
0000-00-01
277277
drop table t1;
278278
End of 5.1 tests
279+
#
280+
# Bug #33629: last_day function can return null, but has 'not null'
281+
# flag set for result
282+
#
283+
SELECT 1 FROM (SELECT LAST_DAY('0')) a;
284+
1
285+
1
286+
Warnings:
287+
Warning 1292 Incorrect datetime value: '0'
288+
SELECT 1 FROM (SELECT MAKEDATE(2011,0)) a;
289+
1
290+
1
291+
CREATE TABLE t1 AS
292+
SELECT LAST_DAY('1970-01-01') AS f1,
293+
MAKEDATE(1970, 1) AS f2;
294+
DESCRIBE t1;
295+
Field Type Null Key Default Extra
296+
f1 date YES NULL
297+
f2 date YES NULL
298+
DROP TABLE t1;
299+
#
300+
End of 6.0 tests

mysql-test/t/type_date.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,21 @@ select * from t1 where a between '0000-00-01' and '0000-00-02';
247247
drop table t1;
248248

249249
--echo End of 5.1 tests
250+
251+
--echo #
252+
--echo # Bug #33629: last_day function can return null, but has 'not null'
253+
--echo # flag set for result
254+
--echo #
255+
256+
SELECT 1 FROM (SELECT LAST_DAY('0')) a;
257+
SELECT 1 FROM (SELECT MAKEDATE(2011,0)) a;
258+
259+
CREATE TABLE t1 AS
260+
SELECT LAST_DAY('1970-01-01') AS f1,
261+
MAKEDATE(1970, 1) AS f2;
262+
DESCRIBE t1;
263+
DROP TABLE t1;
264+
265+
--echo #
266+
267+
--echo End of 6.0 tests

sql/item_timefunc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ class Item_func_makedate :public Item_date_func
871871
{
872872
decimals=0;
873873
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
874+
maybe_null= 1;
874875
}
875876
longlong val_int();
876877
};
@@ -1025,4 +1026,9 @@ class Item_func_last_day :public Item_date
10251026
Item_func_last_day(Item *a) :Item_date(a) {}
10261027
const char *func_name() const { return "last_day"; }
10271028
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
1029+
void fix_length_and_dec()
1030+
{
1031+
Item_date::fix_length_and_dec();
1032+
maybe_null= 1;
1033+
}
10281034
};

0 commit comments

Comments
 (0)