is there a bind_hash()?

is there a bind_hash()?

am 02.12.2005 01:17:29 von thepler

Hi all,

Is there a CPAN module out there that implements something like
bind_hash() from this article:

http://www.perl.com/pub/a/2001/03/dbiokay.html

My searches aren't coming up with anything.

Basically I'm looking for something like this snippet:

@results{@fields} = ();
$sth->bind_columns(map { \$results{$_} } @fields);

wrapped in a nice little interface.

Thanks,
-Todd

RE: is there a bind_hash()?

am 02.12.2005 01:22:24 von john.moon

Subject: is there a bind_hash()?

Hi all,

Is there a CPAN module out there that implements something like=20
bind_hash() from this article:

http://www.perl.com/pub/a/2001/03/dbiokay.html

My searches aren't coming up with anything.

Basically I'm looking for something like this snippet:

@results{@fields} =3D ();
$sth->bind_columns(map { \$results{$_} } @fields);

wrapped in a nice little interface.

Thanks,
-Todd

Have you looked at fetchrow_hashref or fetchall_hashref?

jwm

Re: is there a bind_hash()?

am 02.12.2005 01:31:11 von siracusa

On 12/1/05 7:17 PM, Todd Hepler wrote:
> Basically I'm looking for something like this snippet:
>
> @results{@fields} = ();
> $sth->bind_columns(map { \$results{$_} } @fields);
>
> wrapped in a nice little interface.

Just an unrelated tip: the above can be done a bit more idiomatically (and
probably a teeny bit faster) like this:

$sth->bind_columns(\@results{@fields});

-John

Re: is there a bind_hash()?

am 02.12.2005 13:20:30 von Tim.Bunce

On Thu, Dec 01, 2005 at 07:31:11PM -0500, John Siracusa wrote:
> On 12/1/05 7:17 PM, Todd Hepler wrote:
> > Basically I'm looking for something like this snippet:
> >
> > @results{@fields} = ();
> > $sth->bind_columns(map { \$results{$_} } @fields);
> >
> > wrapped in a nice little interface.
>
> Just an unrelated tip: the above can be done a bit more idiomatically (and
> probably a teeny bit faster) like this:
>
> $sth->bind_columns(\@results{@fields});

Which is very like the example in the DBI docs for the bind_columns method:

$sth->execute;
my %row;
$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
while ($sth->fetch) {
print "$row{region}: $row{sales}\n";
}

I hope you'll agree, Todd, that there's no need for an extra module.
CPAN has more than enough DBI helper/wrapper modules already.

Tim.

Re: is there a bind_hash()?

am 02.12.2005 14:52:44 von thepler

Tim Bunce wrote:
>
> I hope you'll agree, Todd, that there's no need for an extra module.
> CPAN has more than enough DBI helper/wrapper modules already.
>

Thanks for setting me straight.

-Todd