[egenix-users] mx.ODBC.windows Transaction Problem

M.-A. Lemburg mal at lemburg.com
Sat Sep 21 22:54:16 CEST 2002


Joe wrote:
> Hello everyone,
>  
> I am using the ODBC windows module to connect to a MSSQL 2000 server, 
> everything works except manual-transaction mode. I set it to 
> clear_auto_commit (default), so I can use .commit() and .rollback(), and 
> I get the Error: Attribute Error: commit. The docs say this means the 
> database doesn't support transactions but I know this isn't the case. I 
> have a perl script using DBI::ODBC that is able to use transactions. Do 
> I need to recompile the module with certain flags to allow the module to 
> recognize that the DB supports transactions? 

connection.commit() will always succeed -- even on connections which
don't support transactions. connection.rollback() will either
raise an AttributeError or NotSupportedError is the connection
does not support transactions.

 > Any light that could be
> shed on this problem would be appreciated! Here's a code snippet that 
> throws the AttributeError:
>  
> import mx.ODBC.Windows
>  
> db = mx.ODBC.Windows.DriverConnect('DSN=test;uid=xxx;pwd=xxx')
> cursor = db.cursor()
> cursor.execute("update users set name='bob' where users_pk = 15")
> cursor.commit()

.commit() is a method on the connection object, not the cursor.

When calling .commit on the connection you commit all work done
with all cursors currently working on the active transaction
and you implicitly start a new transaction (on all cursors still
possibly open on the connection).

> cursor.close
> db.close

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
_______________________________________________________________________
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting:                               http://www.egenix.com/
Python Software:                    http://www.egenix.com/files/python/




More information about the egenix-users mailing list