diff --git a/ChangeLog b/ChangeLog index 3e25baf0..82a333a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -2013-09-17 Michiel Beijen, Patrick Galbraith, DBI/DBD community +2013-??-?? Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.025) +* Fix example in POD doc for NUM_OF_FIELDS - RT36730, reported by tapoutmma. + +2013-09-17 Michiel Beijen, Patrick Galbraith, DBI/DBD community (4.024) * Fix memory leak if mysql_server_prepare is enabled - RT76462 - Masahiro Chiba * Small dist improvements: Michiel Beijen * Undefined $DBI::errstr on execute fail on Windows: Michiel Beijen diff --git a/eg/proc_example1.pl b/eg/proc_example1.pl index 3ff19d71..bb07c5cf 100644 --- a/eg/proc_example1.pl +++ b/eg/proc_example1.pl @@ -1,6 +1,8 @@ #!/usr/bin/perl use strict; +use warnings; + use DBI; my $db='test'; @@ -34,7 +36,7 @@ $sth->execute || die DBI::err.": ".$DBI::errstr; do { print "\nResult set ".++$i."\n---------------------------------------\n\n"; - for my $colno (0..$sth->{NUM_OF_FIELDS}) { + for my $colno (0..$sth->{NUM_OF_FIELDS}-1) { print $sth->{NAME}->[$colno]."\t"; } print "\n"; diff --git a/eg/proc_example2.pl b/eg/proc_example2.pl index a167908c..74a003dd 100644 --- a/eg/proc_example2.pl +++ b/eg/proc_example2.pl @@ -1,6 +1,8 @@ #!/usr/bin/perl use strict; +use warnings; + use DBI; use Data::Dumper; @@ -43,7 +45,7 @@ BEGIN $sth->execute || die DBI::err.": ".$DBI::errstr; do { print "\nResult set ".++$i."\n---------------------------------------\n\n"; - for my $colno (0..$sth->{NUM_OF_FIELDS}) { + for my $colno (0..$sth->{NUM_OF_FIELDS}-1) { print $sth->{NAME}->[$colno]."\t"; } print "\n"; diff --git a/lib/DBD/mysql.pm b/lib/DBD/mysql.pm index d17d1c46..86262f90 100644 --- a/lib/DBD/mysql.pm +++ b/lib/DBD/mysql.pm @@ -1501,13 +1501,13 @@ header of table names together with all rows: die "Error:" . $sth->errstr . "\n"; } my $names = $sth->{'NAME'}; - my $numFields = $sth->{'NUM_OF_FIELDS'}; - for (my $i = 0; $i < $numFields; $i++) { + my $numFields = $sth->{'NUM_OF_FIELDS'} - 1; + for my $i ( 0..$numFields ) { printf("%s%s", $i ? "," : "", $$names[$i]); } print "\n"; while (my $ref = $sth->fetchrow_arrayref) { - for (my $i = 0; $i < $numFields; $i++) { + for my $i ( 0..$numFields ) { printf("%s%s", $i ? "," : "", $$ref[$i]); } print "\n"; @@ -1764,7 +1764,7 @@ An example would be: $sth->execute || die DBI::err.": ".$DBI::errstr; $rowset=0; do { print "\nRowset ".++$i."\n---------------------------------------\n\n"; - foreach $colno (0..$sth->{NUM_OF_FIELDS}) { + foreach $colno (0..$sth->{NUM_OF_FIELDS}-1) { print $sth->{NAME}->[$colno]."\t"; } print "\n";