develooper Front page | perl.dbi.users | Postings from July 2006

Re: [dbi] Execute marks end of transaction?

Thread Previous | Thread Next
From:
Jonathan Leffler
Date:
July 11, 2006 09:19
Subject:
Re: [dbi] Execute marks end of transaction?
Message ID:
844b8e1c0607110918m2a51169bnb5c335be7b8e0405@mail.gmail.com
On 7/11/06, Martin J. Evans <martin.evans@easysoft.com> wrote:
>
>
> On 11-Jul-2006 Jimmy Li wrote:
> > Can I end a transaction as soon as I call execute()?
>
> Yes


Depends on the statement, of course, and the AutoCommit mode.  For something
other than a cursor-based statement (fetch, or sometimes some versions of
SQL function calls), that will terminate the transaction immediately if
AutoCommit is on.

> or do I have to wait
> > until I finish fetching all the rows?
>
> No
>
> > For example, I have:
> >
> > ----------
> >     $dbh->do("start transaction");
> >
> >     my $groups_query = $dbh->prepare(qq{select id, name from
> staff_grp});
> >     $groups_query->execute;
> >
> ># place1
>
>       $groups_query->finish if (want_to_stop_here);


That finishes the statement (or closes the cursor) - it does not directly do
anything to the transaction.  To finish the transaction, you call
$dbh->commit or $dbh->rollback.  If AutoCommit is on, then maybe the
transaction is completed on finish.

>     while (my @one_group = $groups_query->fetchrow_array)
> >     {
> >         print @one_group;
> >     }
> >
> >#place 2
> >
> > ----------
> >
> > Can I end the transaction in #place1 or do I have to wait until #place2?
>
> See above.
>


-- 
Jonathan Leffler <jonathan.leffler@gmail.com>  #include <disclaimer.h>
Guardian of DBD::Informix - v2005.02 - http://dbi.perl.org
"I don't suffer from insanity - I enjoy every minute of it."

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About