For your reference:
sub dump_results {      # also aliased as a method in DBD::_::st
   my ($sth, $maxlen, $lsep, $fsep, $fh) = @_;
   return 0 unless $sth;
   $maxlen ||= 35;
   $lsep   ||= "\n";
   $fh ||= \*STDOUT;
   my $rows = 0;
   my $ref;
   while($ref = $sth->fetch) {
       print $fh $lsep if $rows++ and $lsep;
       my $str = neat_list($ref,$maxlen,$fsep);
       print $fh $str; # done on two lines to avoid 5.003 errors
   }
   print $fh "\n$rows rows".($DBI::err ? " ($DBI::err: $DBI::errstr)" :
"")."\n";
   $rows;
}

I would like to add another parameter that would suppress the rowcount print
as long as there are no errors. In theory:

sub dump_results {      # also aliased as a method in DBD::_::st
   my ($sth, $maxlen, $lsep, $fsep, $fh, $suppress_rowcount) = @_;

   ...

   print $fh "\n$rows rows".($DBI::err ? " ($DBI::err: $DBI::errstr)" :
"")."\n"
       if(not defined($suppress_rowcount) ## default behaviour
          or not $suppress_rowcount       ## if 1, it may suppress
          or $DBI::err                    ## print if there's an error,
regardless
         );
   $rows;
}

In practice, I think that I'd also like to add also add $suppress_errors.
Seems to me that what we should really do is:

sub dump_results {      # also aliased as a method in DBD::_::st
   my ($sth, $maxlen, $lsep, $fsep, $fh, $hr_attribs) = @_;
   ## hr_ is "hungarian" for hash ref. Not neccessary, but for this
example, I'll use it for clarity

   ## Pedantic, but I ABHOR 'use-of-uninitialized' warnings...
   my $suppress_count = (defined($hr_attribs)
                         and defined($hr_attribs->{'suppress_count'}
                         and $hr_attribs->{'suppress_count'});
   my $suppress_errors = (defined($hr_attribs)
                          and defined($hr_attribs->{'suppress_errors'}
                          and $hr_attribs->{'suppress_errors'});
   ...

   print $fh "\n$rows rows" if (not $suppress_count);
   if($DBI::err and not $suppress_errors) {
       print $fh ($suppress_count ? "\n" : " ");
       print $fh "($DBI::err: $DBI::errstr)";
   }
   print $fh "\n";
   $rows;
}

This arrangement will allow us to (for example) add on formating specs to
neat_list in the same manner and pass them down.

Can I get a consensus and critique before I submit a patch?

--
Matthew O. Persico

Reply via email to