Skip to content

Commit e78d496

Browse files
committed
Make the result.count return type consistent and match the source type
numberOfRows is a platform unsigned long Ruby array lenth is a platform signed long mysql_num_rows returns an unsigned 64-bit long
1 parent 5ae03be commit e78d496

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ext/mysql2/result.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,13 +595,16 @@ static VALUE rb_mysql_result_count(VALUE self) {
595595

596596
GetMysql2Result(self, wrapper);
597597
if (wrapper->is_streaming) {
598-
return LONG2NUM(wrapper->numberOfRows);
598+
/* This is an unsigned long per result.h */
599+
return ULONG2NUM(wrapper->numberOfRows);
599600
}
600601

601602
if (wrapper->resultFreed) {
603+
/* Ruby arrays have platform signed long length */
602604
return LONG2NUM(RARRAY_LEN(wrapper->rows));
603605
} else {
604-
return INT2FIX(mysql_num_rows(wrapper->result));
606+
/* MySQL returns an unsigned 64-bit long here */
607+
return ULL2NUM(mysql_num_rows(wrapper->result));
605608
}
606609
}
607610

0 commit comments

Comments
 (0)