@@ -643,39 +643,26 @@ static VALUE rb_mysql_client_abandon_results(VALUE self) {
643
643
* Query the database with +sql+, with optional +options+. For the possible
644
644
* options, see @@default_query_options on the Mysql2::Client class.
645
645
*/
646
- static VALUE rb_mysql_client_query ( int argc , VALUE * argv , VALUE self ) {
646
+ static VALUE rb_query ( VALUE self , VALUE sql , VALUE current ) {
647
647
#ifndef _WIN32
648
648
struct async_query_args async_args ;
649
649
#endif
650
650
struct nogvl_send_query_args args ;
651
- int async = 0 ;
652
- VALUE opts , current ;
653
- #ifdef HAVE_RUBY_ENCODING_H
654
- rb_encoding * conn_enc ;
655
- #endif
656
651
GET_CLIENT (self );
657
652
658
653
REQUIRE_CONNECTED (wrapper );
659
654
args .mysql = wrapper -> client ;
660
655
661
- current = rb_hash_dup (rb_iv_get (self , "@query_options" ));
662
656
RB_GC_GUARD (current );
663
657
Check_Type (current , T_HASH );
664
658
rb_iv_set (self , "@current_query_options" , current );
665
659
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 );
675
661
#ifdef HAVE_RUBY_ENCODING_H
676
- conn_enc = rb_to_encoding (wrapper -> encoding );
677
662
/* 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 ;
679
666
#endif
680
667
args .sql_ptr = StringValuePtr (args .sql );
681
668
args .sql_len = RSTRING_LEN (args .sql );
@@ -686,15 +673,15 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
686
673
#ifndef _WIN32
687
674
rb_rescue2 (do_send_query , (VALUE )& args , disconnect_and_raise , self , rb_eException , (VALUE )0 );
688
675
689
- if (!async ) {
676
+ if (rb_hash_aref (current , sym_async ) == Qtrue ) {
677
+ return Qnil ;
678
+ } else {
690
679
async_args .fd = wrapper -> client -> net .fd ;
691
680
async_args .self = self ;
692
681
693
682
rb_rescue2 (do_query , (VALUE )& async_args , disconnect_and_raise , self , rb_eException , (VALUE )0 );
694
683
695
684
return rb_mysql_client_async_result (self );
696
- } else {
697
- return Qnil ;
698
685
}
699
686
#else
700
687
do_send_query (& args );
@@ -1262,7 +1249,6 @@ void init_mysql2_client() {
1262
1249
rb_define_singleton_method (cMysql2Client , "escape" , rb_mysql_client_escape , 1 );
1263
1250
1264
1251
rb_define_method (cMysql2Client , "close" , rb_mysql_client_close , 0 );
1265
- rb_define_method (cMysql2Client , "query" , rb_mysql_client_query , -1 );
1266
1252
rb_define_method (cMysql2Client , "abandon_results!" , rb_mysql_client_abandon_results , 0 );
1267
1253
rb_define_method (cMysql2Client , "escape" , rb_mysql_client_real_escape , 1 );
1268
1254
rb_define_method (cMysql2Client , "info" , rb_mysql_client_info , 0 );
@@ -1297,6 +1283,7 @@ void init_mysql2_client() {
1297
1283
rb_define_private_method (cMysql2Client , "ssl_set" , set_ssl_options , 5 );
1298
1284
rb_define_private_method (cMysql2Client , "initialize_ext" , initialize_ext , 0 );
1299
1285
rb_define_private_method (cMysql2Client , "connect" , rb_connect , 7 );
1286
+ rb_define_private_method (cMysql2Client , "_query" , rb_query , 2 );
1300
1287
1301
1288
sym_id = ID2SYM (rb_intern ("id" ));
1302
1289
sym_version = ID2SYM (rb_intern ("version" ));
0 commit comments