[ic] Redundant code in DBI.pm?

Mike Heins mikeh at perusion.com
Fri Mar 13 12:58:45 UTC 2015


Quoting Mike Heins (mikeh at perusion.com):
> Quoting Jon Jensen (jon at endpoint.com):
> > On Fri, 13 Mar 2015, Peter wrote:
> > 
> > >IRT this block of code in the create_sql function in DBI.pm:
> > >
> > >   for (my $i = 0;  $i < @$columns;  $i++) {
> > >       $cols[$i] = $$columns[$i];
> > >#::logDebug("checking column '$cols[$i]'");
> > >               if(defined $key) {
> > >                       $keycol = $i if $cols[$i] eq $key;
> > >               }
> > >               if(defined $config->{COLUMN_DEF}->{$cols[$i]}) {
> > >                       $cols[$i] .= " " .
> > >$config->{COLUMN_DEF}->{$cols[$i]};
> > >               }
> > >               else {
> > >                       $cols[$i] .= " $def_type";
> > >               }
> > >               $$columns[$i] = $cols[$i];
> > >               $$columns[$i] =~ s/\s+.*//;
> > >   }
> > >
> > >The last two lines of the loop look to be redundant to me.
> > >$$columns[$i] already contains the column name, and $cols[$i] contain
> > >the column definition which is the column name, followed by a space and
> > >other stuff, so the last two names write $cols[$i] back to $$columns[$i]
> > >then strip the space + other stuff off the end leaving just the column
> > >name ... which is what was in $$columns[$i] to begin with?
> > >
> > >Can we scrap those two lines or is there something I'm missing?
> > 
> > I read it that way too.
> > 
> > However, to avoid getting caught by anything "tricky, tricky" I
> > think you would want to put some heavy debugging in there before &
> > after and test pretty extensively.
> > 
> > It would also be good to hear from Mike whether he remembers any
> > obscure reason for this.
> 
> The reason is that at you can define the type in the column
> label of the table, i.e.
> 
> code	price decimal(12)	description varchar(200)	image
> 
> I don't think anyone has really ever used that, so it could
> go away if we want it to.

Just tested that out of curiosity:

catalog.cfg:

    Database  foo  foo.txt __SQLDSN__

In foo.txt:

    code varchar(33)	description varchar(233)	price decimal(12)
    1111	The inimitable product.	11.11
	
Yields:

    mysql> desc foo;
    +-------------+---------------+------+-----+---------+-------+
    | Field       | Type          | Null | Key | Default | Extra |
    +-------------+---------------+------+-----+---------+-------+
    | code        | varchar(33)   | YES  | MUL | NULL    |       | 
    | description | varchar(233)  | YES  |     | NULL    |       | 
    | price       | decimal(12,0) | YES  |     | NULL    |       | 
    +-------------+---------------+------+-----+---------+-------+
    3 rows in set (0.00 sec)

I see no reason to disturb it at this point. While I don't expect
anyone uses it, I did for some old things, and I am constantly amazed
at the old catalogs that are still out there.

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.253.4194  <mike at perusion.com>

The sun, with all those planets revolving around it and
dependent on it, can still ripen a bunch of grapes as if
it had nothing else in the universe to do. -- Galileo



More information about the interchange-users mailing list