[DB-SIG] DB-API 1.1

Michael Dietrich mdt@mdt.in-berlin.de
Thu, 4 Jun 1998 09:49:24 +0200


> > commit() 
> > 
> >      Commit any pending transaction to the database. Note that if the
> >      database supports an auto-commit feature, this must be initially
> >      off. An interface method may be provided to turn it back on.
> > 
> > rollback() 
> > 
> >      Roll the database back to the start of any pending
> >      transaction. Note that closing a connection without committing
> >      the changes first will cause an implicit rollback to be
> >      performed.
> 
> Why not have a begin() method?
i like another aproach: i would like to see a transaktionobject, where
the transaction is the livetime of the object. this object has the
methode commit() to really mark all transactions as really. if you get
an exception or forget to call commit() the default is to rollback
every db-change. for any change in the database you need a
transaction-object, so the programmer is forced to use it.
an example:

	t = db.Tramsaction()
	db.Execute(t, 'INSERT ....')
	db.Execute(t, 'DELETE ....')
	db.Execute(t, 'DELETE ....')
	t.Commit()
	t = None

i used this abroach succesfully with c++. most programmers in this
project began to like that. it's easy and you can't forget anything
except the commit. but you immideatly see that. 
another thing is the nested transaction, which is forbidden with most
databases. our transactionclass in that project only commited the
outermost transaction, while all inner transactions where ignored,
that means you could neither commit nor rollback them. so only the
whole transaction could be commited and that's what a transaction is
for.

-- 
see header