1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

less strict assert to take into account weird cases

This commit is contained in:
serg@serg.mylan
2004-08-19 23:10:33 +02:00
parent dd3db08be3
commit b81af1c750
3 changed files with 14 additions and 2 deletions

View File

@@ -114,6 +114,9 @@ select min(a) from t1;
min(a) min(a)
-0.010 -0.010
drop table t1; drop table t1;
create table t1 (c20 char);
insert into t1 (c20) values (5000.0);
drop table t1;
create table t1 (f float(54)); create table t1 (f float(54));
Incorrect column specifier for column 'f' Incorrect column specifier for column 'f'
drop table if exists t1; drop table if exists t1;

View File

@@ -54,6 +54,13 @@ select a from t1 order by a;
select min(a) from t1; select min(a) from t1;
drop table t1; drop table t1;
#
# float in a char(1) field
#
create table t1 (c20 char);
insert into t1 (c20) values (5000.0);
drop table t1;
# Errors # Errors
--error 1063 --error 1063

View File

@@ -3733,15 +3733,17 @@ static void store_double_in_string_field(Field_str *field, uint32 field_length,
use_scientific_notation= (field->ceiling < nr); use_scientific_notation= (field->ceiling < nr);
} }
length= (uint)sprintf(buff, "%-.*g", length= (uint)sprintf(buff, "%-.*g",
use_scientific_notation ? max(0,field_length-5) : field_length, use_scientific_notation ? max(0,(int)field_length-5) : field_length,
nr); nr);
/* /*
+1 below is because "precision" in %g above means the +1 below is because "precision" in %g above means the
max. number of significant digits, not the output width. max. number of significant digits, not the output width.
Thus the width can be larger than number of significant digits by 1 Thus the width can be larger than number of significant digits by 1
(for decimal point) (for decimal point)
the test for field_length < 5 is for extreme cases,
like inserting 500.0 in char(1)
*/ */
DBUG_ASSERT(length <= field_length+1); DBUG_ASSERT(field_length < 5 || length <= field_length+1);
field->store(buff, min(length, field_length)); field->store(buff, min(length, field_length));
} }