@@ -444,9 +444,40 @@ static VALUE rb_mysql_result_fetch_fields(VALUE self) {
444
444
return wrapper -> fields ;
445
445
}
446
446
447
+ 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 ) {
448
+ ID dbTz , appTz ;
449
+
450
+ * symbolizeKeys = RTEST (rb_hash_aref (opts , sym_symbolize_keys ));
451
+ * asArray = rb_hash_aref (opts , sym_as ) == sym_array ;
452
+ * castBool = RTEST (rb_hash_aref (opts , sym_cast_booleans ));
453
+ * cacheRows = RTEST (rb_hash_aref (opts , sym_cache_rows ));
454
+ * cast = RTEST (rb_hash_aref (opts , sym_cast ));
455
+
456
+ dbTz = rb_hash_aref (opts , sym_database_timezone );
457
+ if (dbTz == sym_local ) {
458
+ * db_timezone = intern_local ;
459
+ } else if (dbTz == sym_utc ) {
460
+ * db_timezone = intern_utc ;
461
+ } else {
462
+ if (!NIL_P (dbTz )) {
463
+ rb_warn (":database_timezone option must be :utc or :local - defaulting to :local" );
464
+ }
465
+ * db_timezone = intern_local ;
466
+ }
467
+
468
+ appTz = rb_hash_aref (opts , sym_application_timezone );
469
+ if (appTz == sym_local ) {
470
+ * app_timezone = intern_local ;
471
+ } else if (appTz == sym_utc ) {
472
+ * app_timezone = intern_utc ;
473
+ } else {
474
+ * app_timezone = Qnil ;
475
+ }
476
+ }
477
+
447
478
static VALUE rb_mysql_result_each (int argc , VALUE * argv , VALUE self ) {
448
479
VALUE defaults , opts , block ;
449
- ID db_timezone , app_timezone , dbTz , appTz ;
480
+ ID db_timezone , app_timezone ;
450
481
mysql2_result_wrapper * wrapper ;
451
482
unsigned long i ;
452
483
const char * errstr ;
@@ -461,38 +492,12 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
461
492
} else {
462
493
opts = defaults ;
463
494
}
464
-
465
- symbolizeKeys = RTEST (rb_hash_aref (opts , sym_symbolize_keys ));
466
- asArray = rb_hash_aref (opts , sym_as ) == sym_array ;
467
- castBool = RTEST (rb_hash_aref (opts , sym_cast_booleans ));
468
- cacheRows = RTEST (rb_hash_aref (opts , sym_cache_rows ));
469
- cast = RTEST (rb_hash_aref (opts , sym_cast ));
495
+ rb_mysql_row_query_options (opts , & db_timezone , & app_timezone , & symbolizeKeys , & asArray , & castBool , & cast , & cacheRows );
470
496
471
497
if (wrapper -> is_streaming && cacheRows ) {
472
498
rb_warn ("cacheRows is ignored if streaming is true" );
473
499
}
474
500
475
- dbTz = rb_hash_aref (opts , sym_database_timezone );
476
- if (dbTz == sym_local ) {
477
- db_timezone = intern_local ;
478
- } else if (dbTz == sym_utc ) {
479
- db_timezone = intern_utc ;
480
- } else {
481
- if (!NIL_P (dbTz )) {
482
- rb_warn (":database_timezone option must be :utc or :local - defaulting to :local" );
483
- }
484
- db_timezone = intern_local ;
485
- }
486
-
487
- appTz = rb_hash_aref (opts , sym_application_timezone );
488
- if (appTz == sym_local ) {
489
- app_timezone = intern_local ;
490
- } else if (appTz == sym_utc ) {
491
- app_timezone = intern_utc ;
492
- } else {
493
- app_timezone = Qnil ;
494
- }
495
-
496
501
if (wrapper -> is_streaming ) {
497
502
/* When streaming, we will only yield rows, not return them. */
498
503
if (wrapper -> rows == Qnil ) {
0 commit comments