Skip to content

Commit 9a51469

Browse files
H.Merijn Brand - Tuxrehsack
authored andcommitted
Changed $sth->{TYPE} to be NUMERIC in DBD::File
1 parent e584156 commit 9a51469

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

Changes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ DBI::Changes - List of significant changes to the DBI
1111
Fixed selectrow_*ref to return undef on error in list context
1212
instead if an empty list.
1313
Changed t/42prof_data.t more informative
14+
Changed $sth->{TYPE} to be NUMERIC in DBD::File drivers as per the
15+
DBI docs. Note TYPE_NAME is now also available. [H.Merijn Brand]
1416

15-
=head2 Changes in DBI 1.632 - 5th Nov 2014
17+
=head2 Changes in DBI 1.632 - 9th Nov 2014
1618

1719
Fixed risk of memory corruption with many arguments to methods
1820
originally reported by OSCHWALD for Callbacks but may apply

lib/DBD/File.pm

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,20 +321,50 @@ sub FETCH
321321

322322
# fill overall_defs unless we know
323323
unless (exists $sth->{f_overall_defs} && ref $sth->{f_overall_defs}) {
324+
my $types = $sth->{Database}{Types};
325+
unless ($types) { # Feth types only once per database
326+
if (my $t = $sth->{Database}->type_info_all ()) {
327+
foreach my $i (1 .. $#$t) {
328+
$types->{uc $t->[$i][0]} = $t->[$i][1];
329+
$types->{$t->[$i][1]} ||= uc $t->[$i][0];
330+
}
331+
}
332+
# sane defaults
333+
for ([ 0, "" ],
334+
[ 1, "CHAR" ],
335+
[ 4, "INTEGER" ],
336+
[ 12, "VARCHAR" ],
337+
) {
338+
$types->{$_->[0]} ||= $_->[1];
339+
$types->{$_->[1]} ||= $_->[0];
340+
}
341+
$sth->{Database}{Types} = $types;
342+
}
324343
my $all_meta =
325344
$sth->{Database}->func ("*", "table_defs", "get_sql_engine_meta");
326345
while (my ($tbl, $meta) = each %$all_meta) {
327346
exists $meta->{table_defs} && ref $meta->{table_defs} or next;
328347
foreach (keys %{$meta->{table_defs}{columns}}) {
329-
$sth->{f_overall_defs}{$_} = $meta->{table_defs}{columns}{$_};
348+
my $field_info = $meta->{table_defs}{columns}{$_};
349+
if (defined $field_info->{data_type} &&
350+
$field_info->{data_type} !~ m/^[0-9]+$/) {
351+
$field_info->{type_name} = uc $field_info->{data_type};
352+
$field_info->{data_type} = $types->{$field_info->{type_name}} || 0;
353+
}
354+
$field_info->{type_name} ||= $types->{$field_info->{data_type}} || "CHAR";
355+
$sth->{f_overall_defs}{$_} = $field_info;
330356
}
331357
}
332358
}
333359

334360
my @colnames = $sth->sql_get_colnames ();
335361

336362
$attr eq "TYPE" and
337-
return [ map { $sth->{f_overall_defs}{$_}{data_type} || "CHAR" }
363+
return [ map { $sth->{f_overall_defs}{$_}{data_type} || 12 }
364+
@colnames ];
365+
366+
$attr eq "TYPE_NAME" and
367+
return [ map { $sth->{f_overall_defs}{$_}{type_name} || "VARCHAR" }
338368
@colnames ];
339369

340370
$attr eq "PRECISION" and

t/49dbd_file.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ ok ($dbh = DBI->connect ("dbi:File:", undef, undef, {
176176
ok ($sth = $dbh->prepare ("select * from $tbl"), "Prepare select * from $tbl");
177177
$rowidx = 0;
178178
SKIP: {
179-
$using_dbd_gofer and skip "method intrusion didn't work with proxying", 1;
179+
$using_dbd_gofer and skip "method intrusion didn't work with proxying", 3;
180180
ok ($sth->execute, "execute on $tbl");
181+
like ($_, qr{^[0-9]+$}, "TYPE is numeric") for @{$sth->{TYPE}};
182+
like ($_, qr{^[A-Z]\w+$}, "TYPE_NAME is set") for @{$sth->{TYPE_NAME}};
181183
$dbh->errstr and diag $dbh->errstr;
182184
}
183185

0 commit comments

Comments
 (0)