@@ -259,6 +259,25 @@ static VALUE rb_mysql_client_warning_count(VALUE self) {
259
259
return UINT2NUM (warning_count );
260
260
}
261
261
262
+ static VALUE rb_mysql_info (VALUE self ) {
263
+ const char * info ;
264
+ VALUE rb_str ;
265
+ GET_CLIENT (self );
266
+
267
+ info = mysql_info (wrapper -> client );
268
+
269
+ if (info == NULL ) {
270
+ return Qnil ;
271
+ }
272
+
273
+ rb_str = rb_str_new2 (info );
274
+ #ifdef HAVE_RUBY_ENCODING_H
275
+ rb_enc_associate (rb_str , rb_utf8_encoding ());
276
+ #endif
277
+
278
+ return rb_str ;
279
+ }
280
+
262
281
static VALUE rb_connect (VALUE self , VALUE user , VALUE pass , VALUE host , VALUE port , VALUE database , VALUE socket , VALUE flags ) {
263
282
struct nogvl_connect_args args ;
264
283
VALUE rv ;
@@ -375,6 +394,7 @@ static VALUE nogvl_use_result(void *ptr) {
375
394
static VALUE rb_mysql_client_async_result (VALUE self ) {
376
395
MYSQL_RES * result ;
377
396
VALUE resultObj ;
397
+ VALUE current , is_streaming ;
378
398
GET_CLIENT (self );
379
399
380
400
/* if we're not waiting on a result, do nothing */
@@ -388,7 +408,7 @@ static VALUE rb_mysql_client_async_result(VALUE self) {
388
408
return rb_raise_mysql2_error (wrapper );
389
409
}
390
410
391
- VALUE is_streaming = rb_hash_aref (rb_iv_get (self , "@current_query_options" ), sym_stream );
411
+ is_streaming = rb_hash_aref (rb_iv_get (self , "@current_query_options" ), sym_stream );
392
412
if (is_streaming == Qtrue ) {
393
413
result = (MYSQL_RES * )rb_thread_blocking_region (nogvl_use_result , wrapper , RUBY_UBF_IO , 0 );
394
414
} else {
@@ -404,7 +424,11 @@ static VALUE rb_mysql_client_async_result(VALUE self) {
404
424
return Qnil ;
405
425
}
406
426
407
- resultObj = rb_mysql_result_to_obj (self , wrapper -> encoding , rb_hash_dup (rb_iv_get (self , "@current_query_options" )), result );
427
+ current = rb_hash_dup (rb_iv_get (self , "@current_query_options" ));
428
+ RB_GC_GUARD (current );
429
+ Check_Type (current , T_HASH );
430
+ resultObj = rb_mysql_result_to_obj (self , wrapper -> encoding , current , result );
431
+
408
432
return resultObj ;
409
433
}
410
434
@@ -549,10 +573,13 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
549
573
REQUIRE_CONNECTED (wrapper );
550
574
args .mysql = wrapper -> client ;
551
575
552
- rb_iv_set (self , "@current_query_options" , rb_hash_dup (rb_iv_get (self , "@query_options" )));
553
- current = rb_iv_get (self , "@current_query_options" );
576
+ current = rb_hash_dup (rb_iv_get (self , "@query_options" ));
577
+ RB_GC_GUARD (current );
578
+ Check_Type (current , T_HASH );
579
+ rb_iv_set (self , "@current_query_options" , current );
580
+
554
581
if (rb_scan_args (argc , argv , "11" , & args .sql , & opts ) == 2 ) {
555
- opts = rb_funcall (current , intern_merge_bang , 1 , opts );
582
+ rb_funcall (current , intern_merge_bang , 1 , opts );
556
583
557
584
if (rb_hash_aref (current , sym_async ) == Qtrue ) {
558
585
async = 1 ;
@@ -930,6 +957,7 @@ static VALUE rb_mysql_client_store_result(VALUE self)
930
957
{
931
958
MYSQL_RES * result ;
932
959
VALUE resultObj ;
960
+ VALUE current ;
933
961
GET_CLIENT (self );
934
962
935
963
result = (MYSQL_RES * )rb_thread_blocking_region (nogvl_store_result , wrapper , RUBY_UBF_IO , 0 );
@@ -942,9 +970,12 @@ static VALUE rb_mysql_client_store_result(VALUE self)
942
970
return Qnil ;
943
971
}
944
972
945
- resultObj = rb_mysql_result_to_obj (self , wrapper -> encoding , rb_hash_dup (rb_iv_get (self , "@current_query_options" )), result );
946
- return resultObj ;
973
+ current = rb_hash_dup (rb_iv_get (self , "@current_query_options" ));
974
+ RB_GC_GUARD (current );
975
+ Check_Type (current , T_HASH );
976
+ resultObj = rb_mysql_result_to_obj (self , wrapper -> encoding , current , result );
947
977
978
+ return resultObj ;
948
979
}
949
980
950
981
#ifdef HAVE_RUBY_ENCODING_H
@@ -1112,6 +1143,7 @@ void init_mysql2_client() {
1112
1143
rb_define_method (cMysql2Client , "store_result" , rb_mysql_client_store_result , 0 );
1113
1144
rb_define_method (cMysql2Client , "reconnect=" , set_reconnect , 1 );
1114
1145
rb_define_method (cMysql2Client , "warning_count" , rb_mysql_client_warning_count , 0 );
1146
+ rb_define_method (cMysql2Client , "query_info_string" , rb_mysql_info , 0 );
1115
1147
#ifdef HAVE_RUBY_ENCODING_H
1116
1148
rb_define_method (cMysql2Client , "encoding" , rb_mysql_client_encoding , 0 );
1117
1149
#endif
0 commit comments