Re: [DB-SIG] DB API extension suggestion

2007-06-22 Thread Dieter Maurer
Anthony Tuininga wrote at 2007-6-21 16:39 -0600: > ... >> Is your transaction-controlling implementation of >> connection.__enter__/__exit__ already released, i.e. is it too late to >> get you to change the API to this feature? > >I have not released this publicly yet, no. It would be a good idea t

Re: [DB-SIG] DB API extension suggestion

2007-06-22 Thread Robert Brewer
Anthony Tuininga wrote: > Hmm, I've thought about this a bit more. If you look at the module > contextlib in the Python 2.5 standard library you can see that making > connections and cursors context managers that simply close themselves > is redundant. You can do this instead: > > with contextlib.

Re: [DB-SIG] DB API extension suggestion

2007-06-22 Thread Anthony Tuininga
Hmm, I've thought about this a bit more. If you look at the module contextlib in the Python 2.5 standard library you can see that making connections and cursors context managers that simply close themselves is redundant. You can do this instead: with contextlib.closing(connection.cursor()) as curs

Re: [DB-SIG] DB API extension suggestion

2007-06-21 Thread Carsten Haese
On Thu, 2007-06-21 at 16:39 -0600, Anthony Tuininga wrote: > I have not released this publicly yet, no. It would be a good idea to > have agreement on this rather than have conflicting implementations. Indeed. I see two alternatives, modulo naming: 1) A connection method: with conn.transaction()

Re: [DB-SIG] DB API extension suggestion

2007-06-21 Thread Anthony Tuininga
On 6/21/07, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Thu, 2007-06-21 at 14:26 -0600, Anthony Tuininga wrote: > > On 6/21/07, Carsten Haese <[EMAIL PROTECTED]> wrote: > > > with api.connect(dbname) as conn: > > >with conn.cursor() as cur: > > > cur.execute(stmt) > > > > That's interes

Re: [DB-SIG] DB API extension suggestion

2007-06-21 Thread Carsten Haese
On Thu, 2007-06-21 at 14:26 -0600, Anthony Tuininga wrote: > On 6/21/07, Carsten Haese <[EMAIL PROTECTED]> wrote: > > with api.connect(dbname) as conn: > >with conn.cursor() as cur: > > cur.execute(stmt) > > That's interesting but is it of much use? Connections and cursors > close themse

Re: [DB-SIG] DB API extension suggestion

2007-06-21 Thread Anthony Tuininga
On 6/21/07, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Thu, 2007-06-21 at 10:41 -0600, Anthony Tuininga wrote: > > I have been recently playing with context managers and the new "with" > > statement added in Python 2.5. I would like to suggest the addition of > > the following methods to connec

Re: [DB-SIG] DB API extension suggestion

2007-06-21 Thread Michael Kleehammer
I'm not sure if there is a need for context support at the moment. Almost all databases automatically rollback transactions if they are not committed before a connection is closed. In the pyodbc connection finalizer, I automatically issue a rollback if a commit didn't occur. Since CPython uses re

Re: [DB-SIG] DB API extension suggestion

2007-06-21 Thread Carsten Haese
On Thu, 2007-06-21 at 10:41 -0600, Anthony Tuininga wrote: > I have been recently playing with context managers and the new "with" > statement added in Python 2.5. I would like to suggest the addition of > the following methods to connections: > > def __enter__(self): > return self > > def _

Re: [DB-SIG] DB API extension suggestion

2007-06-21 Thread M.-A. Lemburg
On 2007-06-21 18:41, Anthony Tuininga wrote: > I have been recently playing with context managers and the new "with" > statement added in Python 2.5. I would like to suggest the addition of > the following methods to connections: > > def __enter__(self): > return self > > def __exit__(self,

Re: [DB-SIG] DB API extension suggestion

2007-06-21 Thread Robert Brewer
Anthony Tuininga wrote: > I have been recently playing with context managers and the new "with" > statement added in Python 2.5. I would like to suggest the addition of > the following methods to connections: > > def __enter__(self): > return self > > def __exit__(self, excType, excValue, ex

[DB-SIG] DB API extension suggestion

2007-06-21 Thread Anthony Tuininga
I have been recently playing with context managers and the new "with" statement added in Python 2.5. I would like to suggest the addition of the following methods to connections: def __enter__(self): return self def __exit__(self, excType, excValue, excTraceback): if excType is None and