@@ -67,7 +67,6 @@ struct nogvl_connect_args {
67
67
const char * user ;
68
68
const char * passwd ;
69
69
const char * db ;
70
- const char * init_command ;
71
70
unsigned int port ;
72
71
const char * unix_socket ;
73
72
unsigned long client_flag ;
@@ -157,10 +156,6 @@ static void *nogvl_connect(void *ptr) {
157
156
struct nogvl_connect_args * args = ptr ;
158
157
MYSQL * client ;
159
158
160
- if (args -> init_command != NULL ) {
161
- mysql_options (args -> mysql , MYSQL_INIT_COMMAND , args -> init_command );
162
- }
163
-
164
159
client = mysql_real_connect (args -> mysql , args -> host ,
165
160
args -> user , args -> passwd ,
166
161
args -> db , args -> port , args -> unix_socket ,
@@ -327,7 +322,7 @@ static VALUE rb_mysql_info(VALUE self) {
327
322
return rb_str ;
328
323
}
329
324
330
- static VALUE rb_connect (VALUE self , VALUE user , VALUE pass , VALUE host , VALUE port , VALUE database , VALUE socket , VALUE flags , VALUE init_command ) {
325
+ static VALUE rb_connect (VALUE self , VALUE user , VALUE pass , VALUE host , VALUE port , VALUE database , VALUE socket , VALUE flags ) {
331
326
struct nogvl_connect_args args ;
332
327
VALUE rv ;
333
328
GET_CLIENT (self );
@@ -340,7 +335,6 @@ static VALUE rb_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VALUE po
340
335
args .db = NIL_P (database ) ? NULL : StringValuePtr (database );
341
336
args .mysql = wrapper -> client ;
342
337
args .client_flag = NUM2ULONG (flags );
343
- args .init_command = NIL_P (init_command ) ? NULL : StringValuePtr (init_command );
344
338
345
339
rv = (VALUE ) rb_thread_call_without_gvl (nogvl_connect , & args , RUBY_UBF_IO , 0 );
346
340
if (rv == Qfalse ) {
@@ -786,6 +780,11 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) {
786
780
retval = charval ;
787
781
break ;
788
782
783
+ case MYSQL_INIT_COMMAND :
784
+ charval = (const char * )StringValuePtr (value );
785
+ retval = charval ;
786
+ break ;
787
+
789
788
default :
790
789
return Qfalse ;
791
790
}
@@ -1170,6 +1169,10 @@ static VALUE set_read_default_group(VALUE self, VALUE value) {
1170
1169
return _mysql_client_options (self , MYSQL_READ_DEFAULT_GROUP , value );
1171
1170
}
1172
1171
1172
+ static VALUE set_init_command (VALUE self , VALUE value ) {
1173
+ return _mysql_client_options (self , MYSQL_INIT_COMMAND , value );
1174
+ }
1175
+
1173
1176
static VALUE initialize_ext (VALUE self ) {
1174
1177
GET_CLIENT (self );
1175
1178
@@ -1241,9 +1244,10 @@ void init_mysql2_client() {
1241
1244
rb_define_private_method (cMysql2Client , "secure_auth=" , set_secure_auth , 1 );
1242
1245
rb_define_private_method (cMysql2Client , "default_file=" , set_read_default_file , 1 );
1243
1246
rb_define_private_method (cMysql2Client , "default_group=" , set_read_default_group , 1 );
1247
+ rb_define_private_method (cMysql2Client , "init_command=" , set_init_command , 1 );
1244
1248
rb_define_private_method (cMysql2Client , "ssl_set" , set_ssl_options , 5 );
1245
1249
rb_define_private_method (cMysql2Client , "initialize_ext" , initialize_ext , 0 );
1246
- rb_define_private_method (cMysql2Client , "connect" , rb_connect , 8 );
1250
+ rb_define_private_method (cMysql2Client , "connect" , rb_connect , 7 );
1247
1251
1248
1252
sym_id = ID2SYM (rb_intern ("id" ));
1249
1253
sym_version = ID2SYM (rb_intern ("version" ));
0 commit comments