@@ -30,14 +30,15 @@ typedef struct {
30
30
int streaming ;
31
31
ID db_timezone ;
32
32
ID app_timezone ;
33
- VALUE block_given ;
33
+ int block_given ; /* boolean */
34
34
} result_each_args ;
35
35
36
36
extern VALUE mMysql2 , cMysql2Client , cMysql2Error ;
37
37
static VALUE cMysql2Result , cDateTime , cDate ;
38
38
static VALUE opt_decimal_zero , opt_float_zero , opt_time_year , opt_time_month , opt_utc_offset ;
39
39
static ID intern_new , intern_utc , intern_local , intern_localtime , intern_local_offset ,
40
- intern_civil , intern_new_offset , intern_merge , intern_BigDecimal ;
40
+ intern_civil , intern_new_offset , intern_merge , intern_BigDecimal ,
41
+ intern_query_options ;
41
42
static VALUE sym_symbolize_keys , sym_as , sym_array , sym_database_timezone ,
42
43
sym_application_timezone , sym_local , sym_utc , sym_cast_booleans ,
43
44
sym_cache_rows , sym_cast , sym_stream , sym_name ;
@@ -695,7 +696,7 @@ static VALUE rb_mysql_result_fetch_fields(VALUE self) {
695
696
696
697
GET_RESULT (self );
697
698
698
- defaults = rb_iv_get (self , "@query_options" );
699
+ defaults = rb_ivar_get (self , intern_query_options );
699
700
Check_Type (defaults , T_HASH );
700
701
if (rb_hash_aref (defaults , sym_symbolize_keys ) == Qtrue ) {
701
702
symbolizeKeys = 1 ;
@@ -740,7 +741,7 @@ static VALUE rb_mysql_result_each_(VALUE self,
740
741
row = fetch_row_func (self , fields , args );
741
742
if (row != Qnil ) {
742
743
wrapper -> numberOfRows ++ ;
743
- if (args -> block_given != Qnil ) {
744
+ if (args -> block_given ) {
744
745
rb_yield (row );
745
746
}
746
747
}
@@ -790,7 +791,7 @@ static VALUE rb_mysql_result_each_(VALUE self,
790
791
return Qnil ;
791
792
}
792
793
793
- if (args -> block_given != Qnil ) {
794
+ if (args -> block_given ) {
794
795
rb_yield (row );
795
796
}
796
797
}
@@ -808,7 +809,7 @@ static VALUE rb_mysql_result_each_(VALUE self,
808
809
809
810
static VALUE rb_mysql_result_each (int argc , VALUE * argv , VALUE self ) {
810
811
result_each_args args ;
811
- VALUE defaults , opts , block , (* fetch_row_func )(VALUE , MYSQL_FIELD * fields , const result_each_args * args );
812
+ VALUE defaults , opts , (* fetch_row_func )(VALUE , MYSQL_FIELD * fields , const result_each_args * args );
812
813
ID db_timezone , app_timezone , dbTz , appTz ;
813
814
int symbolizeKeys , asArray , castBool , cacheRows , cast ;
814
815
@@ -818,9 +819,12 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
818
819
rb_raise (cMysql2Error , "Statement handle already closed" );
819
820
}
820
821
821
- defaults = rb_iv_get (self , "@query_options" );
822
+ defaults = rb_ivar_get (self , intern_query_options );
822
823
Check_Type (defaults , T_HASH );
823
- if (rb_scan_args (argc , argv , "01&" , & opts , & block ) == 1 ) {
824
+
825
+ // A block can be passed to this method, but since we don't call the block directly from C,
826
+ // we don't need to capture it into a variable here with the "&" scan arg.
827
+ if (rb_scan_args (argc , argv , "01" , & opts ) == 1 ) {
824
828
opts = rb_funcall (defaults , intern_merge , 1 , opts );
825
829
} else {
826
830
opts = defaults ;
@@ -886,7 +890,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
886
890
args .cast = cast ;
887
891
args .db_timezone = db_timezone ;
888
892
args .app_timezone = app_timezone ;
889
- args .block_given = block ;
893
+ args .block_given = rb_block_given_p () ;
890
894
891
895
if (wrapper -> stmt_wrapper ) {
892
896
fetch_row_func = rb_mysql_result_fetch_row_stmt ;
@@ -951,7 +955,7 @@ VALUE rb_mysql_result_to_obj(VALUE client, VALUE encoding, VALUE options, MYSQL_
951
955
}
952
956
953
957
rb_obj_call_init (obj , 0 , NULL );
954
- rb_iv_set (obj , "@query_options" , options );
958
+ rb_ivar_set (obj , intern_query_options , options );
955
959
956
960
/* Options that cannot be changed in results.each(...) { |row| }
957
961
* should be processed here. */
@@ -980,6 +984,7 @@ void init_mysql2_result() {
980
984
intern_civil = rb_intern ("civil" );
981
985
intern_new_offset = rb_intern ("new_offset" );
982
986
intern_BigDecimal = rb_intern ("BigDecimal" );
987
+ intern_query_options = rb_intern ("@query_options" );
983
988
984
989
sym_symbolize_keys = ID2SYM (rb_intern ("symbolize_keys" ));
985
990
sym_as = ID2SYM (rb_intern ("as" ));
0 commit comments