@@ -93,12 +93,13 @@ use warnings;
93
93
|| [ map { " col$_ " } 1..$numFields ];
94
94
$sth -> {TYPE } = $attribs -> {TYPE }
95
95
|| [ (DBI::SQL_VARCHAR()) x $numFields ];
96
- $sth -> {PRECISION } = $attribs -> {PRECISION }
97
- || _max_columnar_lengths($numFields , $rows );
98
96
$sth -> {SCALE } = $attribs -> {SCALE }
99
97
|| [ (0) x $numFields ];
100
98
$sth -> {NULLABLE } = $attribs -> {NULLABLE }
101
99
|| [ (2) x $numFields ];
100
+ if ($attribs -> {PRECISION }) {
101
+ $sth -> {PRECISION } = $attribs -> {PRECISION };
102
+ } # else FETCH will dynamically compute
102
103
}
103
104
104
105
$outer ;
@@ -155,18 +156,6 @@ use warnings;
155
156
return \@args ;
156
157
}
157
158
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
- }
170
159
}
171
160
172
161
@@ -214,6 +203,10 @@ use warnings;
214
203
sub FETCH {
215
204
my ($sth , $attrib ) = @_ ;
216
205
# would normally validate and only fetch known attributes
206
+ if ($attrib eq ' PRECISION' ) {
207
+ # prepare() did _not_ specify PRECISION. We'll only get here once.
208
+ return $sth -> {PRECISION } = _max_col_lengths(@{$sth }{' NUM_OF_FIELDS' , ' rows' });
209
+ }
217
210
# else pass up to DBI to handle
218
211
return $sth -> SUPER::FETCH($attrib );
219
212
}
@@ -224,6 +217,19 @@ use warnings;
224
217
# else pass up to DBI to handle
225
218
return $sth -> SUPER::STORE($attrib , $value );
226
219
}
220
+
221
+ sub _max_col_lengths {
222
+ my ($numFields , $rows ) = @_ ;
223
+ my @precision = (0,) x $numFields ;
224
+ my $len ;
225
+ for my $row (@$rows ) {
226
+ for my $i (0 .. $numFields - 1) {
227
+ next unless defined ($len = length ($row -> [$i ]));
228
+ $precision [$i ] = $len if $len > $precision [$i ];
229
+ }
230
+ }
231
+ return wantarray ? @precision : \@precision ;
232
+ }
227
233
}
228
234
229
235
1;
0 commit comments