Re: plperl and/or insert trigger problem

From: Richard Huxton <dev(at)archonet(dot)com>
To: Bart Degryse <Bart(dot)Degryse(at)indicator(dot)be>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: plperl and/or insert trigger problem
Date: 2007-06-06 15:44:03
Message-ID: 4666D643.1090103@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bart Degryse wrote:
> I tend to exclude reason 1: I've dumped the whole array using a debugger and it really contains what I return when looping through it.
> As far as I can see it's rather reason 2: execute_for_fetch seems to fill the array incorrectly, that is: it's a valid array, but the last value added to it also seems to overwrite previously added values.

Hmm - see below

>
> I seem to have found a workaround but my perl knowledge is too limited to evaluate if it's a good one.

I'm no guru myself...

> When I replace
> my $fetch_tuple_sub = sub { $sel->fetchrow_arrayref };
> by
> my $fetch_tuple_sub = sub {
> my $ary_ref = $sel->fetchrow_arrayref;
> print "my method: ".$dbh_pg->errstr."\n" if $dbh_pg->err;
> return $ary_ref;
> };
> then the expected exception messages get printed.
> Is this a acceptable way to do it in your opinion?

Looks OK to me, except you'll not get any error message on the last row
- the insert will be called after the fetch.

I've had a quick look at my copy of DBI.pm (Debian Etch - lives in
/usr/lib/perl5/DBI.pm)

Around line 1930, we have the error-handling for execute_for_fetch()

else {
$err_count++;
my $err = $sth->err;
push @$tuple_status, [ $err, $errstr_cache{$err} ||= $sth->errstr,
$sth->state ];
...

Notice how it's taking a copy of the error code ("my $err = ") but not
the error-string? What happens if you change the code to take a copy of
sth->errstr too:

my ($err,$errstr) = ($sth->err, $sth->errstr);
push @$tuple_status, [ $err, $errstr_cache{$err} ||= $errstr,
$sth->state];

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Erwin Brandstetter 2007-06-06 15:56:37 Re: Join field values
Previous Message Bart Degryse 2007-06-06 15:07:59 Re: plperl and/or insert trigger problem