Skip to content

Commit 8104df9

Browse files
committed
Another example to bind columns (issue#159)
1 parent 57edc4c commit 8104df9

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

ChangeLog

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
1.647 - 2025-01-17, H.Merijn Brand
22
* Spellcheck
3-
* Fix Makefile rules for Changes
3+
* Fix Makefile rules for Changes (Windows case issue)
4+
* Another example to bind columns (issue#159)
45

56
1.646 - 2025-01-11, H.Merijn Brand
67
* Remove "experimental" tag from statistics_info () (issue#134)

DBI.pm

+18-1
Original file line numberDiff line numberDiff line change
@@ -6894,11 +6894,28 @@ a hash (thanks to H.Merijn Brand):
68946894
68956895
$sth->execute;
68966896
my %row;
6897-
$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
6897+
$sth->bind_columns (\( @row{ @{$sth->{NAME_lc} }} ));
68986898
while ($sth->fetch) {
68996899
print "$row{region}: $row{sales}\n";
69006900
}
69016901
6902+
but has a small drawback: If data already fetched call to L</bind_columns>
6903+
will flush current values. If you want to bind_columns after you have fetched
6904+
you can use:
6905+
6906+
use feature "refaliasing";
6907+
no warnings "experimental::refaliasing";
6908+
while (my $row = $sth->fetchrow_arrayref) {
6909+
\(@$data{ $sth->{NAME_lc}->@* }) = \(@$row);
6910+
}
6911+
6912+
or, with older perl versions:
6913+
6914+
use Data::Alias;
6915+
alias @$data{ $sth->{NAME_lc}->@* } = @$row;
6916+
6917+
This is useful in situations when you have many left joins, but wanna to join
6918+
your %$data hash to only subset of fetched values.
69026919
69036920
=head3 C<dump_results>
69046921

lib/DBI/Changes.pm

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ Spellcheck
2222
2323
=item *
2424
25-
Fix Makefile rules for Changes
25+
Fix Makefile rules for Changes (Windows case issue)
26+
27+
=item *
28+
29+
Another example to bind columns (issue#159)
2630
2731
=back
2832

0 commit comments

Comments
 (0)