Can you post an example script that calls selectrow_hashref and
demonstrates the problem?

Tim.

On Fri, Feb 14, 2003 at 01:18:56PM +1100, Craig Sanders wrote:
> this seems to have changed since i installed DBI 1.32 (i upgraded from 1.30),
> and is breaking some scripts which assume that it will always return a hash.
> 
> sometimes (when the query returns no rows), it returns the scalar "1" -
> attempting to use that as a hashref causes the script to die (with "strict
> refs" set - would cause strange errors without it)
> 
> the problem seems to be in _do_selectrow() in DBI.pm, which is also used
> by selectrow_arrayref.
> 
> as a temporary workaround fix, i hacked _do_selectrow() so that it
> always returns the appropriate reference.  
> 
> like so:
> 
>     sub _do_selectrow {
>   my ($method, $dbh, $stmt, $attr, @bind) = @_;
>   my $sth = ((ref $stmt) ? $stmt : $dbh->prepare($stmt, $attr))
>       or return;
>   $sth->execute(@bind)
>       or return;
>   my $row = $sth->$method()
>       and $sth->finish;
>   # temporary workaround fix.  CAS 2003-02-14
>   if ($method =~ /ref/ && ! ref($row)) {
>     warn "***** _do_selectrow workaround";
>     $row = [] if ($method =~ /array/);
>     $row = {} if ($method =~ /hash/);
>   } ;
>   return $row;
>     }
> 
> 
> i don't know the DBI code well enough to know whether this will have
> other undesirable consequences, but it stops my scripts from dying until
> a real fix is available.
> 
> 
> craig
> 
> -- 
> craig sanders <[EMAIL PROTECTED]>
> 
> Fabricati Diem, PVNC.
>  -- motto of the Ankh-Morpork City Watch

Reply via email to