mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-29646: sformat('Num [{:20}]', 42) gives incorrect result in view
The problem is that sformat does not assign the enough space for the result string. The result string is allocated with the max_length of argument, but the correst max_length should be based on the format string. The patch fixes the problem by using MAX_BLOB_WIDTH to assign length
This commit is contained in:
committed by
Daniel Black
parent
7d967423fe
commit
f288d42cdb
@@ -434,7 +434,7 @@ create table t1 as select sformat(_ucs2 x'003D007B007D003D', _ucs2 x'04420435044
|
|||||||
show create table t1;
|
show create table t1;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
t1 CREATE TABLE `t1` (
|
t1 CREATE TABLE `t1` (
|
||||||
`x` varchar(8) CHARACTER SET ucs2 COLLATE ucs2_general_ci DEFAULT NULL
|
`x` longtext CHARACTER SET ucs2 COLLATE ucs2_general_ci DEFAULT NULL
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
drop table t1;
|
drop table t1;
|
||||||
set names latin1;
|
set names latin1;
|
||||||
@@ -468,3 +468,26 @@ set names latin1;
|
|||||||
#
|
#
|
||||||
# End of 10.7 tests
|
# End of 10.7 tests
|
||||||
#
|
#
|
||||||
|
#
|
||||||
|
# Start of 10.8 tests
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# MDEV-29646 sformat('Num [{:20}]', 42) gives incorrect result in view
|
||||||
|
#
|
||||||
|
create view v1 as select sformat('Num [{:20}]', 42);
|
||||||
|
select * from v1;
|
||||||
|
sformat('Num [{:20}]', 42)
|
||||||
|
Num [ 42]
|
||||||
|
drop view v1;
|
||||||
|
create view v1 as SELECT sformat('Square root of [{:d}] is [{:.20}]', 2, sqrt(2));
|
||||||
|
select * from v1;
|
||||||
|
sformat('Square root of [{:d}] is [{:.20}]', 2, sqrt(2))
|
||||||
|
Square root of [2] is [1.4142135623730951455]
|
||||||
|
drop view v1;
|
||||||
|
create table t1 (a text, b int, c text);
|
||||||
|
insert t1 values ('[{} -> {}]', 10, '{}'), ('[{:20} <- {}]', 1, '{:30}');
|
||||||
|
select sformat(a,b,c) from t1;
|
||||||
|
sformat(a,b,c)
|
||||||
|
[10 -> {}]
|
||||||
|
[ 1 <- {:30}]
|
||||||
|
drop table t1;
|
||||||
|
@@ -253,3 +253,24 @@ set names latin1;
|
|||||||
echo #;
|
echo #;
|
||||||
echo # End of 10.7 tests;
|
echo # End of 10.7 tests;
|
||||||
echo #;
|
echo #;
|
||||||
|
|
||||||
|
echo #;
|
||||||
|
echo # Start of 10.8 tests;
|
||||||
|
echo #;
|
||||||
|
|
||||||
|
echo #;
|
||||||
|
echo # MDEV-29646 sformat('Num [{:20}]', 42) gives incorrect result in view;
|
||||||
|
echo #;
|
||||||
|
|
||||||
|
create view v1 as select sformat('Num [{:20}]', 42);
|
||||||
|
select * from v1;
|
||||||
|
drop view v1;
|
||||||
|
|
||||||
|
create view v1 as SELECT sformat('Square root of [{:d}] is [{:.20}]', 2, sqrt(2));
|
||||||
|
select * from v1;
|
||||||
|
drop view v1;
|
||||||
|
|
||||||
|
create table t1 (a text, b int, c text);
|
||||||
|
insert t1 values ('[{} -> {}]', 10, '{}'), ('[{:20} <- {}]', 1, '{:30}');
|
||||||
|
select sformat(a,b,c) from t1;
|
||||||
|
drop table t1;
|
||||||
|
@@ -1348,13 +1348,13 @@ bool Item_func_sformat::fix_length_and_dec()
|
|||||||
|
|
||||||
for (uint i=0 ; i < arg_count ; i++)
|
for (uint i=0 ; i < arg_count ; i++)
|
||||||
{
|
{
|
||||||
char_length+= args[i]->max_char_length();
|
|
||||||
if (args[i]->result_type() == STRING_RESULT &&
|
if (args[i]->result_type() == STRING_RESULT &&
|
||||||
Type_std_attributes::agg_item_set_converter(c, func_name_cstring(),
|
Type_std_attributes::agg_item_set_converter(c, func_name_cstring(),
|
||||||
args+i, 1, flags, 1))
|
args+i, 1, flags, 1))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char_length= MAX_BLOB_WIDTH;
|
||||||
fix_char_length_ulonglong(char_length);
|
fix_char_length_ulonglong(char_length);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user