@@ -446,7 +446,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
446
446
mysql2_result_wrapper * wrapper ;
447
447
unsigned long i ;
448
448
const char * errstr ;
449
- int symbolizeKeys = 0 , asArray = 0 , castBool = 0 , cacheRows = 1 , cast = 1 , streaming = 0 ;
449
+ int symbolizeKeys = 0 , asArray = 0 , castBool = 0 , cacheRows = 1 , cast = 1 ;
450
450
MYSQL_FIELD * fields = NULL ;
451
451
452
452
GetMysql2Result (self , wrapper );
@@ -479,11 +479,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
479
479
cast = 0 ;
480
480
}
481
481
482
- if (rb_hash_aref (opts , sym_stream ) == Qtrue ) {
483
- streaming = 1 ;
484
- }
485
-
486
- if (streaming && cacheRows ) {
482
+ if (wrapper -> is_streaming && cacheRows ) {
487
483
rb_warn ("cacheRows is ignored if streaming is true" );
488
484
}
489
485
@@ -509,7 +505,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
509
505
}
510
506
511
507
if (wrapper -> lastRowProcessed == 0 ) {
512
- if (streaming ) {
508
+ if (wrapper -> is_streaming ) {
513
509
/* We can't get number of rows if we're streaming, */
514
510
/* until we've finished fetching all rows */
515
511
wrapper -> numberOfRows = 0 ;
@@ -524,7 +520,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
524
520
}
525
521
}
526
522
527
- if (streaming ) {
523
+ if (wrapper -> is_streaming ) {
528
524
if (!wrapper -> streamingComplete ) {
529
525
VALUE row ;
530
526
@@ -601,12 +597,12 @@ static VALUE rb_mysql_result_count(VALUE self) {
601
597
mysql2_result_wrapper * wrapper ;
602
598
603
599
GetMysql2Result (self , wrapper );
600
+ if (wrapper -> is_streaming ) {
601
+ return LONG2NUM (wrapper -> numberOfRows );
602
+ }
603
+
604
604
if (wrapper -> resultFreed ) {
605
- if (wrapper -> streamingComplete ){
606
- return LONG2NUM (wrapper -> numberOfRows );
607
- } else {
608
- return LONG2NUM (RARRAY_LEN (wrapper -> rows ));
609
- }
605
+ return LONG2NUM (RARRAY_LEN (wrapper -> rows ));
610
606
} else {
611
607
return INT2FIX (mysql_num_rows (wrapper -> result ));
612
608
}
@@ -634,6 +630,10 @@ VALUE rb_mysql_result_to_obj(VALUE client, VALUE encoding, VALUE options, MYSQL_
634
630
635
631
rb_iv_set (obj , "@query_options" , options );
636
632
633
+ /* Options that cannot be changed in results.each(...) { |row| }
634
+ * should be processed here. */
635
+ wrapper -> is_streaming = (rb_hash_aref (options , sym_stream ) == Qtrue ? 1 : 0 );
636
+
637
637
return obj ;
638
638
}
639
639
0 commit comments