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
loopingthrough 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
validarray, 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