Skip to content

Commit dff820c

Browse files
committed
fix precision when fetching float through mysqlnd
fixes failing ext/mysqli/tests/010.phpt
1 parent 3b78a24 commit dff820c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ext/mysqlnd/mysqlnd_ps_codec.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,27 @@ ps_fetch_float(zval * zv, const MYSQLND_FIELD * const field, unsigned int pack_l
200200
/* The following cast is guaranteed to do the right thing */
201201
dval = (double) d32val;
202202
}
203+
#elif defined(PHP_WIN32)
204+
{
205+
/* float datatype on Winows is already 4 byte but has a precision of 7 digits */
206+
char num_buf[2048];
207+
(void)_gcvt_s(num_buf, 2048, fval, field->decimals >= 31 ? 7 : field->decimals);
208+
dval = zend_strtod(num_buf, NULL);
209+
}
203210
#else
204211
{
205212
char num_buf[2048]; /* Over allocated */
206213
char *s;
207214

215+
#ifndef FLT_DIG
216+
# define FLT_DIG 6
217+
#endif
208218
/* Convert to string. Ignoring localization, etc.
209219
* Following MySQL's rules. If precision is undefined (NOT_FIXED_DEC i.e. 31)
210220
* or larger than 31, the value is limited to 6 (FLT_DIG).
211221
*/
212222
s = php_gcvt(fval,
213-
field->decimals >= 31 ? 6 : field->decimals,
223+
field->decimals >= 31 ? FLT_DIG : field->decimals,
214224
'.',
215225
'e',
216226
num_buf);

0 commit comments

Comments
 (0)