Skip to content

Commit 84d6c0b

Browse files
committed
Refactor how options and encoding are passed from Client to Result
1 parent ec9b61c commit 84d6c0b

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

ext/mysql2/client.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,6 @@ static VALUE nogvl_use_result(void *ptr) {
364364
static VALUE rb_mysql_client_async_result(VALUE self) {
365365
MYSQL_RES * result;
366366
VALUE resultObj;
367-
#ifdef HAVE_RUBY_ENCODING_H
368-
mysql2_result_wrapper * result_wrapper;
369-
#endif
370367
GET_CLIENT(self);
371368

372369
/* if we're not waiting on a result, do nothing */
@@ -396,14 +393,7 @@ static VALUE rb_mysql_client_async_result(VALUE self) {
396393
return Qnil;
397394
}
398395

399-
resultObj = rb_mysql_result_to_obj(self, result);
400-
/* pass-through query options for result construction later */
401-
rb_iv_set(resultObj, "@query_options", rb_hash_dup(rb_iv_get(self, "@current_query_options")));
402-
403-
#ifdef HAVE_RUBY_ENCODING_H
404-
GetMysql2Result(resultObj, result_wrapper);
405-
result_wrapper->encoding = wrapper->encoding;
406-
#endif
396+
resultObj = rb_mysql_result_to_obj(self, wrapper->encoding, rb_hash_dup(rb_iv_get(self, "@current_query_options")), result);
407397
return resultObj;
408398
}
409399

@@ -929,10 +919,6 @@ static VALUE rb_mysql_client_store_result(VALUE self)
929919
{
930920
MYSQL_RES * result;
931921
VALUE resultObj;
932-
#ifdef HAVE_RUBY_ENCODING_H
933-
mysql2_result_wrapper * result_wrapper;
934-
#endif
935-
936922
GET_CLIENT(self);
937923

938924
result = (MYSQL_RES *)rb_thread_blocking_region(nogvl_store_result, wrapper, RUBY_UBF_IO, 0);
@@ -945,14 +931,7 @@ static VALUE rb_mysql_client_store_result(VALUE self)
945931
return Qnil;
946932
}
947933

948-
resultObj = rb_mysql_result_to_obj(self, result);
949-
/* pass-through query options for result construction later */
950-
rb_iv_set(resultObj, "@query_options", rb_hash_dup(rb_iv_get(self, "@current_query_options")));
951-
952-
#ifdef HAVE_RUBY_ENCODING_H
953-
GetMysql2Result(resultObj, result_wrapper);
954-
result_wrapper->encoding = wrapper->encoding;
955-
#endif
934+
resultObj = rb_mysql_result_to_obj(self, wrapper->encoding, rb_hash_dup(rb_iv_get(self, "@current_query_options")), result);
956935
return resultObj;
957936

958937
}

ext/mysql2/result.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static VALUE rb_mysql_result_count(VALUE self) {
573573
}
574574

575575
/* Mysql2::Result */
576-
VALUE rb_mysql_result_to_obj(VALUE client, MYSQL_RES *r) {
576+
VALUE rb_mysql_result_to_obj(VALUE client, VALUE encoding, VALUE options, MYSQL_RES *r) {
577577
VALUE obj;
578578
mysql2_result_wrapper * wrapper;
579579
obj = Data_Make_Struct(cMysql2Result, mysql2_result_wrapper, rb_mysql_result_mark, rb_mysql_result_free, wrapper);
@@ -584,13 +584,16 @@ VALUE rb_mysql_result_to_obj(VALUE client, MYSQL_RES *r) {
584584
wrapper->result = r;
585585
wrapper->fields = Qnil;
586586
wrapper->rows = Qnil;
587-
wrapper->encoding = Qnil;
587+
wrapper->encoding = encoding;
588588
wrapper->streamingComplete = 0;
589589
wrapper->client = client;
590590
wrapper->client_wrapper = DATA_PTR(client);
591591
wrapper->client_wrapper->refcount++;
592592

593593
rb_obj_call_init(obj, 0, NULL);
594+
595+
rb_iv_set(obj, "@query_options", options);
596+
594597
return obj;
595598
}
596599

ext/mysql2/result.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define MYSQL2_RESULT_H
33

44
void init_mysql2_result();
5-
VALUE rb_mysql_result_to_obj(VALUE client, MYSQL_RES * r);
5+
VALUE rb_mysql_result_to_obj(VALUE client, VALUE encoding, VALUE options, MYSQL_RES *r);
66

77
typedef struct {
88
VALUE fields;

0 commit comments

Comments
 (0)