Fix for bugs #68114 (Build fails on OS X due to undefined symbols)

and #68657 (Reading 4 byte floats with Mysqli and libmysqlclient
has rounding errors).

The patch removes support for Decimal floating point numbers and
now defaults to using similar logic as what libmysqlclient does:
convert a 4 byte floating point number into a string, and then the
string into a double. The quirks of MySQL are maintained as seen in
Field_Float::val_str()
This commit is contained in:
Keyur Govande 2015-01-06 06:33:38 +00:00
parent 3f1d1892c9
commit f2eadb93b9
9 changed files with 140 additions and 90 deletions

View file

@ -33,6 +33,7 @@
#include "ext/standard/php_smart_str.h"
#include "php_mysqli_structs.h"
#include "mysqli_priv.h"
#include "ext/standard/float_to_double.h"
#if !defined(MYSQLI_USE_MYSQLND)
@ -413,8 +414,18 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc,
col_type = (stmt->stmt->fields) ? stmt->stmt->fields[ofs].type : MYSQL_TYPE_STRING;
switch (col_type) {
case MYSQL_TYPE_DOUBLE:
case MYSQL_TYPE_FLOAT:
convert_to_double_ex(args[i]);
stmt->result.buf[ofs].type = IS_DOUBLE;
stmt->result.buf[ofs].buflen = sizeof(float);
stmt->result.buf[ofs].val = (char *)emalloc(sizeof(float));
bind[ofs].buffer_type = MYSQL_TYPE_FLOAT;
bind[ofs].buffer = stmt->result.buf[ofs].val;
bind[ofs].is_null = &stmt->result.is_null[ofs];
break;
case MYSQL_TYPE_DOUBLE:
convert_to_double_ex(args[i]);
stmt->result.buf[ofs].type = IS_DOUBLE;
stmt->result.buf[ofs].buflen = sizeof(double);
@ -1045,8 +1056,22 @@ void mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAMETERS)
}
break;
case IS_DOUBLE:
ZVAL_DOUBLE(stmt->result.vars[i], *(double *)stmt->result.buf[i].val);
{
double dval;
if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_FLOAT) {
#ifndef NOT_FIXED_DEC
# define NOT_FIXED_DEC 31
#endif
dval = float_to_double(*(float *)stmt->result.buf[i].val,
(stmt->stmt->fields[i].decimals >= NOT_FIXED_DEC) ? -1 :
stmt->stmt->fields[i].decimals);
} else {
dval = *((double *)stmt->result.buf[i].val);
}
ZVAL_DOUBLE(stmt->result.vars[i], dval);
break;
}
case IS_STRING:
if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_LONGLONG
#if MYSQL_VERSION_ID > 50002