Skip to content

Commit 13c77db

Browse files
committed
Factor out result @query_options into a separate function.
1 parent aa88da4 commit 13c77db

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

ext/mysql2/result.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,6 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, MYSQL_FIELD * fields, const r
511511
{
512512
VALUE rowVal;
513513
MYSQL_ROW row;
514-
MYSQL_FIELD * fields;
515514
unsigned int i = 0;
516515
unsigned long * fieldLengths;
517516
void * ptr;
@@ -759,6 +758,37 @@ static VALUE rb_mysql_result_fetch_fields(VALUE self) {
759758
return wrapper->fields;
760759
}
761760

761+
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) {
762+
ID dbTz, appTz;
763+
764+
*symbolizeKeys = RTEST(rb_hash_aref(opts, sym_symbolize_keys));
765+
*asArray = rb_hash_aref(opts, sym_as) == sym_array;
766+
*castBool = RTEST(rb_hash_aref(opts, sym_cast_booleans));
767+
*cacheRows = RTEST(rb_hash_aref(opts, sym_cache_rows));
768+
*cast = RTEST(rb_hash_aref(opts, sym_cast));
769+
770+
dbTz = rb_hash_aref(opts, sym_database_timezone);
771+
if (dbTz == sym_local) {
772+
*db_timezone = intern_local;
773+
} else if (dbTz == sym_utc) {
774+
*db_timezone = intern_utc;
775+
} else {
776+
if (!NIL_P(dbTz)) {
777+
rb_warn(":database_timezone option must be :utc or :local - defaulting to :local");
778+
}
779+
*db_timezone = intern_local;
780+
}
781+
782+
appTz = rb_hash_aref(opts, sym_application_timezone);
783+
if (appTz == sym_local) {
784+
*app_timezone = intern_local;
785+
} else if (appTz == sym_utc) {
786+
*app_timezone = intern_utc;
787+
} else {
788+
*app_timezone = Qnil;
789+
}
790+
}
791+
762792
static VALUE rb_mysql_result_each_(VALUE self,
763793
VALUE(*fetch_row_func)(VALUE, MYSQL_FIELD *fields, const result_each_args *args),
764794
const result_each_args *args)

0 commit comments

Comments
 (0)