From 2bb8721e84e2b9b06d15e0d02cf35d92c371be03 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Wed, 4 Aug 2010 00:54:05 -0700 Subject: [PATCH] respect :symbolize_keys option for Mysql2::Result#fields if it's called before the first row is built --- ext/mysql2/result.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ext/mysql2/result.c b/ext/mysql2/result.c index 02f70f0..0801030 100644 --- a/ext/mysql2/result.c +++ b/ext/mysql2/result.c @@ -237,9 +237,16 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID timezone, int symbolizeKey static VALUE rb_mysql_result_fetch_fields(VALUE self) { mysql2_result_wrapper * wrapper; unsigned int i = 0; + short int symbolizeKeys = 0; + VALUE defaults; GetMysql2Result(self, wrapper); + defaults = rb_iv_get(self, "@query_options"); + if (rb_hash_aref(defaults, sym_symbolize_keys) == Qtrue) { + symbolizeKeys = 1; + } + if (wrapper->fields == Qnil) { wrapper->numberOfFields = mysql_num_fields(wrapper->result); wrapper->fields = rb_ary_new2(wrapper->numberOfFields); @@ -247,7 +254,7 @@ static VALUE rb_mysql_result_fetch_fields(VALUE self) { if (RARRAY_LEN(wrapper->fields) != wrapper->numberOfFields) { for (i=0; inumberOfFields; i++) { - rb_mysql_result_fetch_field(self, i, 0); + rb_mysql_result_fetch_field(self, i, symbolizeKeys); } }