1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

MDEV-34215 Fix DATE_FORMAT result length for negative TIME

DATE_FORMAT calculated its maximum result length solely from the format
string. Formatting a negative TIME also prepends a minus sign, so the
cursor protocol trusted an undersized result and truncated -01 to -0.

Account for the possible sign in format_length() for TIME_FORMAT() and
DATE_FORMAT() with a native TIME argument. Enable the existing cursor
protocol regression cases for binary, latin1, and utf32 result character
sets.
This commit is contained in:
GoldenEmperor1177
2026-09-29 22:48:20 +05:30
committed by Daniel Black
parent 30e7c940ff
commit 45c0b8649c
3 changed files with 4 additions and 13 deletions

View File

@@ -236,11 +236,8 @@ SELECT DATE_FORMAT('2004-02-02','%W');
SELECT HEX(DATE_FORMAT('2004-02-02','%W'));
#Enable after fix MDEV-33936
--disable_view_protocol
#enable after fix MDEV-34215
--disable_cursor_protocol
SELECT DATE_FORMAT(TIME'-01:01:01','%h');
SELECT HEX(DATE_FORMAT(TIME'-01:01:01','%h'));
--enable_cursor_protocol
--enable_view_protocol
--echo # latin1 format, binary result
@@ -248,11 +245,8 @@ SELECT DATE_FORMAT('2004-02-02',_latin1'%W');
SELECT HEX(DATE_FORMAT('2004-02-02',_latin1'%W'));
#Enable after fix MDEV-33936
--disable_view_protocol
#enable after fix MDEV-34215
--disable_cursor_protocol
SELECT DATE_FORMAT(TIME'-01:01:01',_latin1'%h');
SELECT HEX(DATE_FORMAT(TIME'-01:01:01',_latin1'%h'));
--enable_cursor_protocol
--enable_view_protocol
--echo # Binary format, latin1 result
@@ -261,11 +255,8 @@ SELECT DATE_FORMAT('2004-02-02',_binary'%W');
SELECT HEX(DATE_FORMAT('2004-02-02',_binary'%W'));
#Enable after fix MDEV-33936
--disable_view_protocol
#enable after fix MDEV-34215
--disable_cursor_protocol
SELECT DATE_FORMAT(TIME'-01:01:01',_binary'%h');
SELECT HEX(DATE_FORMAT(TIME'-01:01:01',_binary'%h'));
--enable_cursor_protocol
--enable_view_protocol
--echo #
--echo # End of 10.4 tests

View File

@@ -1134,11 +1134,8 @@ SELECT HEX(DATE_FORMAT(TIME'-01:01:01','%h'));
--echo # utf8 format, utf32 result
SELECT DATE_FORMAT('2004-02-02',_utf8'%W');
SELECT HEX(DATE_FORMAT('2004-02-02',_utf8'%W'));
#enable after fix MDEV-34215
--disable_cursor_protocol
SELECT DATE_FORMAT(TIME'-01:01:01',_utf8'%h');
SELECT HEX(DATE_FORMAT(TIME'-01:01:01',_utf8'%h'));
--enable_cursor_protocol
--echo # utf32 format, utf8 result
SET NAMES utf8;

View File

@@ -1814,7 +1814,10 @@ bool Item_func_date_format::eq(const Item *item, const Eq_config &config) const
uint Item_func_date_format::format_length(const String *format)
{
uint size=0;
/* A negative TIME value adds a leading minus sign. */
uint size= (is_time_format ||
args[0]->type_handler()->mysql_timestamp_type() ==
MYSQL_TIMESTAMP_TIME) ? 1 : 0;
const char *ptr=format->ptr();
const char *end=ptr+format->length();