IMHO it depends on your needs. Usually the 4th will try some sort of error
recovery and if that fails, rollback itself. This bubbles up until it
reaches the top. 

-----Ursprüngliche Nachricht-----
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Gesendet: Montag, 9. April 2007 19:50
An: sqlite-users@sqlite.org
Cc: [EMAIL PROTECTED]
Betreff: Fwd: Re: [sqlite] SQLite and nested transactions

I'm still learning how databases and transactions work so bear with me.
How does error handling work?

If I have 5 nested transactions and the 5th transaction fails is this
transaction failure supposed to be communicated to the parent or does the
fourth transaction try to do error recovery?
Ray

> Date: Mon, 9 Apr 2007 9:38:16 -0700
> From:  <[EMAIL PROTECTED]>
> To: sqlite-users@sqlite.org
> Cc: Dennis Cote <[EMAIL PROTECTED]>
> Subject: Re: [sqlite] SQLite and nested transactions
> 
> 
> So. If i read this code right.
> * The transaction_level keeps track of how many nested transactions have
occurred.
> * Only the parent transaction allows the commit.
> 
> In this case, only a single journal is required (the parent journal).
> Thanks,
> Ray
> 
> 
> ---- Dennis Cote <[EMAIL PROTECTED]> wrote: 
> > Darren Duncan wrote:
> > >
> > > I will clarify that child transactions are just an elegant way of 
> > > partitioning a larger task, and that parent transactions always 
> > > overrule children; even if a child transaction commits 
> > > successfully, a rollback of its parent means there are no lasting
changes.
> > Darren,
> > 
> > Because of this, and the fact that a transaction is basically a 
> > guarantee that all or none of the enclosed statements are executed, 
> > it is much simpler to implement nested transactions using a counter 
> > and the existing transaction API in a set of wrapper functions. 
> > There is no need to maintain all the intermediate state information. 
> > All you need to know is the current nesting level, and if any 
> > enclosed transaction was rolled back.
> > 
> > The following code shows the basic process.
> > 
> >     int transaction_level = 0;
> >     bool transaction_failed;
> > 
> >     void begin_nested_transaction()
> >     {
> >         if (transaction_level++ == 0) {
> >             transaction_failed = false;
> >             sqlite3_exec("begin");
> >         }
> >     }
> > 
> >     void commit_nested_transaction()
> >     {
> >         if (--transaction_level == 0)
> >             if (transaction_failed)
> >                 sqlite3_exec("rollback");
> >             else
> >                 sqlite3_exec("commit");
> >     }
> > 
> >     void rollback_nested_transaction()
> >     {
> >         transaction_failed = true;
> >         commit_transaction();
> >     }
> > 
> > HTH
> > Dennis Cote
> > 
> > --------------------------------------------------------------------
> > --------- To unsubscribe, send email to 
> > [EMAIL PROTECTED]
> > --------------------------------------------------------------------
> > ---------
> > 
> 
> 
> ----------------------------------------------------------------------
> ------- To unsubscribe, send email to 
> [EMAIL PROTECTED]
> ----------------------------------------------------------------------
> -------
> 


----------------------------------------------------------------------------
-
To unsubscribe, send email to [EMAIL PROTECTED]
----------------------------------------------------------------------------
-



-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to