Angel has asked for the wisdom of the Perl Monks concerning the following question:
I keep doing stuff like this when I have to get a whole bunch of fields from a database and I want to not use hashref since I know array ref is faster.
Basically I make a select query and then get the array back and then dump each element from the array into the variable I need.
I thought about making an array of the fields and looping though the result array, but there probably is some magic answer I can't figure out.
thanks in advance
my $sqlQuery = "SELECT Object_ID, ID, Script_Name, Sql_Name, Min_Length, Max_Length, Char_Regex, Char_Allowed, Key_Test_Type, Key_Test_Table, Key_Test_Field, Update_Allowed, Display_Transform, Update_Transform, FieldType, FieldDataSource, Display_Order FROM OM_ObjectMetaData WHERE OM_ObjectMetaData.Object_ID = ?"; #print "<!-- $sqlQuery -->\n\n\n\n\n"; my $query = $dbh->prepare( $sqlQuery ); $query->execute( $self->{ID} ) || die $dbh->errstr; while( @result_array = $query->fetchrow_array ) { $self->{fields}{$result_array[2]}{Object_ID} = $result +_array[0]; $self->{fields}{$result_array[2]}{ID} = $result +_array[1]; $self->{fields}{$result_array[2]}{Script_Name} = $result +_array[2]; $self->{fields}{$result_array[2]}{Sql_Name} = $result +_array[3]; $self->{fields}{$result_array[2]}{Min_Length} = $re +sult_array[4]; $self->{fields}{$result_array[2]}{Max_Length} = $res +ult_array[5]; $self->{fields}{$result_array[2]}{Char_Regex} = $res +ult_array[6]; $self->{fields}{$result_array[2]}{Char_Allowed} = $resul +t_array[7]; $self->{fields}{$result_array[2]}{Key_Test_Type} = $res +ult_array[8]; $self->{fields}{$result_array[2]}{Key_Test_Table} = $result +_array[9]; $self->{fields}{$result_array[2]}{Key_Test_Field} = $result +_array[10]; $self->{fields}{$result_array[2]}{Update_Allowed} = $result +_array[11]; $self->{fields}{$result_array[2]}{Display_Transform} = $result +_array[12]; $self->{fields}{$result_array[2]}{Update_Transform} = $result +_array[13]; $self->{fields}{$result_array[2]}{FieldType} = $result +_array[14]; $self->{fields}{$result_array[2]}{FieldDataSource} = $result +_array[15]; $self->{fields}{$result_array[2]}{DisplayOrder} = $result +_array[16]; $self->{fields}{$result_array[2]}{Value} = ""; $self->{display_order}{$result_array[16]} = $result_array[2]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Better way of accessing fields
by matija (Priest) on Mar 18, 2004 at 19:28 UTC | |
|
Re: Better way of accessing fields
by pbeckingham (Parson) on Mar 18, 2004 at 19:36 UTC | |
|
Re: Better way of accessing fields
by jZed (Prior) on Mar 18, 2004 at 19:10 UTC | |
|
Re: Better way of accessing fields
by kvale (Monsignor) on Mar 18, 2004 at 19:22 UTC |