@@ -94,7 +94,7 @@ use warnings;
94
94
$sth -> {TYPE } = $attribs -> {TYPE }
95
95
|| [ (DBI::SQL_VARCHAR()) x $numFields ];
96
96
$sth -> {PRECISION } = $attribs -> {PRECISION }
97
- || [ map { length ( $sth -> { NAME } -> [ $_ ]) } 0.. $ numFields -1 ] ;
97
+ || _max_columnar_lengths( $ numFields, $rows ) ;
98
98
$sth -> {SCALE } = $attribs -> {SCALE }
99
99
|| [ (0) x $numFields ];
100
100
$sth -> {NULLABLE } = $attribs -> {NULLABLE }
@@ -154,6 +154,19 @@ use warnings;
154
154
return $dbh -> set_err(42, " not enough parameters" ) unless @args >= 2;
155
155
return \@args ;
156
156
}
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
+ }
157
170
}
158
171
159
172
@@ -281,7 +294,7 @@ The number and order should match the number and ordering of the C<$data> column
281
294
282
295
C<%attr > is a hash of other standard DBI attributes that you might pass to a prepare statement.
283
296
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.
285
298
286
299
=back
287
300
0 commit comments