X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI.pm;h=941b6a4ca4d5968a84cf0d589a81e4716ef564ef;hb=0b5dee17b40cc4029549209a6c84b14c3647a361;hp=61fef778a95ee54a3306696323ef0ad2ed266172;hpb=23f067d16c10318f06d060a6205bcd05a84ec06e;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 61fef77..941b6a4 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -842,47 +842,55 @@ sub _execute { map { defined ($_ && $_->[1]) ? qq{'$_->[1]'} : q{'NULL'} } @bind; $self->debugobj->query_start($sql, @debug_bind); } - my $sth = eval { $self->sth($sql,$op) }; - if (!$sth || $@) { - $self->throw_exception( - 'no sth generated via sql (' . ($@ || $self->_dbh->errstr) . "): $sql" - ); - } + my ($rv, $sth); + RETRY: while (1) { + $sth = eval { $self->sth($sql,$op) }; - my $rv; - if ($sth) { - my $time = time(); - $rv = eval { - my $placeholder_index = 1; + if (!$sth || $@) { + $self->throw_exception( + 'no sth generated via sql (' . ($@ || $self->_dbh->errstr) . "): $sql" + ); + } - foreach my $bound (@bind) { + if ($sth) { + my $time = time(); + $rv = eval { + my $placeholder_index = 1; - my $attributes = {}; - my($column_name, @data) = @$bound; + foreach my $bound (@bind) { - if( $bind_attributes ) { - $attributes = $bind_attributes->{$column_name} - if defined $bind_attributes->{$column_name}; - } + my $attributes = {}; + my($column_name, @data) = @$bound; - foreach my $data (@data) - { - $data = ref $data ? ''.$data : $data; # stringify args + if( $bind_attributes ) { + $attributes = $bind_attributes->{$column_name} + if defined $bind_attributes->{$column_name}; + } - $sth->bind_param($placeholder_index, $data, $attributes); - $placeholder_index++; + foreach my $data (@data) + { + $data = ref $data ? ''.$data : $data; # stringify args + + $sth->bind_param($placeholder_index, $data, $attributes); + $placeholder_index++; + } } + $sth->execute(); + }; + + if ($@ || !$rv) { + $self->throw_exception("Error executing '$sql': ".($@ || $sth->errstr)) + if $self->connected; + $self->_populate_dbh; + } else { + last RETRY; } - $sth->execute(); - }; - - if ($@ || !$rv) { - $self->throw_exception("Error executing '$sql': ".($@ || $sth->errstr)); + } else { + $self->throw_exception("'$sql' did not generate a statement."); } - } else { - $self->throw_exception("'$sql' did not generate a statement."); - } + } # While(1) to retry if disconencted + if ($self->debug) { my @debug_bind = map { defined ($_ && $_->[1]) ? qq{'$_->[1]'} : q{'NULL'} } @bind;