Skip to content

Commit

Permalink
Another example to bind columns (issue#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tux committed Jan 17, 2025
1 parent 57edc4c commit 8104df9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1.647 - 2025-01-17, H.Merijn Brand
* Spellcheck
* Fix Makefile rules for Changes
* Fix Makefile rules for Changes (Windows case issue)
* Another example to bind columns (issue#159)

1.646 - 2025-01-11, H.Merijn Brand
* Remove "experimental" tag from statistics_info () (issue#134)
Expand Down
19 changes: 18 additions & 1 deletion DBI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6894,11 +6894,28 @@ a hash (thanks to H.Merijn Brand):
$sth->execute;
my %row;
$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
$sth->bind_columns (\( @row{ @{$sth->{NAME_lc} }} ));
while ($sth->fetch) {
print "$row{region}: $row{sales}\n";
}
but has a small drawback: If data already fetched call to L</bind_columns>

This comment has been minimized.

Copy link
@esabol

esabol Jan 27, 2025

This is not grammatically correct. IMHO, it should be "If the data has already been fetched, the call to L</bind_columns>".

This comment has been minimized.

Copy link
@Tux

Tux Jan 28, 2025

Author Member

done

will flush current values. If you want to bind_columns after you have fetched

This comment has been minimized.

Copy link
@esabol

esabol Jan 27, 2025

There should be a comma after "fetched" on this line.

This comment has been minimized.

Copy link
@Tux

Tux Jan 28, 2025

Author Member

done

you can use:
use feature "refaliasing";
no warnings "experimental::refaliasing";
while (my $row = $sth->fetchrow_arrayref) {
\(@$data{ $sth->{NAME_lc}->@* }) = \(@$row);
}
or, with older perl versions:
use Data::Alias;
alias @$data{ $sth->{NAME_lc}->@* } = @$row;
This is useful in situations when you have many left joins, but wanna to join

This comment has been minimized.

Copy link
@esabol

esabol Jan 27, 2025

Please change "wanna" to "want to".

This comment has been minimized.

Copy link
@Tux

Tux Jan 28, 2025

Author Member

done

your %$data hash to only subset of fetched values.
=head3 C<dump_results>
Expand Down
6 changes: 5 additions & 1 deletion lib/DBI/Changes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ Spellcheck
=item *
Fix Makefile rules for Changes
Fix Makefile rules for Changes (Windows case issue)
=item *
Another example to bind columns (issue#159)
=back
Expand Down

0 comments on commit 8104df9

Please sign in to comment.