No commit in connection context mgr

Jan Murre <[email protected]> Tue, 8 Nov 2016 17:09:24 +0100
Newsgroups gmane.comp.python.egenix.user
Message-ID <CAE_3tvobivbN0Emwg7L_Z_rbf14CfzESifHZ4H9+MyFj9QBbRw@mail.gmail.com>
--===============64667941676901575==
Content-Type: multipart/alternative; boundary=001a11377e183b38c80540cc5d08

--001a11377e183b38c80540cc5d08
Content-Type: text/plain; charset=UTF-8

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

--001a11377e183b38c80540cc5d08
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div><div><div><div><div><div>Hi,<br><br></div>I=
 am using the following code with a MS SQL database and the Microsoft drive=
r:<br><br><span style=3D"font-family:monospace,monospace">-----------<br>co=
n =3D Connect(dsn, user=3Duser,<br>=C2=A0=C2=A0=C2=A0 password=3Dpassword, =
clear_auto_commit=3D1)<br><br>with con:<br>=C2=A0=C2=A0=C2=A0 with con.curs=
or() as cursor:<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cursor.callpr=
oc(&#39;proc_AddReservation_web&#39;, (12, None, &#39;nl-nl&#39;))<br><br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 result =3D []<br>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 while True:<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 result.append(cursor.fetchall())<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if not c=
ursor.nextset():<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break<br></span></div><span style=3D"f=
ont-family:monospace,monospace">-----------<br></span><br></div>Based on th=
e documentation I would have expected a commit inside the context manager.<=
br><br></div>When I use a conn.commit() or even a cursor.close() in the inn=
er with block (the cursor context manager), the transactions gets committed=
.<br><br></div>Setting clear_auto_commit=3D0 results in the following excep=
tion:<br><br>&quot;mx.ODBC.Error.NotSupportedError: connection has AUTOCOMM=
IT turned on&quot;<br></div><div>So, it seems one of the context mgr. does =
try to commit the transaction.<br></div><div><br><br><br></div>Furthermore,=
 I want to add a try except block around the two context mgrs to catch/log/=
reraise exceptions.<br></div>However, it seems that the context managers ef=
fectively swallow exceptions and do not reraise them on __exit__.<br><br></=
div>Regards, Jan<br><br></div>

--001a11377e183b38c80540cc5d08--


--===============64667941676901575==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit


_______________________________________________________________________
eGenix.com User Mailing List                     http://www.egenix.com/
https://www.egenix.com/mailman/listinfo/egenix-users

--===============64667941676901575==--