respect :symbolize_keys option for Mysql2::Result#fields if it's called before the first row is built

This commit is contained in:
Brian Lopez 2010-08-04 00:54:05 -07:00
parent 923393351a
commit 2bb8721e84

View File

@ -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) { static VALUE rb_mysql_result_fetch_fields(VALUE self) {
mysql2_result_wrapper * wrapper; mysql2_result_wrapper * wrapper;
unsigned int i = 0; unsigned int i = 0;
short int symbolizeKeys = 0;
VALUE defaults;
GetMysql2Result(self, wrapper); 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) { if (wrapper->fields == Qnil) {
wrapper->numberOfFields = mysql_num_fields(wrapper->result); wrapper->numberOfFields = mysql_num_fields(wrapper->result);
wrapper->fields = rb_ary_new2(wrapper->numberOfFields); 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) { if (RARRAY_LEN(wrapper->fields) != wrapper->numberOfFields) {
for (i=0; i<wrapper->numberOfFields; i++) { for (i=0; i<wrapper->numberOfFields; i++) {
rb_mysql_result_fetch_field(self, i, 0); rb_mysql_result_fetch_field(self, i, symbolizeKeys);
} }
} }