@@ -78,6 +78,23 @@ enum exit_codes
78
78
EXIT_UPGRADING_QUERIES_ERROR = 5 ,
79
79
};
80
80
81
+
82
+ class Mysql_connection_holder
83
+ {
84
+ MYSQL* m_mysql_connection;
85
+
86
+ public:
87
+ explicit Mysql_connection_holder (MYSQL *mysql_connection)
88
+ : m_mysql_connection(mysql_connection)
89
+ { }
90
+
91
+ ~Mysql_connection_holder ()
92
+ {
93
+ mysql_close (this ->m_mysql_connection );
94
+ }
95
+ };
96
+
97
+
81
98
class Program : public Base ::Abstract_connection_program
82
99
{
83
100
public:
@@ -119,6 +136,8 @@ class Program : public Base::Abstract_connection_program
119
136
setbuf (stdout, NULL );
120
137
121
138
this ->m_mysql_connection = this ->create_connection ();
139
+ // Remember to call mysql_close()
140
+ Mysql_connection_holder connection_holder (m_mysql_connection);
122
141
this ->m_query_runner = new Mysql_query_runner (this ->m_mysql_connection );
123
142
this ->m_query_runner ->add_message_callback (new Instance_callback
124
143
<int , Mysql_message, Program>(this , &Program::print_error));
@@ -434,8 +453,6 @@ class Program : public Base::Abstract_connection_program
434
453
/* Create a file indicating upgrade has been performed */
435
454
this ->create_mysql_upgrade_info_file ();
436
455
437
- mysql_close (this ->m_mysql_connection );
438
-
439
456
return 0 ;
440
457
}
441
458
@@ -525,13 +542,13 @@ class Program : public Base::Abstract_connection_program
525
542
const char **query_ptr;
526
543
int result;
527
544
545
+ Instance_callback<int , vector<string>, Program>
546
+ result_callback (this , &Program::result_callback);
547
+ Instance_callback<int , Mysql_message, Program>
548
+ message_callback (this , &Program::fix_privilage_tables_error);
528
549
Mysql_query_runner runner (*this ->m_query_runner );
529
- runner.add_result_callback (
530
- new Instance_callback<int , vector<string>, Program>(
531
- this , &Program::result_callback));
532
- runner.add_message_callback (
533
- new Instance_callback<int , Mysql_message, Program>(
534
- this , &Program::fix_privilage_tables_error));
550
+ runner.add_result_callback (&result_callback);
551
+ runner.add_message_callback (&message_callback);
535
552
536
553
this ->print_verbose_message (" Running queries to upgrade MySQL server." );
537
554
@@ -565,13 +582,13 @@ class Program : public Base::Abstract_connection_program
565
582
const char **query_ptr;
566
583
int result;
567
584
585
+ Instance_callback<int , vector<string>, Program>
586
+ result_callback (this , &Program::result_callback);
587
+ Instance_callback<int , Mysql_message, Program>
588
+ message_callback (this , &Program::fix_privilage_tables_error);
568
589
Mysql_query_runner runner (*this ->m_query_runner );
569
- runner.add_result_callback (
570
- new Instance_callback<int , vector<string>, Program>(
571
- this , &Program::result_callback));
572
- runner.add_message_callback (
573
- new Instance_callback<int , Mysql_message, Program>(
574
- this , &Program::fix_privilage_tables_error));
590
+ runner.add_result_callback (&result_callback);
591
+ runner.add_message_callback (&message_callback);
575
592
576
593
this ->print_verbose_message (" Upgrading the sys schema." );
577
594
@@ -744,13 +761,8 @@ class Program : public Base::Abstract_connection_program
744
761
*/
745
762
int fix_privilage_tables_error (Mysql_message message)
746
763
{
747
- String error;
748
- uint dummy_errors;
749
- error.copy (" error" , 5 , &my_charset_latin1,
750
- this ->m_mysql_connection ->charset , &dummy_errors);
751
-
752
764
bool is_error = my_strcasecmp (this ->m_mysql_connection ->charset ,
753
- message.severity .c_str (), error. c_ptr () ) == 0 ;
765
+ message.severity .c_str (), " error" ) == 0 ;
754
766
755
767
// This if it is error message and if it is not expected one.
756
768
if (this ->m_temporary_verbose ||
0 commit comments