Gordon Henriksen wrote:

fetchrow_hashref is definitely a very useful, but my favorite (and also the most efficient) DBI methodology is bind_columns. DBI maintains a list of references corresponding to columns in the result set, and when the result set is advanced, stores the values into the variables referenced. e.g., Perl 5:


my $sth = $dbh->prepare("select a, b, c from tab");
$sth->execute;
$sth->bind_columns(\my($a, $b, $c));
while ($sth->fetch) {
print "a: $a, b: $b, c: $c\n";
}


Equivalent to:

my $sth = $dbh->prepare("select a, b, c from tab");
$sth->execute;
$sth->bind_col(0, \my $a);
$sth->bind_col(1, \my $b);
$sth->bind_col(2, \my $c);
while ($sth->fetch) {
print "a: $a, b: $b, c: $c\n";
}


So if you're going to basically go all out in emulating DBI's fetch_* permutations, don't forget this one. :)

I am not really trying to emulate any methods at the moment it just happens that these ways come naturally to Perl Hackers. In fact the entire way the data comes out is open for debate and it might be a good time to add a few nice features to it if anyone can think of any.


I doubt if any of the functionality that currently exists will be changed but this is not up to me, all that stuff is at a much higher layer of abstraction than where I am currently digging.

Harry Jackson

Reply via email to