File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 9292 $sth -> {TYPE } = $attribs -> {TYPE }
9393 || [ (DBI::SQL_VARCHAR()) x $numFields ];
9494 $sth -> {PRECISION } = $attribs -> {PRECISION }
95- || [ map { length ( $sth -> { NAME } -> [ $_ ]) } 0.. $ numFields -1 ] ;
95+ || _max_columnar_lengths( $ numFields, $rows ) ;
9696 $sth -> {SCALE } = $attribs -> {SCALE }
9797 || [ (0) x $numFields ];
9898 $sth -> {NULLABLE } = $attribs -> {NULLABLE }
152152 return $dbh -> set_err(42, " not enough parameters" ) unless @args >= 2;
153153 return \@args ;
154154 }
155+
156+ sub _max_columnar_lengths {
157+ my ($numFields , $rows ) = @_ ;
158+ my @precision = (0,) x $numFields ;
159+ my $len ;
160+ for my $row (@$rows ) {
161+ for my $i (0 .. $numFields - 1) {
162+ next unless defined $len = length ($row -> [$i ]);
163+ $precision [$i ] = $len if $len > $precision [$i ];
164+ }
165+ }
166+ return wantarray ? @precision : \@precision ;
167+ }
155168}
156169
157170
@@ -279,7 +292,7 @@ The number and order should match the number and ordering of the C<$data> column
279292
280293C<%attr > is a hash of other standard DBI attributes that you might pass to a prepare statement.
281294
282- Currently only NAME, TYPE, and PRECISION are supported.
295+ Currently only NAME, TYPE, and PRECISION are supported. PRECISION will be automatically computed if not supplied.
283296
284297=back
285298
You can’t perform that action at this time.
0 commit comments