in reply to Weird DBI behaviour
my $array_ref = $select->fetchall_arrayref();
and actually use it. In the second, you call the above, but don't do anything with it as you subsequently call
You could fetch only the one-and-only column in the first snippent itself by doing the following --..$select->fetchrow_array
my $array_ref = $select->fetchall_arrayref([0]);
All that said, there is no reason I can think of why the ordering should be different.
Update: Try the following in the first snippet
# instead of my $array_ref = $select->fetchall_arrayref(); # try my $array_ref = $select->fetchall_arrayref;
From the DBI docs
I sometimes wish DBI were simpler in the naming conventions of its methods. I have always resisted using Class::DBI (I believe if a difficult task requires an abstraction to make it easier, then the task should be made easier in the first place), but I guess it is time to give in and start learning C::DBI and its ilk that attempt to make DBI easier to use.fetchall_arrayref $tbl_ary_ref = $sth->fetchall_arrayref; $tbl_ary_ref = $sth->fetchall_arrayref( $slice ); $tbl_ary_ref = $sth->fetchall_arrayref( $slice, $max_rows );The fetchall_arrayref method can be used to fetch all the data to be returned from a prepared and executed statement handle. It returns a reference to an array that contains one reference per row.
If there are no rows to return, fetchall_arrayref returns a reference to an empty array. If an error occurs, fetchall_arrayref returns the data fetched thus far, which may be none. You should check $sth->err afterwards (or use the RaiseError attribute) to discover if the data is complete or was truncated due to an error.
If $slice is an array reference, fetchall_arrayref uses "fetchrow_arrayref" to fetch each row as an array ref. If the $slice array is not empty then it is used as a slice to select individual columns by perl array index number (starting at 0, unlike column and parameter numbers which start at 1).
With no parameters, or if $slice is undefined, fetchall_arrayref acts as if passed an empty array ref.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Weird DBI behaviour
by Joost (Canon) on Aug 19, 2005 at 13:23 UTC | |
Re^2: Weird DBI behaviour
by jZed (Prior) on Aug 19, 2005 at 15:45 UTC | |
by punkish (Priest) on Aug 19, 2005 at 16:38 UTC | |
by jZed (Prior) on Aug 19, 2005 at 16:47 UTC |