Re: Mixed Case Column Names

[prev] [thread] [next] [Date index for 2005/04/14]

From: Kingsley Kerce
Subject: Re: Mixed Case Column Names
Date: 14:54 on 14 Apr 2005
Jay Hargreaves writes:
 > In fact the workaround I provided doesn't appear to work either - I 
 > guess columns() does not use the mutator_name() method as I had expected.
 > 
 > I've also just noticed that columns() does not provide the columns in 
 > the order I listed them - which is also the order they appear in the 
 > table. Is there anyway they can be returned in the correct order?

Your ordering requirement may be satisfied by something similar to the
following.  Untested and possibly pseudocode.

package TPG_Staging;
use base TPG_DBI;

@primary_columns = qw(ClientID);
@other_columns = qw(JobReference SSC PostcodeArea Format LT_60g Machinable BagWeight BagItems Sortation AccessSiteCode AccessPoint BagID CollectionDate HandoverDate ServiceRegister MailingHouseID);

__PACKAGE__->table("Staging");
__PACKAGE__->columns(Primary => @primary_columns);
__PACKAGE__->columns(Others => @other_columns);

sub my_columns {
  return (@primary_columns, @other_columns);
}

# ...later...

my @columns = TPG_Staging->my_columns;

If you don't like the method name my_columns() then figure out how to
override the columns() method appropriately.

If a module doesn't do what you want then code overrides that do.

Kings

 > 
 > Thanks
 > Jay
 > 
 > Jay Hargreaves wrote:
 > > Hi everyone!
 > > 
 > > I have the following table module:
 > > 
 > > --- TPG_Staging.pm ---
 > > package TPG_Staging;
 > > use base TPG_DBI;
 > > 
 > > __PACKAGE__->table("Staging");
 > > __PACKAGE__->columns(Primary => qw(ClientID));
 > > __PACKAGE__->columns(Others => qw(JobReference SSC PostcodeArea Format 
 > > LT_60g Machinable BagWeight BagItems Sortation AccessSiteCode 
 > > AccessPoint BagID CollectionDate HandoverDate ServiceRegister 
 > > MailingHouseID));
 > > ---
 > > 
 > > When I query the columns that are contained in the table:
 > > 
 > > my @columns = TPG_Staging->columns;
 > > 
 > > I receive a list of the columns as expected but with all the the names 
 > > in lower case. It is important that the column names are presented AS IS 
 > > since they are used directly in my user interface.
 > > 
 > > Is this lower-casing always the case with Class::DBI? I have not 
 > > experienced this problem before as I tend to use lower-case column names 
 > > as standard. Is there a way around this problem other than providing 
 > > explicit mappings from the lower-case name to the uppercase name:
 > > 
 > > ---
 > > # accessor is simple enough
 > > sub accessor_name
 > > { my ($class, $column) = @_;
 > >   return lc $column;
 > > }
 > > 
 > > # mutator requires explicit mapping
 > > sub mutator_name
 > > { my ($class, $column) = @_;
 > >   my %mutator = ( clientid => 'ClientID',
 > >                   jobreference => 'JobReference',
 > >                   ...
 > >                 );
 > >   return $mutator($column);
 > > }
 > > ---
 > > 
 > > I am using Class::DBI 0.96 on Windows XP with MySQL ver 4.0.15.
 > > 
 > > Thanks
 > > Jay
 > > 
 > 
 > -- 
 > a: 89 hodge lane, hartford, northwich, cw8 3ag
 > m: 07899 872 306
 > e: jay@xxxxxxx.xxx
 > 
 > ______________________________________________________________________
 > This email has been scanned by the MessageLabs Email Security System.
 > For more information please visit http://www.messagelabs.com/email 
 > ______________________________________________________________________

Mixed Case Column Names
Jay Hargreaves 14:26 on 14 Apr 2005

Re: Mixed Case Column Names
Jay Hargreaves 14:40 on 14 Apr 2005

Re: Mixed Case Column Names
Dana Hudes 14:50 on 14 Apr 2005

Re: Mixed Case Column Names
Kingsley Kerce 14:54 on 14 Apr 2005

Re: Mixed Case Column Names
Jay Hargreaves 15:45 on 14 Apr 2005

Re: Mixed Case Column Names
Daniel Wijnands 14:51 on 14 Apr 2005

Re: Mixed Case Column Names
Tony Bowden 17:34 on 14 Apr 2005

Generated at 12:49 on 16 Apr 2005 by mariachi v0.52