Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
f0ca9bc6
Commit
f0ca9bc6
authored
Dec 30, 2019
by
Gagan Goel
Committed by
Robert Bindar
Jan 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-20732 Correctly set the length of the FORMAT() result for float data type as argument.
parent
1c97cd33
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
5 deletions
+28
-5
mysql-test/main/func_math.result
mysql-test/main/func_math.result
+16
-0
mysql-test/main/func_math.test
mysql-test/main/func_math.test
+7
-0
mysql-test/main/func_str.result
mysql-test/main/func_str.result
+1
-1
sql/item_strfunc.cc
sql/item_strfunc.cc
+2
-3
sql/sql_type.cc
sql/sql_type.cc
+1
-1
sql/sql_type.h
sql/sql_type.h
+1
-0
No files found.
mysql-test/main/func_math.result
View file @
f0ca9bc6
...
...
@@ -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
#
mysql-test/main/func_math.test
View file @
f0ca9bc6
...
...
@@ -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
(
3
e38
),
(
-
3
e38
),
(
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
#
mysql-test/main/func_str.result
View file @
f0ca9bc6
...
...
@@ -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;
...
...
sql/item_strfunc.cc
View file @
f0ca9bc6
...
...
@@ -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
());
...
...
sql/sql_type.cc
View file @
f0ca9bc6
...
...
@@ -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
...
...
sql/sql_type.h
View file @
f0ca9bc6
...
...
@@ -5147,6 +5147,7 @@ class Type_handler_float: public Type_handler_real_result
}
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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment