Joshua D. Drake wrote: > > On 09/14/2011 10:25 AM, Michael Bayer wrote: >> >> >> On Sep 14, 2011, at 12:56 PM, Joshua D. Drake wrote: >> >>> No. What I am saying is, the begin() is optional. If you look at my >>> example, if PostgreSQL is in autocommit mode, the only way to start a >>> transaction is to execute a query to start the transaction (BEGIN or >>> START TRANSACTION). From a, "it would be nice if" perspective, I >>> would like to have the option of using .begin() to start a >>> transaction. That seems to jive better with proper coding. >>> >> >> "proper" on postgresql sure. On Oracle, there is no BEGIN. I like >> that the DBAPI tries to simplify this disconnect with a consistent, >> moderately coarse-grained facade rather than confusing users and >> burdening DBAPI authors with two ways to do it. >> > > Thus the "optional". Those that can make use of it can, those that don't > don't need it or it will be silently ignored.
I find the following is more readable (explicit better then implicit etc.): connection = connect(dbname, uid, pwd) # Regular user code: ... transactional code ... # Experts only section: try: connection.autocommit = True ... non-transactional code ... finally: connection.autocommit = False # Regular user code: ... transactional code ... connection.commit() You usually only need autocommit code in case you are dealing with databases that cannot handle database definition SQL (DDL) inside transactions (e.g. create/drop databases or tables), if you have a need for atomic operations, or need to avoid locking for some special reason. In practice, it's often better to open a separate connection in autocommit mode, than to switch modes on a single connection. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 14 2011) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2011-10-04: PyCon DE 2011, Leipzig, Germany 20 days to go ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig