Click here to get back home

$db->DataHash does not return keys/fields in same order as they appear in database

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
$db->DataHash does not return keys/fields in same order as they appear in database dtshedd 09-16-2007
Get Chitika Premium
Posted by dtshedd on September 16, 2007, 11:59 am
Please log in for more thread options


I am using the following code adapted from
http://www.roth.net/perl/odbc/docs/object/
to try and capture the field names of a database. The odd thing is
that the fields names are not returned in the order they appear in the
table. I know from the aforementioned site there is a sort option but
the order of the field names in the table are not in alphabetical
order. any way to get the returned field names in the order in which
they appear in the Access database?

TIA

Dan

**

$db->Sql("SELECT * FROM Groups");
$db->FetchRow();
%hash = $db->DataHash;
foreach $key (keys %hash) {
        @fields[$i]=$key;
print "my field $fields[$i]\n";
$i++;

}


Posted by Mike Pomraning on September 16, 2007, 4:48 pm
Please log in for more thread options


dtshedd@yahoo.com wrote:
> I am using the following code adapted from
http://www.roth.net/perl/odbc/docs/object/
> to try and capture the field names of a database. The odd thing is
> that the fields names are not returned in the order they appear in the
> table. I know from the aforementioned site there is a sort option but
> the order of the field names in the table are not in alphabetical
> order. any way to get the returned field names in the order in which
> they appear in the Access database?

Please read "perldata". Perl's hashes aren't ordered, so this behavior
is, to my mind, expected. Also, the sort option you refer to seems
rather to be the sort function ("perldoc -f sort").

Now, Win32::ODBC, the module in question, doesn't seem guarantee the
order of db field names in any case. See its documentation for the
FieldNames() method, for instance.

Finally, ask yourself if the "physical" order of the columns really
matters. As long as you can discriminate field 'foo' from field 'bar',
what does their internal database layout matter?

Regards,
Mike

Similar ThreadsPosted
Apache::SSIChain Out of Order November 8, 2004, 8:40 pm
Module loading order February 12, 2006, 11:42 pm
Which module should I use in order to load files over the internet? October 5, 2006, 3:38 pm
system return value? January 26, 2007, 5:52 pm
Net::Cmd::code doesn't return value of Net::Cmd::dataend January 10, 2005, 9:17 pm
Parsing return message from fetchmail June 27, 2006, 3:04 pm
SSH Modules: Accessing CLI box using SSH and not getting the return output?? November 12, 2006, 11:48 pm
Net::SSH::W32Perl Script hanging when trying to return data March 10, 2005, 1:14 pm
Net::SSH::W32Perl Script hanging when trying to return data March 10, 2005, 1:30 pm
Return keys from $db->DataHash directly into an array September 16, 2007, 11:56 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap