@@ -642,40 +642,27 @@ 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 ;
650- int async = 0 ;
651- VALUE opts , current ;
652650 VALUE thread_current = rb_thread_current ();
653- #ifdef HAVE_RUBY_ENCODING_H
654- rb_encoding * conn_enc ;
655- #endif
656651 GET_CLIENT (self );
657652
658653 REQUIRE_CONNECTED (wrapper );
659654 args .mysql = wrapper -> client ;
660655
661- current = rb_hash_dup (rb_iv_get (self , "@query_options" ));
662656 RB_GC_GUARD (current );
663657 Check_Type (current , T_HASH );
664658 rb_iv_set (self , "@current_query_options" , current );
665659
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- }
673-
674- Check_Type (args .sql , T_STRING );
660+ Check_Type (sql , T_STRING );
675661#ifdef HAVE_RUBY_ENCODING_H
676- conn_enc = rb_to_encoding (wrapper -> encoding );
677662 /* ensure the string is in the encoding the connection is expecting */
678- args .sql = rb_str_export_to_enc (args .sql , conn_enc );
663+ args .sql = rb_str_export_to_enc (sql , rb_to_encoding (wrapper -> encoding ));
664+ #else
665+ args .sql = sql ;
679666#endif
680667 args .sql_ptr = RSTRING_PTR (args .sql );
681668 args .sql_len = RSTRING_LEN (args .sql );
@@ -699,15 +686,15 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
699686#ifndef _WIN32
700687 rb_rescue2 (do_send_query , (VALUE )& args , disconnect_and_raise , self , rb_eException , (VALUE )0 );
701688
702- if (!async ) {
689+ if (rb_hash_aref (current , sym_async ) == Qtrue ) {
690+ return Qnil ;
691+ } else {
703692 async_args .fd = wrapper -> client -> net .fd ;
704693 async_args .self = self ;
705694
706695 rb_rescue2 (do_query , (VALUE )& async_args , disconnect_and_raise , self , rb_eException , (VALUE )0 );
707696
708697 return rb_mysql_client_async_result (self );
709- } else {
710- return Qnil ;
711698 }
712699#else
713700 do_send_query (& args );
@@ -1259,7 +1246,6 @@ void init_mysql2_client() {
12591246 rb_define_singleton_method (cMysql2Client , "info" , rb_mysql_client_info , 0 );
12601247
12611248 rb_define_method (cMysql2Client , "close" , rb_mysql_client_close , 0 );
1262- rb_define_method (cMysql2Client , "query" , rb_mysql_client_query , -1 );
12631249 rb_define_method (cMysql2Client , "abandon_results!" , rb_mysql_client_abandon_results , 0 );
12641250 rb_define_method (cMysql2Client , "escape" , rb_mysql_client_real_escape , 1 );
12651251 rb_define_method (cMysql2Client , "server_info" , rb_mysql_client_server_info , 0 );
@@ -1292,6 +1278,7 @@ void init_mysql2_client() {
12921278 rb_define_private_method (cMysql2Client , "ssl_set" , set_ssl_options , 5 );
12931279 rb_define_private_method (cMysql2Client , "initialize_ext" , initialize_ext , 0 );
12941280 rb_define_private_method (cMysql2Client , "connect" , rb_connect , 7 );
1281+ rb_define_private_method (cMysql2Client , "_query" , rb_query , 2 );
12951282
12961283 sym_id = ID2SYM (rb_intern ("id" ));
12971284 sym_version = ID2SYM (rb_intern ("version" ));
0 commit comments