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

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

am 16.09.2007 17:59:41 von dtshedd

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++;

}

Re: $db->DataHash does not return keys/fields in same order as theyappear in database

am 16.09.2007 22:48:02 von Mike Pomraning

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