@@ -67,7 +67,6 @@ struct nogvl_connect_args {
6767 const char * user ;
6868 const char * passwd ;
6969 const char * db ;
70- const char * init_command ;
7170 unsigned int port ;
7271 const char * unix_socket ;
7372 unsigned long client_flag ;
@@ -157,10 +156,6 @@ static void *nogvl_connect(void *ptr) {
157156 struct nogvl_connect_args * args = ptr ;
158157 MYSQL * client ;
159158
160- if (args -> init_command != NULL ) {
161- mysql_options (args -> mysql , MYSQL_INIT_COMMAND , args -> init_command );
162- }
163-
164159 client = mysql_real_connect (args -> mysql , args -> host ,
165160 args -> user , args -> passwd ,
166161 args -> db , args -> port , args -> unix_socket ,
@@ -327,7 +322,7 @@ static VALUE rb_mysql_info(VALUE self) {
327322 return rb_str ;
328323}
329324
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 ) {
331326 struct nogvl_connect_args args ;
332327 VALUE rv ;
333328 GET_CLIENT (self );
@@ -340,7 +335,6 @@ static VALUE rb_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VALUE po
340335 args .db = NIL_P (database ) ? NULL : StringValuePtr (database );
341336 args .mysql = wrapper -> client ;
342337 args .client_flag = NUM2ULONG (flags );
343- args .init_command = NIL_P (init_command ) ? NULL : StringValuePtr (init_command );
344338
345339 rv = (VALUE ) rb_thread_call_without_gvl (nogvl_connect , & args , RUBY_UBF_IO , 0 );
346340 if (rv == Qfalse ) {
@@ -786,6 +780,11 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) {
786780 retval = charval ;
787781 break ;
788782
783+ case MYSQL_INIT_COMMAND :
784+ charval = (const char * )StringValuePtr (value );
785+ retval = charval ;
786+ break ;
787+
789788 default :
790789 return Qfalse ;
791790 }
@@ -1170,6 +1169,10 @@ static VALUE set_read_default_group(VALUE self, VALUE value) {
11701169 return _mysql_client_options (self , MYSQL_READ_DEFAULT_GROUP , value );
11711170}
11721171
1172+ static VALUE set_init_command (VALUE self , VALUE value ) {
1173+ return _mysql_client_options (self , MYSQL_INIT_COMMAND , value );
1174+ }
1175+
11731176static VALUE initialize_ext (VALUE self ) {
11741177 GET_CLIENT (self );
11751178
@@ -1241,9 +1244,10 @@ void init_mysql2_client() {
12411244 rb_define_private_method (cMysql2Client , "secure_auth=" , set_secure_auth , 1 );
12421245 rb_define_private_method (cMysql2Client , "default_file=" , set_read_default_file , 1 );
12431246 rb_define_private_method (cMysql2Client , "default_group=" , set_read_default_group , 1 );
1247+ rb_define_private_method (cMysql2Client , "init_command=" , set_init_command , 1 );
12441248 rb_define_private_method (cMysql2Client , "ssl_set" , set_ssl_options , 5 );
12451249 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 );
12471251
12481252 sym_id = ID2SYM (rb_intern ("id" ));
12491253 sym_version = ID2SYM (rb_intern ("version" ));
0 commit comments