mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-20732 Correctly set the length of the FORMAT() result for float data type as argument.
This commit is contained in:
committed by
Robert Bindar
parent
1c97cd339e
commit
f0ca9bc669
@ -2723,6 +2723,22 @@ t2 CREATE TABLE `t2` (
|
|||||||
`c1` varchar(30) DEFAULT NULL
|
`c1` varchar(30) DEFAULT NULL
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||||
DROP TABLE t1,t2;
|
DROP TABLE t1,t2;
|
||||||
|
CREATE OR REPLACE TABLE t1 (f float);
|
||||||
|
INSERT INTO t1 VALUES (3e38), (-3e38), (0), (12.34), (-12.34);
|
||||||
|
CREATE OR REPLACE TABLE t2 AS SELECT FORMAT(f,0) FROM t1;
|
||||||
|
SELECT * FROM t2;
|
||||||
|
FORMAT(f,0)
|
||||||
|
300,000,000,549,775,580,000,000,000,000,000,000,000
|
||||||
|
-300,000,000,549,775,580,000,000,000,000,000,000,000
|
||||||
|
0
|
||||||
|
12
|
||||||
|
-12
|
||||||
|
SHOW CREATE TABLE t2;
|
||||||
|
Table Create Table
|
||||||
|
t2 CREATE TABLE `t2` (
|
||||||
|
`FORMAT(f,0)` varchar(53) DEFAULT NULL
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||||
|
DROP TABLE t1,t2;
|
||||||
#
|
#
|
||||||
# End of 10.4 tests
|
# End of 10.4 tests
|
||||||
#
|
#
|
||||||
|
@ -1733,6 +1733,13 @@ SELECT HEX(c1) FROM t2;
|
|||||||
SHOW CREATE TABLE t2;
|
SHOW CREATE TABLE t2;
|
||||||
DROP TABLE t1,t2;
|
DROP TABLE t1,t2;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TABLE t1 (f float);
|
||||||
|
INSERT INTO t1 VALUES (3e38), (-3e38), (0), (12.34), (-12.34);
|
||||||
|
CREATE OR REPLACE TABLE t2 AS SELECT FORMAT(f,0) FROM t1;
|
||||||
|
SELECT * FROM t2;
|
||||||
|
SHOW CREATE TABLE t2;
|
||||||
|
DROP TABLE t1,t2;
|
||||||
|
|
||||||
--echo #
|
--echo #
|
||||||
--echo # End of 10.4 tests
|
--echo # End of 10.4 tests
|
||||||
--echo #
|
--echo #
|
||||||
|
@ -2708,7 +2708,7 @@ create table t1(a float);
|
|||||||
insert into t1 values (1.33);
|
insert into t1 values (1.33);
|
||||||
select format(a, 2) from t1;
|
select format(a, 2) from t1;
|
||||||
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
|
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
|
||||||
def format(a, 2) 253 4 4 Y 0 39 8
|
def format(a, 2) 253 56 4 Y 0 39 8
|
||||||
format(a, 2)
|
format(a, 2)
|
||||||
1.33
|
1.33
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
@ -2668,10 +2668,9 @@ bool Item_func_format::fix_length_and_dec()
|
|||||||
{
|
{
|
||||||
uint32 char_length= args[0]->type_handler()->Item_decimal_notation_int_digits(args[0]);
|
uint32 char_length= args[0]->type_handler()->Item_decimal_notation_int_digits(args[0]);
|
||||||
uint dec= FORMAT_MAX_DECIMALS;
|
uint dec= FORMAT_MAX_DECIMALS;
|
||||||
if (args[1]->const_item() && !args[1]->is_expensive())
|
if (args[1]->const_item() && !args[1]->is_expensive() && !args[1]->null_value)
|
||||||
{
|
{
|
||||||
Longlong_hybrid tmp= args[1]->to_longlong_hybrid();
|
Longlong_hybrid tmp= args[1]->to_longlong_hybrid();
|
||||||
if (!args[1]->null_value)
|
|
||||||
dec= tmp.to_uint(FORMAT_MAX_DECIMALS);
|
dec= tmp.to_uint(FORMAT_MAX_DECIMALS);
|
||||||
}
|
}
|
||||||
uint32 max_sep_count= (char_length / 3) + (dec ? 1 : 0) + /*sign*/1;
|
uint32 max_sep_count= (char_length / 3) + (dec ? 1 : 0) + /*sign*/1;
|
||||||
|
@ -3550,7 +3550,7 @@ Type_handler_general_purpose_int::Item_decimal_notation_int_digits(
|
|||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Decimal to binary digits ratio converges to log2(10) thus using 3 as
|
Binary to Decimal digits ratio converges to log2(10) thus using 3 as
|
||||||
a divisor.
|
a divisor.
|
||||||
*/
|
*/
|
||||||
uint32
|
uint32
|
||||||
|
@ -5147,6 +5147,7 @@ public:
|
|||||||
}
|
}
|
||||||
bool type_can_have_auto_increment_attribute() const { return true; }
|
bool type_can_have_auto_increment_attribute() const { return true; }
|
||||||
uint32 max_display_length(const Item *item) const { return 25; }
|
uint32 max_display_length(const Item *item) const { return 25; }
|
||||||
|
uint32 Item_decimal_notation_int_digits(const Item *item) const { return 39; }
|
||||||
uint32 calc_pack_length(uint32 length) const { return sizeof(float); }
|
uint32 calc_pack_length(uint32 length) const { return sizeof(float); }
|
||||||
Item *create_typecast_item(THD *thd, Item *item,
|
Item *create_typecast_item(THD *thd, Item *item,
|
||||||
const Type_cast_attributes &attr) const;
|
const Type_cast_attributes &attr) const;
|
||||||
|
Reference in New Issue
Block a user