@@ -755,50 +755,60 @@ static VALUE rb_mysql_result_fetch_fields(VALUE self) {
755
755
return wrapper -> fields ;
756
756
}
757
757
758
- static void rb_mysql_row_query_options (VALUE opts , ID * db_timezone , ID * app_timezone , int * symbolizeKeys , int * asArray , int * castBool , int * cast , int * cacheRows ) {
758
+ static result_each_args rb_mysql_row_query_options (VALUE self , VALUE opts ) {
759
759
ID dbTz , appTz ;
760
+ VALUE defaults ;
761
+ result_each_args args ;
762
+
763
+ defaults = rb_iv_get (self , "@query_options" );
764
+ Check_Type (defaults , T_HASH );
765
+ if (!NIL_P (opts )) {
766
+ opts = rb_funcall (defaults , intern_merge , 1 , opts );
767
+ } else {
768
+ opts = defaults ;
769
+ }
760
770
761
- * symbolizeKeys = RTEST (rb_hash_aref (opts , sym_symbolize_keys ));
762
- * asArray = rb_hash_aref (opts , sym_as ) == sym_array ;
763
- * castBool = RTEST (rb_hash_aref (opts , sym_cast_booleans ));
764
- * cacheRows = RTEST (rb_hash_aref (opts , sym_cache_rows ));
765
- * cast = RTEST (rb_hash_aref (opts , sym_cast ));
771
+ args .symbolizeKeys = RTEST (rb_hash_aref (opts , sym_symbolize_keys ));
772
+ args .asArray = rb_hash_aref (opts , sym_as ) == sym_array ;
773
+ args .castBool = RTEST (rb_hash_aref (opts , sym_cast_booleans ));
774
+ args .cacheRows = RTEST (rb_hash_aref (opts , sym_cache_rows ));
775
+ args .cast = RTEST (rb_hash_aref (opts , sym_cast ));
776
+ args .block_given = Qnil ;
766
777
767
778
dbTz = rb_hash_aref (opts , sym_database_timezone );
768
779
if (dbTz == sym_local ) {
769
- * db_timezone = intern_local ;
780
+ args . db_timezone = intern_local ;
770
781
} else if (dbTz == sym_utc ) {
771
- * db_timezone = intern_utc ;
782
+ args . db_timezone = intern_utc ;
772
783
} else {
773
784
if (!NIL_P (dbTz )) {
774
785
rb_warn (":database_timezone option must be :utc or :local - defaulting to :local" );
775
786
}
776
- * db_timezone = intern_local ;
787
+ args . db_timezone = intern_local ;
777
788
}
778
789
779
790
appTz = rb_hash_aref (opts , sym_application_timezone );
780
791
if (appTz == sym_local ) {
781
- * app_timezone = intern_local ;
792
+ args . app_timezone = intern_local ;
782
793
} else if (appTz == sym_utc ) {
783
- * app_timezone = intern_utc ;
794
+ args . app_timezone = intern_utc ;
784
795
} else {
785
- * app_timezone = Qnil ;
796
+ args . app_timezone = Qnil ;
786
797
}
798
+
799
+ return args ;
787
800
}
788
801
789
802
static VALUE rb_mysql_result_element (int argc , VALUE * argv , VALUE self ) {
790
803
result_each_args args ;
791
804
MYSQL_FIELD * fields = NULL ;
792
- ID db_timezone , app_timezone ;
793
805
VALUE seek , count , row , rows ;
794
806
long i , c_seek , c_count = 0 ;
795
- int symbolizeKeys , asArray , castBool , cacheRows , cast ;
796
- VALUE defaults , block , opts , ( * fetch_row_func )( VALUE , MYSQL_FIELD * fields , const result_each_args * args ) ;
807
+ VALUE ( * fetch_row_func )( VALUE , MYSQL_FIELD * fields , const result_each_args * args ) ;
808
+ VALUE block , opts ;
797
809
798
810
GET_RESULT (self );
799
811
800
- defaults = rb_iv_get (self , "@query_options" );
801
- Check_Type (defaults , T_HASH );
802
812
rb_scan_args (argc , argv , "12&" , & seek , & count , & opts , & block );
803
813
804
814
/* If the second arg is a hash, it's the opts and there's no count */
@@ -814,13 +824,8 @@ static VALUE rb_mysql_result_element(int argc, VALUE * argv, VALUE self) {
814
824
if (!c_count ) return rb_ary_new ();
815
825
}
816
826
817
- if (!NIL_P (opts )) {
818
- opts = rb_funcall (defaults , intern_merge , 1 , opts );
819
- } else {
820
- opts = defaults ;
821
- }
822
-
823
- rb_mysql_row_query_options (opts , & db_timezone , & app_timezone , & symbolizeKeys , & asArray , & castBool , & cast , & cacheRows );
827
+ args = rb_mysql_row_query_options (self , opts );
828
+ args .block_given = block ;
824
829
825
830
if (wrapper -> is_streaming ) {
826
831
rb_raise (cMysql2Error , "Element reference operator #[] cannot be used in streaming mode." );
@@ -848,16 +853,7 @@ static VALUE rb_mysql_result_element(int argc, VALUE * argv, VALUE self) {
848
853
}
849
854
850
855
mysql_data_seek (wrapper -> result , c_seek );
851
-
852
- // Backward compat
853
- args .symbolizeKeys = symbolizeKeys ;
854
- args .asArray = asArray ;
855
- args .castBool = castBool ;
856
- args .cacheRows = cacheRows ;
857
- args .cast = cast ;
858
- args .db_timezone = db_timezone ;
859
- args .app_timezone = app_timezone ;
860
- args .block_given = block ;
856
+ fields = mysql_fetch_fields (wrapper -> result );
861
857
862
858
if (wrapper -> stmt ) {
863
859
fetch_row_func = rb_mysql_result_fetch_row_stmt ;
@@ -974,21 +970,14 @@ static VALUE rb_mysql_result_each_(VALUE self,
974
970
975
971
static VALUE rb_mysql_result_each (int argc , VALUE * argv , VALUE self ) {
976
972
result_each_args args ;
977
- VALUE defaults , opts , block , (* fetch_row_func )(VALUE , MYSQL_FIELD * fields , const result_each_args * args );
978
- ID db_timezone , app_timezone ;
979
- int symbolizeKeys , asArray , castBool , cacheRows , cast ;
973
+ VALUE (* fetch_row_func )(VALUE , MYSQL_FIELD * fields , const result_each_args * args );
974
+ VALUE opts , block ;
980
975
981
976
GET_RESULT (self );
982
977
983
- defaults = rb_iv_get (self , "@query_options" );
984
- Check_Type (defaults , T_HASH );
985
- if (rb_scan_args (argc , argv , "01&" , & opts , & block ) == 1 ) {
986
- opts = rb_funcall (defaults , intern_merge , 1 , opts );
987
- } else {
988
- opts = defaults ;
989
- }
990
-
991
- rb_mysql_row_query_options (opts , & db_timezone , & app_timezone , & symbolizeKeys , & asArray , & castBool , & cast , & cacheRows );
978
+ rb_scan_args (argc , argv , "01&" , & opts , & block );
979
+ args = rb_mysql_row_query_options (self , opts );
980
+ args .block_given = block ;
992
981
993
982
if (wrapper -> lastRowProcessed == 0 && !wrapper -> is_streaming ) {
994
983
wrapper -> numberOfRows = wrapper -> stmt ? mysql_stmt_num_rows (wrapper -> stmt ) : mysql_num_rows (wrapper -> result );
@@ -999,16 +988,6 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
999
988
wrapper -> rows = rb_ary_new2 (wrapper -> numberOfRows );
1000
989
}
1001
990
1002
- // Backward compat
1003
- args .symbolizeKeys = symbolizeKeys ;
1004
- args .asArray = asArray ;
1005
- args .castBool = castBool ;
1006
- args .cacheRows = cacheRows ;
1007
- args .cast = cast ;
1008
- args .db_timezone = db_timezone ;
1009
- args .app_timezone = app_timezone ;
1010
- args .block_given = block ;
1011
-
1012
991
if (wrapper -> stmt ) {
1013
992
fetch_row_func = rb_mysql_result_fetch_row_stmt ;
1014
993
} else {
0 commit comments