You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Ged Haywood <ge...@www2.jubileegroup.co.uk> on 2002/03/13 11:29:40 UTC

Re: Tie hashes in DBIx::Recordset [OT]

Hi there,

On Wed, 13 Mar 2002, Marcus Claesson wrote:

> How do I succesfully preserve the column order (''$fields'=>
> $joined_col') in my array-of-hashes generated using DBIx::Recordset?

Check out a Perl tutorial or the Camel book.  Perl's hashes do their own
thing with ordering, so unless you do something like (sort keys %hash)
you will get what you get.  Arrays can preserve sequences but involve
you in more coding much of the time.

73,
Ged.


Re: Tie hashes in DBIx::Recordset [OT]

Posted by Marcus Claesson <ma...@angiogenetics.se>.
>Perl's hashes do their own thing with ordering, so unless you do something
like (sort keys %hash)
>you will get what you get.

Yes, but tieing the hash while creating it, in my case with Tie::IxHash,
should preserve the inesertion order.
That works with for example
tie %hash, 'Tie::IxHash';
%hash = ("one"=>"1", "two"=>"2", "three"=>"3");
But not when I create an array of hashes using DBIx::Recordset like below:
________________
use Tie::IxHash;
use DBIx::Recordset;

...sub execute {
tie %main::set, 'Tie::IxHash';
*main::set = DBIx::Recordset->Search({('!DataSource' => $db,
'!Table'      => $table,
'$fields'     => $joined_col,
'$where'    => $query,
'$max'       => 10)});
....
}________________

Marcus

Ged Haywood wrote:

> Hi there,
>
> On Wed, 13 Mar 2002, Marcus Claesson wrote:
>
> > How do I succesfully preserve the column order (''$fields'=>
> > $joined_col') in my array-of-hashes generated using DBIx::Recordset?
>
> Check out a Perl tutorial or the Camel book.  Perl's hashes do their own
> thing with ordering, so unless you do something like (sort keys %hash)
> you will get what you get.  Arrays can preserve sequences but involve
> you in more coding much of the time.
>
> 73,
> Ged.


RE: Tie hashes in DBIx::Recordset [OT]

Posted by Jeff <ja...@aquabolt.com>.
Obviously sorting the hash keys wont give you the columns
in the select statement order.

After doing something like:
  my $sth = $dbh->execute(@params) or die...

You can get back the lower case column names in the select 
statement order using:
  my @names = @{$sth->{NAME_lc}};

Note that $sth->{NAME_lc} is not always populated, depending 
upon your SQL.

Regards

Jeff


-----Original Message-----
From: Ged Haywood [mailto:ged@www2.jubileegroup.co.uk] 
Sent: 13 March 2002 10:30
To: Marcus Claesson
Cc: modperl@perl.apache.org
Subject: Re: Tie hashes in DBIx::Recordset [OT]


Hi there,

On Wed, 13 Mar 2002, Marcus Claesson wrote:

> How do I succesfully preserve the column order (''$fields'=>
> $joined_col') in my array-of-hashes generated using DBIx::Recordset?

Check out a Perl tutorial or the Camel book.  Perl's hashes do their own
thing with ordering, so unless you do something like (sort keys %hash)
you will get what you get.  Arrays can preserve sequences but involve
you in more coding much of the time.

73,
Ged.