Skip to content

Commit a099e55

Browse files
committed
Cast MYSQL_TYPE_DECIMAL AND MYSQL_TYPE_NEWDECIMAL to integer if number of decimals is 0
Otherwise aggregate functions like SUM will produce decimals even when summing integers
1 parent 450978e commit a099e55

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ext/mysql2/result.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
237237
break;
238238
case MYSQL_TYPE_DECIMAL: // DECIMAL or NUMERIC field
239239
case MYSQL_TYPE_NEWDECIMAL: // Precision math DECIMAL or NUMERIC field (MySQL 5.0.3 and up)
240-
if (strtod(row[i], NULL) == 0.000000){
240+
if (fields[i].decimals == 0) {
241+
val = rb_cstr2inum(row[i], 10);
242+
} else if (strtod(row[i], NULL) == 0.000000){
241243
val = rb_funcall(cBigDecimal, intern_new, 1, opt_decimal_zero);
242244
}else{
243245
val = rb_funcall(cBigDecimal, intern_new, 1, rb_str_new(row[i], fieldLengths[i]));

0 commit comments

Comments
 (0)