Skip to content

Commit afaa514

Browse files
committed
Move mysql_fetch_fields closer to point of use.
1 parent 4e769bb commit afaa514

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

ext/mysql2/result.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,11 @@ static VALUE mysql2_set_field_string_encoding(VALUE val, MYSQL_FIELD field, rb_e
181181
#endif
182182

183183

184-
static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezone, int symbolizeKeys, int asArray, int castBool, int cast, MYSQL_FIELD * fields) {
184+
static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezone, int symbolizeKeys, int asArray, int castBool, int cast) {
185185
VALUE rowVal;
186186
mysql2_result_wrapper * wrapper;
187187
MYSQL_ROW row;
188+
MYSQL_FIELD * fields;
188189
unsigned int i = 0;
189190
unsigned long * fieldLengths;
190191
void * ptr;
@@ -216,6 +217,9 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
216217
wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
217218
}
218219

220+
/* get the MySQL field types to convert to Ruby field types */
221+
fields = mysql_fetch_fields(wrapper->result);
222+
219223
for (i = 0; i < wrapper->numberOfFields; i++) {
220224
VALUE field = rb_mysql_result_fetch_field(self, i, symbolizeKeys);
221225
if (row[i]) {
@@ -500,10 +504,8 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
500504
if(!wrapper->streamingComplete) {
501505
VALUE row;
502506

503-
fields = mysql_fetch_fields(wrapper->result);
504-
505507
do {
506-
row = rb_mysql_result_fetch_row(self, db_timezone, app_timezone, symbolizeKeys, asArray, castBool, cast, fields);
508+
row = rb_mysql_result_fetch_row(self, db_timezone, app_timezone, symbolizeKeys, asArray, castBool, cast);
507509

508510
if (block != Qnil && row != Qnil) {
509511
rb_yield(row);
@@ -528,14 +530,13 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
528530
} else {
529531
unsigned long rowsProcessed = 0;
530532
rowsProcessed = RARRAY_LEN(wrapper->rows);
531-
fields = mysql_fetch_fields(wrapper->result);
532533

533534
for (i = 0; i < wrapper->numberOfRows; i++) {
534535
VALUE row;
535536
if (cacheRows && i < rowsProcessed) {
536537
row = rb_ary_entry(wrapper->rows, i);
537538
} else {
538-
row = rb_mysql_result_fetch_row(self, db_timezone, app_timezone, symbolizeKeys, asArray, castBool, cast, fields);
539+
row = rb_mysql_result_fetch_row(self, db_timezone, app_timezone, symbolizeKeys, asArray, castBool, cast);
539540
if (cacheRows) {
540541
rb_ary_store(wrapper->rows, i, row);
541542
}

0 commit comments

Comments
 (0)