1
0
mirror of https://github.com/php/php-src.git synced 2026-04-23 16:08:35 +02:00

fix precision when fetching float through mysqlnd

fixes failing ext/mysqli/tests/010.phpt
This commit is contained in:
Anatol Belski
2014-09-10 19:29:11 +02:00
parent 3b78a24ee9
commit dff820cea3
+11 -1
View File
@@ -200,17 +200,27 @@ ps_fetch_float(zval * zv, const MYSQLND_FIELD * const field, unsigned int pack_l
/* The following cast is guaranteed to do the right thing */
dval = (double) d32val;
}
#elif defined(PHP_WIN32)
{
/* float datatype on Winows is already 4 byte but has a precision of 7 digits */
char num_buf[2048];
(void)_gcvt_s(num_buf, 2048, fval, field->decimals >= 31 ? 7 : field->decimals);
dval = zend_strtod(num_buf, NULL);
}
#else
{
char num_buf[2048]; /* Over allocated */
char *s;
#ifndef FLT_DIG
# define FLT_DIG 6
#endif
/* Convert to string. Ignoring localization, etc.
* Following MySQL's rules. If precision is undefined (NOT_FIXED_DEC i.e. 31)
* or larger than 31, the value is limited to 6 (FLT_DIG).
*/
s = php_gcvt(fval,
field->decimals >= 31 ? 6 : field->decimals,
field->decimals >= 31 ? FLT_DIG : field->decimals,
'.',
'e',
num_buf);