On Wed, 31 Jul 2013 08:51:40 +0100, "Martin J. Evans"
<martin.ev...@easysoft.com> wrote:

> On 30/07/13 21:30, H.Merijn Brand wrote:
> > On Tue, 30 Jul 2013 20:23:50 +0100, "Martin J. Evans"
> > <martin.ev...@easysoft.com> wrote:
> >> I have not looked at this in context but it seems to me this code is
> >> assuming element 0 and element 1 are TYPE_NAME and DATA_TYPE whereas
> >> type_info_all starts with a map which describes the columns in the
> >> result.
> >
> > Yes, «grep { ref $_ eq "ARRAY" }» filters that out
> > It is a pseudo-hash, which I don't like, but it is unlikely to ever
> > change. Would you be more comfortable with this?
> >
> >         unless ($type_map) {
> >             # TYPE_NAME => DATA_TYPE
> >             $type_map = {   # Minimal type set (like CSV)
> >                 BLOB    => -4,
> >                 TEXT    => -1,
> >                 CHAR    =>  1,
> >                 INTEGER =>  4,
> >                 REAL    =>  7,
> >                 VARCHAR => 12,
> >                 };
> >             if (my $tia = $sth->{Database}->type_info_all ()) {
> >                 my $tiah = shift @$tia;
> >                 my %tiah = map { uc ($_) => $tiah->{$_} } keys %$tiah;
> >                 my ($tni, $dti) = map {$tiah->{$_}} "TYPE_NAME", 
> > "DATA_TYPE";
> >                 $type_map->{$_->[$tni]} = $_->[$dti] for @$tia;
> >                 }
> >             }
> >
> > works just as well for me
> 
> Yes.

Change pushed to dir_search_hashes branch in DBI
This is the branch where I am currently working in to support the
missing features for DBD::File related DBD's like DBD::CSV

I wanted a clean test case before serious DBI::Test play started

> >>> +               }
> >>> +
> >>>               $attr eq "TYPE"      and
> >>> -               return [ map { $sth->{f_overall_defs}{$_}{data_type}   || 
> >>> "CHAR" }
> >>> +               return [ map { $type_map->{$_} || $_ }
> >>> +                        map { $sth->{f_overall_defs}{$_}{data_type}   || 
> >>> "VARCHAR" }
> >>>                               @colnames ];
> >>>
> >>>               $attr eq "PRECISION" and
> >>> -->8---
> >>>
> >>> All DBI tests still pass, and several TODO tests in DBD::CSV now pass
> >>>
> >>> If DBD::xxx provides GetInfo.pm and TypeInfo.pm, the conversions will
> >>> automatically be updated (once).
> >>
> >> It will work as it stands so long as type_info_all maps type_name and
> >> data_type as indexes 0 and 1. If that changes it looks like it will
> >> break.
> >
> > The chances that will ever change are ZERO
> 
> True but how many times have I fixed a bug because some coder made the same 
> assumption.

Assumption may well be the mother of all fuckups.
Knowing the underlying code however did make me know rather than assume
what I was doing, but as this is not *hot* code (it is only done once)
I agree with the portability change.

-- 
H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.19   porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/        http://www.test-smoke.org/
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/

Reply via email to