postgres insert
am 23.11.2006 16:13:13 von Tom Allison
I've been using something like this for Oracle for some time
and tried it with Postgresql.
(RaiseError doesn't change the outcome)
sub insert_token {
my $token = shift;
eval{ $sth1->execute($token) };
if ($@) {
return 1 if $@ =~ /duplicate key violates unique constraint/;
die "ERROR: $@\n";
}
return $sth1->rows;
}
I get a STDERR warning printed out everytime this has a duplicate key violation...
Any idea why eval{} doesn't suppress this?
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
Re: postgres insert
am 23.11.2006 20:32:13 von info
Tom Allison am Donnerstag, 23. November 2006 16:13:
[snipped some code]
> I get a STDERR warning printed out everytime this has a duplicate key
> violation...
>
> Any idea why eval{} doesn't suppress this?
Hi Tom
It'd be a bad idea... eval BLOCK adds the ability to catch runtime errors and
modify the default reaction to a die. It is not here to hide any problems of
code.
You can suppress the output of warnings at a certain place by f.ex:
#!/usr/bin/perl
use strict; use warnings;
warn "Test1\n";
{
local $SIG{__WARN__}=sub {}; # <<<<
warn "Test2\n";
}
warn "Test3\n";
__END__
output:
Test1
Test3
Dani [not part of the output...]
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
Re: postgres insert
am 25.11.2006 19:03:37 von Tom Allison
D. Bolliger wrote:
> Tom Allison am Donnerstag, 23. November 2006 16:13:
>
> [snipped some code]
>> I get a STDERR warning printed out everytime this has a duplicate key
>> violation...
>>
>> Any idea why eval{} doesn't suppress this?
>
> Hi Tom
>
> It'd be a bad idea... eval BLOCK adds the ability to catch runtime errors and
> modify the default reaction to a die. It is not here to hide any problems of
> code.
>
Found out what the problem was. I had PrintError enabled by default.
Once that was set to PrintError => 0 the problem went away.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org