in reply to Re: Re: DBI (Prepare once execute many fails)
in thread DBI (Prepare once execute many fails)

to clarify... it is neccesary when you don' want to retrieve all the data provided by a select statement, which should rarely be the case since you would filter the rows via your query. but in most cases of $sth->execute() it is not neccesary because most ppl do while(@row=$sth->fetchrow_array){} and if it doesn' work update drivers correct?

Replies are listed 'Best First'.
Re: Re: Re: Re: DBI (Prepare once execute many fails)
by runrig (Abbot) on Jun 06, 2003 at 21:25 UTC
    to clarify... it is neccesary when you don' want to retrieve all the data provided by a select statement
    If it is necessary in any DBD driver, then it should be considered a bug and reported to the author as such. The only reason to call finish is to free up any temporary database resources that your statement might be using, e.g. a temporary table required for an "order by" clause. As mentioned elsewhere, the DBD itself should be calling finish itself before an execute on an active statement handle. That being said, if you're only fetching one row, you ought to call finish, but it shouldn't be necessary. If that fixes the OP's problem, then there's a bug in the DBD he's using.
Re: Re: Re: Re: DBI (Prepare once execute many fails)
by Itatsumaki (Friar) on Jun 06, 2003 at 18:41 UTC

    Grygonos, it seems gmax and I disagree on this point.

    My understanding is that DBI specifies that execute() is called on an active-statement handle, the DBD is supposed to automatically reset the Active flag (i.e. call finish()). Discussions on the DBI mailing list seem to have come to the consensus that finish() is unnecessary and can hide real problems. The one case where it might be useful is to instruct the DB to free up resources after you're done with an $sth that hasn't been fully fetched through.

    So, in summary my reading of the documentation indicates it isn't needed and should be avoided as much as possible. There was a pretty extensive discussion of this in December/January on the list dbi-users@perl.org which you might want to check out.

    For DBD::ODBC there was a bug in versions prior to 1.02 that required finish() in certain circumstances, but that has been resolved and it's worth upgrading to a more recent version.

    Hope this helps!


    -Tats