[egenix-users] No commit in connection context mgr

Jan Murre jan.murre at catalyz.nl
Tue Nov 8 17:09:24 CET 2016


Hi,

I am using the following code with a MS SQL database and the Microsoft
driver:

-----------
con = Connect(dsn, user=user,
    password=password, clear_auto_commit=1)

with con:
    with con.cursor() as cursor:
        cursor.callproc('proc_AddReservation_web', (12, None, 'nl-nl'))

        result = []
        while True:
            result.append(cursor.fetchall())
            if not cursor.nextset():
                break
-----------

Based on the documentation I would have expected a commit inside the
context manager.

When I use a conn.commit() or even a cursor.close() in the inner with block
(the cursor context manager), the transactions gets committed.

Setting clear_auto_commit=0 results in the following exception:

"mx.ODBC.Error.NotSupportedError: connection has AUTOCOMMIT turned on"
So, it seems one of the context mgr. does try to commit the transaction.



Furthermore, I want to add a try except block around the two context mgrs
to catch/log/reraise exceptions.
However, it seems that the context managers effectively swallow exceptions
and do not reraise them on __exit__.

Regards, Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /mailman-archives/egenix-users/attachments/20161108/7cbc8532/attachment.htm


More information about the egenix-users mailing list