ColtsFoot has asked for the wisdom of the Perl Monks concerning the following question:

I have some code that retrieves 20+ columns from an Oracle
database using DBD::ODBC. The last field is a large memo field.
I've included the line
$dbh->{LongReadLen} = 1024;
But when I try to use
@row = $sth->fetchrow_array();
I dont get any data back, on the otherhand if I use
$row = $sth->fetch();
and then extract the data using
$memofield = $$row[22];
things seem to work. Can anyone explain when I should use
fetch and when to use fetchrow_array.

TIA

Replies are listed 'Best First'.
Re: DBI::ODBC fetch and fetchrow_array
by BBQ (Curate) on Jul 24, 2000 at 19:25 UTC
    I have never heard of just plain fetch, even if I only need a single cell out of the database I will use fetchrow() and its friends. Works for me all the time. Have you tried switching from DBD::ODBC to DBD::Oracle? I have encountered unexpected behavior with DBD::ODBC in the past.

    Just my R$0.02 worth..

    #!/home/bbq/bin/perl
    # Trust no1!
      *fetchrow_arrayref = \&fetch;

      fetchrow_arrayref() is fetch() in disguise.

      -Matt

(CMonster: bind_columns) RE: DBI::ODBC fetch and fetchrow_array
by CMonster (Scribe) on Jul 24, 2000 at 20:21 UTC

    As a quick refresher, fetch is a synonym for fetchrow_arrayref, which in general will be faster than a fetchrow_array because it doesn't have to allocate more memory and assign more variables.

    In ColtsFoot's case, I think variable allocation might be part of the problem if dealing with Memo fields. Try checking the result of fetchrow_array for errors; the best way to do that is to turn on RaiseError and PrintError.

    You might also want to look at bind_columns, which gives the convenience of variables without the pain of re-assigning them for each row.

Re: DBI::ODBC fetch and fetchrow_array
by agoth (Chaplain) on Jul 24, 2000 at 20:24 UTC
    $sth->fetch is an alias for fetchrow_arrayref
    and
    $sth->fetchrow is an alias for fetchrow_array

    HTH