@@ -94,7 +94,7 @@ use warnings;
9494 $sth -> {TYPE } = $attribs -> {TYPE }
9595 || [ (DBI::SQL_VARCHAR()) x $numFields ];
9696 $sth -> {PRECISION } = $attribs -> {PRECISION }
97- || [ map { length ( $sth -> { NAME } -> [ $_ ]) } 0.. $ numFields -1 ] ;
97+ || _max_columnar_lengths( $ numFields, $rows ) ;
9898 $sth -> {SCALE } = $attribs -> {SCALE }
9999 || [ (0) x $numFields ];
100100 $sth -> {NULLABLE } = $attribs -> {NULLABLE }
@@ -154,6 +154,19 @@ use warnings;
154154 return $dbh -> set_err(42, " not enough parameters" ) unless @args >= 2;
155155 return \@args ;
156156 }
157+
158+ sub _max_columnar_lengths {
159+ my ($numFields , $rows ) = @_ ;
160+ my @precision = (0,) x $numFields ;
161+ my $len ;
162+ for my $row (@$rows ) {
163+ for my $i (0 .. $numFields - 1) {
164+ next unless defined $len = length ($row -> [$i ]);
165+ $precision [$i ] = $len if $len > $precision [$i ];
166+ }
167+ }
168+ return wantarray ? @precision : \@precision ;
169+ }
157170}
158171
159172
@@ -281,7 +294,7 @@ The number and order should match the number and ordering of the C<$data> column
281294
282295C<%attr > is a hash of other standard DBI attributes that you might pass to a prepare statement.
283296
284- Currently only NAME, TYPE, and PRECISION are supported.
297+ Currently only NAME, TYPE, and PRECISION are supported. PRECISION will be automatically computed if not supplied.
285298
286299=back
287300
0 commit comments