Below is the list of changes that have just been committed into a local
4.1 repository of igor. When igor does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-03-30 00:53:01-07:00, igor@stripped +3 -0
Fixed bug #26788: an assertion abort the function Field_str::store
that converts double values into strings for a character field.
It chooses the most precise and most compact the representation
for any double value. If however the the field is not long enough
to hold any meaningful representation the function truncates it
and issues a warning message.
In some cases the string representations were incorrect. This is
fixed by the patch.
mysql-test/r/insert.result@stripped, 2007-03-30 00:52:58-07:00, igor@stripped +50 -0
Added a test case for bug #26788.
mysql-test/t/insert.test@stripped, 2007-03-30 00:52:58-07:00, igor@stripped +32 -0
Added a test case for bug #26788.
sql/field.cc@stripped, 2007-03-30 00:52:58-07:00, igor@stripped +30 -18
Fixed bug #26788: an assertion abort the function Field_str::store
that converts double values into strings for a character field.
It chooses the most precise and the most compact representation
for any double value. If however the the field is not long enough
to hold any meaningful representation the function truncates the
result of conversion and issues a warning message.
In some cases the string representations were incorrect. This is
fixed by the patch.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: igor
# Host: olga.mysql.com
# Root: /home/igor/dev-opt/mysql-4.1-opt-bug26788
--- 1.235/sql/field.cc 2007-03-30 00:53:04 -07:00
+++ 1.236/sql/field.cc 2007-03-30 00:53:05 -07:00
@@ -5001,31 +5001,43 @@
uint length;
bool use_scientific_notation= TRUE;
uint char_length= field_length / charset()->mbmaxlen;
+ int precision= char_length;
/*
Check fabs(nr) against longest value that can be stored in field,
- which depends on whether the value is < 1 or not, and negative or not
+ which depends on whether the value is < 1 or not, and negative or not.
*/
double anr= fabs(nr);
- int neg= (nr < 0.0) ? 1 : 0;
- if (char_length > 4 && char_length < 32 &&
- (anr < 1.0 ? anr > 1/(log_10[max(0,(int) char_length-neg-2)]) /* -2 for "0." */
- : anr < log_10[char_length-neg]-1))
- use_scientific_notation= FALSE;
+ if (nr < 0.0)
+ precision--; /* '-' always takes one character */
+ /*
+ The scientific notation is always used when the exponent of the value is
+ less than -4 or greater than or equal to the precision argument.
+ */
+ if (precision > 0 &&
+ anr >= 1/log_10[min(4,precision-1)] && anr <= log_10[precision]-1)
+ {
+ int i;
+
+ if (anr < log_10[precision-1])
+ --precision; /* take into account possible '.' */
+
+ /* Take into account possible zeros at the beginning (4 at most) */
+ for (i= 0 ; i < precision && anr < 1/log_10[i]; i++) ;
+
+ precision-= i;
+ use_scientific_notation= precision == 0;
+ }
+ else
+ precision= max(0, precision-5);
- length= (uint) my_sprintf(buff, (buff, "%-.*g",
- (use_scientific_notation ?
- max(0, (int)char_length-neg-5) :
- char_length),
- nr));
+ length= (uint) my_sprintf(buff, (buff, "%-.*g", precision, nr));
/*
- +1 below is because "precision" in %g above means the
- max. number of significant digits, not the output width.
- Thus the width can be larger than number of significant digits by 1
- (for decimal point)
- the test for char_length < 5 is for extreme cases,
- like inserting 500.0 in char(1)
+ Note that when use_scientific_notation is TRUE length may be greater
+ than char_length. In this case a warning about data truncation will be
+ issued by the following call of the store method.
*/
- DBUG_ASSERT(char_length < 5 || length <= char_length+1);
+ DBUG_ASSERT(length <= char_length ||
+ use_scientific_notation && char_length <= 4);
return store((const char *) buff, length, charset());
}
--- 1.23/mysql-test/r/insert.result 2007-03-30 00:53:05 -07:00
+++ 1.24/mysql-test/r/insert.result 2007-03-30 00:53:05 -07:00
@@ -325,3 +325,53 @@
f_double_15_1_u 0.0
f_float_3_1_u 0.0
drop table t1;
+CREATE TABLE t1 (
+a char(20) NOT NULL,
+b char(7) DEFAULT NULL,
+c char(4) DEFAULT NULL
+);
+INSERT INTO t1(a,b) VALUES (1.225e-05, 1.225e-05);
+INSERT INTO t1(a,b) VALUES (1.225e-04, 1.225e-04);
+INSERT INTO t1(a,b) VALUES (1.225e-01, 1.225e-01);
+INSERT INTO t1(a,b) VALUES (1.225877e-01, 1.225877e-01);
+INSERT INTO t1(a,b) VALUES (1.225e+01, 1.225e+01);
+INSERT INTO t1(a,b,c) VALUES (1.225e+01, 1.225e+01, 1.225e+01);
+INSERT INTO t1(a,b) VALUES (1.225e+05, 1.225e+05);
+INSERT INTO t1(a,b) VALUES (1.225e+10, 1.225e+10);
+INSERT INTO t1(a,b) VALUES (1.225e+15, 1.225e+15);
+INSERT INTO t1(a,b) VALUES (5000000, 5000000);
+INSERT INTO t1(a,c) VALUES (1.225, 1.225);
+INSERT INTO t1(a,c) VALUES (1.37, 1.37);
+INSERT INTO t1(a,c) VALUES (-1.37, -1.37);
+Warnings:
+Warning 1265 Data truncated for column 'c' at row 1
+INSERT INTO t1(a,c) VALUES (1.87e-3, 1.87e-3);
+Warnings:
+Warning 1265 Data truncated for column 'c' at row 1
+INSERT INTO t1(a,c) VALUES (-1.87e-2, -1.87e-2);
+Warnings:
+Warning 1265 Data truncated for column 'c' at row 1
+INSERT INTO t1(a,c) VALUES (5000, 5000);
+INSERT INTO t1(a,c) VALUES (-5000, -5000);
+Warnings:
+Warning 1265 Data truncated for column 'c' at row 1
+SELECT * FROM t1;
+a b c
+1.225e-05 1.2e-05 NULL
+0.0001225 0.00012 NULL
+0.122499999999999998 0.1225 NULL
+0.122587699999999994 0.12259 NULL
+12.25 12.25 NULL
+12.25 12.25 12.2
+122500 122500 NULL
+12250000000 1.2e+10 NULL
+1225000000000000 1.2e+15 NULL
+5000000 5000000 NULL
+1.225000000000000089 NULL 1.23
+1.370000000000000107 NULL 1.37
+-1.37 NULL -1.3
+0.00187 NULL 0.00
+-0.0187 NULL -0.0
+5000 NULL 5000
+-5000 NULL -500
+DROP TABLE t1;
--- 1.21/mysql-test/t/insert.test 2007-03-30 00:53:05 -07:00
+++ 1.22/mysql-test/t/insert.test 2007-03-30 00:53:05 -07:00
@@ -155,4 +155,36 @@
drop table t1;
--enable_ps_protocol
+#
+# Bug #26788: insert a double literal into a char field
+#
+
+CREATE TABLE t1 (
+ a char(20) NOT NULL,
+ b char(7) DEFAULT NULL,
+ c char(4) DEFAULT NULL
+);
+
+INSERT INTO t1(a,b) VALUES (1.225e-05, 1.225e-05);
+INSERT INTO t1(a,b) VALUES (1.225e-04, 1.225e-04);
+INSERT INTO t1(a,b) VALUES (1.225e-01, 1.225e-01);
+INSERT INTO t1(a,b) VALUES (1.225877e-01, 1.225877e-01);
+INSERT INTO t1(a,b) VALUES (1.225e+01, 1.225e+01);
+INSERT INTO t1(a,b,c) VALUES (1.225e+01, 1.225e+01, 1.225e+01);
+INSERT INTO t1(a,b) VALUES (1.225e+05, 1.225e+05);
+INSERT INTO t1(a,b) VALUES (1.225e+10, 1.225e+10);
+INSERT INTO t1(a,b) VALUES (1.225e+15, 1.225e+15);
+INSERT INTO t1(a,b) VALUES (5000000, 5000000);
+INSERT INTO t1(a,c) VALUES (1.225, 1.225);
+INSERT INTO t1(a,c) VALUES (1.37, 1.37);
+INSERT INTO t1(a,c) VALUES (-1.37, -1.37);
+INSERT INTO t1(a,c) VALUES (1.87e-3, 1.87e-3);
+INSERT INTO t1(a,c) VALUES (-1.87e-2, -1.87e-2);
+INSERT INTO t1(a,c) VALUES (5000, 5000);
+INSERT INTO t1(a,c) VALUES (-5000, -5000);
+
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
# End of 4.1 tests
| Thread |
|---|
| • bk commit into 4.1 tree (igor:1.2623) BUG#26788 | igor | 30 Mar |