From: | lachesis(at)ignmail(dot)com (Dave Robinson) |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: transactions on Postgresql |
Date: | 2001-05-24 13:02:48 |
Message-ID: | 90af9a8c.0105240502.2fbc2027@posting.google.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
hicham bouzdad <h(dot)bouzdad(at)inovaction(dot)com> wrote in message news:<3B0B8A0C(dot)B46AC073(at)inovaction(dot)com>...
> Hi everybody,
>
> my subject is about : DBI / PostgreSql & Transactions with Perl.
> my code is :
>
> $dbh->{AutoCommit} = 0; #-------- begin of transaction
> while (<FILE>) {
> ...
> $sql = "insert into $table ($col) values ($val)";
> $res = $dbh->do($sql);
> }
>
> $dbh->rollback; #--------- end of transaction
>
> my problem : if an insert fail, all following insert are aborted :-(
>
> NB : it's not necessary to me that ALL inserts , will be done
> with succes.
> my question is : if a BAD insert fail , how can i do for doing
> other inserts who may be are GOOD ?
>
> thanks a lot for help ;-)
You want to look at wrapping your do statement into an eval block you
can then capture the insert death in $@
i.e.
eval{
$res = $dbh->do($sql);
};
if ($@){
#if the do failed - do whatever logging/checking you want
}
From | Date | Subject | |
---|---|---|---|
Next Message | Denis Chapligin | 2001-05-24 15:01:25 | ERWin |
Previous Message | Sergey E. Volkov | 2001-05-24 12:50:40 | Re: Return cursor |