dbi_bunce_tips

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



Subject: Re: fetchrow_hashref vs placeholders, binding
From: Tim Bunce <Tim.Bunce@ig.co.uk>
Date: Thu, 10 Aug 2000 21:04:02 +0100

There's little point in using bind_columns if what you want at the
end of the day is a hash ref.

See how fetchrow_hashref does it (using 'perldoc -m DBI'):

    sub fetchrow_hashref {
        my $sth = shift;
        my $name = shift || 'NAME';
        my $row = $sth->fetch or return undef;
        my %hash;
        @hash{ @{ $sth->FETCH($name) } } = @$row;
        return \%hash;
    }

Do the same but factor out the getting of the names:

    my $NAMES = $sth->{NAME_lc};
  	while (my $row = $sth->fetchrow_arrayref) {
        my %hash;
        @hash{ @$NAMES } = @$row;
  		push @found, \%hash;
  	}
	$loop_count = @found;

Or you could just use

    $rows = $sth->fetchall_arrayref({});

:-)

Tim.

===

Subject: Re: fetchrow_hashref vs placeholders, binding
From: Tim Bunce <Tim.Bunce@ig.co.uk>
Date: Fri, 11 Aug 2000 09:23:14 +0100

On Fri, Aug 11, 2000 at 01:50:26PM -0500, Neil Lunn wrote:
> 
> >From: Tim Bunce <Tim.Bunce@ig.co.uk>
> >
> >     $rows = $sth->fetchall_arrayref({});
> 
> I didn't know that one! Could have saved me some past grief!

Rereading the docs is recommended. They're far more clearly written
in DBI 1.14 (polished up by our DBI book editor :-).

> One I'm looking at now. What if you wanted to take 12 of the columns and 
> store those under a list context
> 
> ie:
> 
>     gross_sale#1 becomes $gross_sale[1] or even $row->{gross_sale}[1]
>     or $row->[$x]{gross-sale}[1]
> 
> Should this be more of a bind_columns approach?

I probably wouldn't bother unless the number of columns was small and fixed.
But it's still just a few lines of code.

===

Subject: Re: DBD::ODBC problems
From: Tim Bunce <Tim.Bunce@ig.co.uk>
Date: Fri, 11 Aug 2000 18:27:32 +0100

On Thu, Jul 20, 2000 at 02:19:48PM -0600, Aaron Patterson wrote:
> 
> I set the trace level to three, and this is what happened:
> 
> Segmentation fault (core dumped)
> 
> This is the entry in ~/.odbc.ini:
> 
> [asuka]
> Driver          = /usr/local/lib/libiodbc.so

That's not a driver, it's the driver manager.

Tim.

===



the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu