DBI + ODBC - Which Fetch? Having executed the query and marked the selected rows for retrieval, there are various methods available in DBI to fetch the data. - fetchrow_array
This retrieves one row at a time - you call it until you get undef as the return value, which indocates that there are no more rows to return.
while(@returnRow = $stHandle->fetchrow_array()) { # process row }
@returnRow is an array of fields in the row, - fetchrow_arrayref/fetch
fetch is the shorthand version of fetchrow_arrayref and is faster than fetchrow_array
while($returnRowRef = $stHandle->fetch()) { # process row reference }
Instead of retrieving a new copy for each row, fetchrow_arayref returns a reference to an internal copy that is filled with the current row's data. Each call to fetch/fetchrow_arrayref populates the internal array with the next row's data and returns the reference. Again, if undef is returned there are no more rows. - fetchrow_hashref
Instead of returning an array reference like fetchrow_arrayref, this method returns a reference to a hash, where the keys are the column names and the values are the data. We gain knowledge of the column names without having to resort to driver-specific metadata, but we lose performance.
while($returnHashRef = $stHandle->fetchrow_hashref()) { # process row hash reference }
| | |