Skip to content

Commit ec574ee

Browse files
tamirdsodabrew
authored andcommitted
client.c need not know about @query_options
1 parent 80eb5c9 commit ec574ee

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

ext/mysql2/client.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -642,40 +642,30 @@ static VALUE rb_mysql_client_abandon_results(VALUE self) {
642642
* Query the database with +sql+, with optional +options+. For the possible
643643
* options, see @@default_query_options on the Mysql2::Client class.
644644
*/
645-
static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
645+
static VALUE rb_query(VALUE self, VALUE sql, VALUE current) {
646646
#ifndef _WIN32
647647
struct async_query_args async_args;
648648
#endif
649649
struct nogvl_send_query_args args;
650650
int async = 0;
651-
VALUE opts, current;
652651
VALUE thread_current = rb_thread_current();
653-
#ifdef HAVE_RUBY_ENCODING_H
654-
rb_encoding *conn_enc;
655-
#endif
656652
GET_CLIENT(self);
657653

658654
REQUIRE_CONNECTED(wrapper);
659655
args.mysql = wrapper->client;
660656

661-
current = rb_hash_dup(rb_iv_get(self, "@query_options"));
662657
RB_GC_GUARD(current);
663658
Check_Type(current, T_HASH);
664659
rb_iv_set(self, "@current_query_options", current);
665660

666-
if (rb_scan_args(argc, argv, "11", &args.sql, &opts) == 2) {
667-
rb_funcall(current, intern_merge_bang, 1, opts);
668-
669-
if (rb_hash_aref(current, sym_async) == Qtrue) {
670-
async = 1;
671-
}
672-
}
661+
async = rb_hash_aref(current, sym_async) == Qtrue;
673662

674-
Check_Type(args.sql, T_STRING);
663+
Check_Type(sql, T_STRING);
675664
#ifdef HAVE_RUBY_ENCODING_H
676-
conn_enc = rb_to_encoding(wrapper->encoding);
677665
/* ensure the string is in the encoding the connection is expecting */
678-
args.sql = rb_str_export_to_enc(args.sql, conn_enc);
666+
args.sql = rb_str_export_to_enc(sql, rb_to_encoding(wrapper->encoding));
667+
#else
668+
args.sql = sql;
679669
#endif
680670
args.sql_ptr = RSTRING_PTR(args.sql);
681671
args.sql_len = RSTRING_LEN(args.sql);
@@ -1279,7 +1269,6 @@ void init_mysql2_client() {
12791269
rb_define_method(cMysql2Client, "encoding", rb_mysql_client_encoding, 0);
12801270
#endif
12811271

1282-
rb_define_private_method(cMysql2Client, "_query", rb_mysql_client_query, -1);
12831272
rb_define_private_method(cMysql2Client, "connect_timeout=", set_connect_timeout, 1);
12841273
rb_define_private_method(cMysql2Client, "read_timeout=", set_read_timeout, 1);
12851274
rb_define_private_method(cMysql2Client, "write_timeout=", set_write_timeout, 1);
@@ -1292,6 +1281,7 @@ void init_mysql2_client() {
12921281
rb_define_private_method(cMysql2Client, "ssl_set", set_ssl_options, 5);
12931282
rb_define_private_method(cMysql2Client, "initialize_ext", initialize_ext, 0);
12941283
rb_define_private_method(cMysql2Client, "connect", rb_connect, 7);
1284+
rb_define_private_method(cMysql2Client, "_query", rb_query, 2);
12951285

12961286
sym_id = ID2SYM(rb_intern("id"));
12971287
sym_version = ID2SYM(rb_intern("version"));

lib/mysql2/client.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ def self.default_query_options
7575
end
7676

7777
if Thread.respond_to?(:handle_interrupt)
78-
def query(*args, &block)
78+
def query(sql, options = {})
7979
Thread.handle_interrupt(Timeout::ExitException => :never) do
80-
_query(*args, &block)
80+
_query(sql, @query_options.merge(options))
8181
end
8282
end
8383
else
84-
alias_method :query, :_query
85-
public :query
84+
def query(sql, options = {})
85+
_query(sql, @query_options.merge(options))
86+
end
8687
end
8788

8889
def query_info

0 commit comments

Comments
 (0)