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 92
92
$sth -> {TYPE } = $attribs -> {TYPE }
93
93
|| [ (DBI::SQL_VARCHAR()) x $numFields ];
94
94
$sth -> {PRECISION } = $attribs -> {PRECISION }
95
- || [ map { length ( $sth -> { NAME } -> [ $_ ]) } 0.. $ numFields -1 ] ;
95
+ || _max_columnar_lengths( $ numFields, $rows ) ;
96
96
$sth -> {SCALE } = $attribs -> {SCALE }
97
97
|| [ (0) x $numFields ];
98
98
$sth -> {NULLABLE } = $attribs -> {NULLABLE }
152
152
return $dbh -> set_err(42, " not enough parameters" ) unless @args >= 2;
153
153
return \@args ;
154
154
}
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
+ }
155
168
}
156
169
157
170
@@ -279,7 +292,7 @@ The number and order should match the number and ordering of the C<$data> column
279
292
280
293
C<%attr > is a hash of other standard DBI attributes that you might pass to a prepare statement.
281
294
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.
283
296
284
297
=back
285
298
You can’t perform that action at this time.
0 commit comments