summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/main/func_math.result16
-rw-r--r--mysql-test/main/func_math.test7
-rw-r--r--mysql-test/main/func_str.result2
-rw-r--r--sql/item_strfunc.cc5
-rw-r--r--sql/sql_type.cc2
-rw-r--r--sql/sql_type.h1
6 files changed, 28 insertions, 5 deletions
diff --git a/mysql-test/main/func_math.result b/mysql-test/main/func_math.result
index d50abe00e72..5770859c377 100644
--- a/mysql-test/main/func_math.result
+++ b/mysql-test/main/func_math.result
@@ -2723,6 +2723,22 @@ t2 CREATE TABLE `t2` (
`c1` varchar(30) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
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
#
diff --git a/mysql-test/main/func_math.test b/mysql-test/main/func_math.test
index 5f333c06b78..15c27076ba3 100644
--- a/mysql-test/main/func_math.test
+++ b/mysql-test/main/func_math.test
@@ -1733,6 +1733,13 @@ SELECT HEX(c1) FROM t2;
SHOW CREATE TABLE 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 # End of 10.4 tests
--echo #
diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result
index 5de77f18a24..b4e3f27eda6 100644
--- a/mysql-test/main/func_str.result
+++ b/mysql-test/main/func_str.result
@@ -2708,7 +2708,7 @@ create table t1(a float);
insert into t1 values (1.33);
select format(a, 2) from t1;
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)
1.33
drop table t1;
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index d31f47e68fd..0baa762d25f 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2668,11 +2668,10 @@ bool Item_func_format::fix_length_and_dec()
{
uint32 char_length= args[0]->type_handler()->Item_decimal_notation_int_digits(args[0]);
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();
- 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;
collation.set(default_charset());
diff --git a/sql/sql_type.cc b/sql/sql_type.cc
index 31b85c2e858..f1f6ecfb046 100644
--- a/sql/sql_type.cc
+++ b/sql/sql_type.cc
@@ -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.
*/
uint32
diff --git a/sql/sql_type.h b/sql/sql_type.h
index 04eb5a25891..2be651a2f2f 100644
--- a/sql/sql_type.h
+++ b/sql/sql_type.h
@@ -5147,6 +5147,7 @@ public:
}
bool type_can_have_auto_increment_attribute() const { return true; }
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); }
Item *create_typecast_item(THD *thd, Item *item,
const Type_cast_attributes &attr) const;