~percona-toolkit-dev/percona-toolkit/pqd-enhanced-resume-file

« back to all changes in this revision

Viewing changes to lib/Cxn.pm

  • Committer: Daniel Nichter
  • Date: 2013-03-13 18:38:45 UTC
  • Revision ID: daniel@percona.com-20130313183845-qka3b8qx14yrqgw4
Fix lib/Cxn.pm that didn't merge correctly.  Fix t/lib/OptionParser.t test failure.  Update Cxn, OptionParser, and DSNParser in all tools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
               || '';
103
103
 
104
104
   my $self = {
105
 
      dsn          => $dsn,
106
 
      dbh          => $args{dbh},
107
 
      dsn_name     => $dsn_name,
108
 
      hostname     => '',
109
 
      set          => $args{set},
110
 
      NAME_lc      => defined($args{NAME_lc}) ? $args{NAME_lc} : 1,
111
 
      dbh_set      => 0,
112
 
      ask_pass     => $o->get('ask-pass'),
113
 
      DSNParser    => $dp,
 
105
      dsn             => $dsn,
 
106
      dbh             => $args{dbh},
 
107
      dsn_name        => $dsn_name,
 
108
      hostname        => '',
 
109
      set             => $args{set},
 
110
      NAME_lc         => defined($args{NAME_lc}) ? $args{NAME_lc} : 1,
 
111
      dbh_set         => 0,
 
112
      ask_pass        => $o->get('ask-pass'),
 
113
      DSNParser       => $dp,
114
114
      is_cluster_node => undef,
 
115
      parent          => $args{parent},
115
116
   };
116
117
 
117
118
   return bless $self, $class;
118
119
}
119
120
 
120
121
sub connect {
121
 
   my ( $self ) = @_;
 
122
   my ( $self, %opts ) = @_;
122
123
   my $dsn = $self->{dsn};
123
124
   my $dp  = $self->{DSNParser};
124
125
 
129
130
         $dsn->{p} = OptionParser::prompt_noecho("Enter MySQL password: ");
130
131
         $self->{asked_for_pass} = 1;
131
132
      }
132
 
      $dbh = $dp->get_dbh($dp->get_cxn_params($dsn),  { AutoCommit => 1 });
 
133
      $dbh = $dp->get_dbh(
 
134
         $dp->get_cxn_params($dsn),
 
135
         {
 
136
            AutoCommit => 1,
 
137
            %opts,
 
138
         },
 
139
      );
133
140
   }
134
 
   PTDEBUG && _d($dbh, 'Connected dbh to', $self->{name});
135
141
 
136
 
   return $self->set_dbh($dbh);
 
142
   $dbh = $self->set_dbh($dbh);
 
143
   PTDEBUG && _d($dbh, 'Connected dbh to', $self->{hostname},$self->{dsn_name});
 
144
   return $dbh;
137
145
}
138
146
 
139
147
sub set_dbh {
166
174
      $self->{hostname} = $hostname;
167
175
   }
168
176
 
 
177
   if ( $self->{parent} ) {
 
178
      PTDEBUG && _d($dbh, 'Setting InactiveDestroy=1 in parent');
 
179
      $dbh->{InactiveDestroy} = 1;
 
180
   }
 
181
 
169
182
   # Call the set callback to let the caller SET any MySQL variables.
170
183
   if ( my $set = $self->{set}) {
171
184
      $set->($dbh);
176
189
   return $dbh;
177
190
}
178
191
 
 
192
sub lost_connection {
 
193
   my ($self, $e) = @_;
 
194
   return 0 unless $e;
 
195
   return $e =~ m/MySQL server has gone away/
 
196
       || $e =~ m/Lost connection to MySQL server/;
 
197
      # The 1st pattern means that MySQL itself died or was stopped.
 
198
      # The 2nd pattern means that our cxn was killed (KILL <id>).
 
199
}
 
200
 
179
201
# Sub: dbh
180
202
#   Return the cxn's dbh.
181
203
sub dbh {
200
222
 
201
223
sub DESTROY {
202
224
   my ($self) = @_;
203
 
   if ( $self->{dbh}
204
 
         && blessed($self->{dbh})
205
 
         && $self->{dbh}->can("disconnect") ) {
206
 
      PTDEBUG && _d('Disconnecting dbh', $self->{dbh}, $self->{name});
 
225
 
 
226
   PTDEBUG && _d('Destroying cxn');
 
227
 
 
228
   if ( $self->{parent} ) {
 
229
      PTDEBUG && _d($self->{dbh}, 'Not disconnecting dbh in parent');
 
230
   }
 
231
   elsif ( $self->{dbh}
 
232
           && blessed($self->{dbh})
 
233
           && $self->{dbh}->can("disconnect") )
 
234
   {
 
235
      PTDEBUG && _d($self->{dbh}, 'Disconnecting dbh on', $self->{hostname},
 
236
         $self->{dsn_name});
207
237
      $self->{dbh}->disconnect();
208
238
   }
 
239
 
209
240
   return;
210
241
}
211
242