Re: dbi transactions error handling

[email protected] (Paolo Lunazzi)
Newsgroups perl.dbi.users
Organization http://groups.google.com
Message-ID <e878fea6-78bf-439a-a4ef-4b8a4d840745@q26g2000vbn.googlegroups.com>
Thanks for your solution. Your code works well but I don't understand
why in my example eval doesn't catch the error and why, even in your
example, with PrintError = 0 I get on output all the warnings of
statements failed. Transactions section in DBI documentation
recommends to use RaiseError and eval { ... } to implement
transactions so I don't understand where is my mistake.

PL


On Sep 20, 7:11 pm, [email protected] (Ian Harisay) wrote:
> I think you would be better off to write it like this.
>
> $dbh->{RaiseError} = 0;
> $dbh->{PrintError} = 0;
> $dbh->{AutoCommit} = 0;
>
> my @record = ($row_id, $file_id, $offset, $country, $date_day, $campaign, $leaf_id, $status_id);
>
> my $rv;
> SWITCH: {
>   last unless($rv = $sql_live->execute(@record));
>   last unless($rv = $sql_dwh->execute(@record));
>
> };
>
> if($rv){
>   $dbh->commit();}
>
> else{
>   warn "Transaction failed, rolling back. Error was:\n $dbh->errstr\n";
>   $dbh->rollback();
>
>
>
> }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.