package DBI::Format::String; @DBI::Format::String::ISA = qw(DBI::Format::Base); sub header { my($self, $sth, $fh, $sep) = @_; $self->{'fh'} = $self->setup_fh($fh); $self->{'sth'} = $sth; $self->{'data'} = []; $self->{sep} = $sep if defined $sep; my $types = $sth->{'TYPE'}; my @right_justify; my @widths; my $names = $sth->{'NAME'}; my $type; for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) { $type = $types->[$i]; push(@widths, ($type == DBI::SQL_DATE)? 8 : ($type == DBI::SQL_INTEGER and $sth->{PRECISION}->[$i] > 15 )? 10 : ($type == DBI::SQL_NUMERIC and $sth->{PRECISION}->[$i] > 15 )? 10 : defined($sth->{PRECISION}->[$i]) ? $sth->{PRECISION}->[$i]: 0); push(@right_justify, ($type == DBI::SQL_NUMERIC() || $type == DBI::SQL_DECIMAL() || $type == DBI::SQL_INTEGER() || $type == DBI::SQL_SMALLINT() || $type == DBI::SQL_FLOAT() || $type == DBI::SQL_REAL() || $type == DBI::SQL_BIGINT() || $type == DBI::SQL_TINYINT())); my $format_names; $format_names .= sprintf("%%-%ds ", $widths[$i]); print $fh (sprintf($format_names, $names->[$i])); } $self->{'widths'} = \@widths; $self->{'right_justify'} = \@right_justify; print $fh "\n"; }