Skip to content

Commit 81fd9bc

Browse files
committed
Factor out result @query_options into a separate function.
1 parent d0fef7c commit 81fd9bc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

ext/mysql2/result.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,37 @@ static VALUE rb_mysql_result_fetch_fields(VALUE self) {
755755
return wrapper->fields;
756756
}
757757

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) {
759+
ID dbTz, appTz;
760+
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));
766+
767+
dbTz = rb_hash_aref(opts, sym_database_timezone);
768+
if (dbTz == sym_local) {
769+
*db_timezone = intern_local;
770+
} else if (dbTz == sym_utc) {
771+
*db_timezone = intern_utc;
772+
} else {
773+
if (!NIL_P(dbTz)) {
774+
rb_warn(":database_timezone option must be :utc or :local - defaulting to :local");
775+
}
776+
*db_timezone = intern_local;
777+
}
778+
779+
appTz = rb_hash_aref(opts, sym_application_timezone);
780+
if (appTz == sym_local) {
781+
*app_timezone = intern_local;
782+
} else if (appTz == sym_utc) {
783+
*app_timezone = intern_utc;
784+
} else {
785+
*app_timezone = Qnil;
786+
}
787+
}
788+
758789
static VALUE rb_mysql_result_each_(VALUE self,
759790
VALUE(*fetch_row_func)(VALUE, MYSQL_FIELD *fields, const result_each_args *args),
760791
const result_each_args *args)

0 commit comments

Comments
 (0)