I would like to propose adding support to pyodbc to enable its use as
a context manager. That is, I would like the following to work:
import pyodbc
with pyodbc.connect (dsn='mydb') as conn:
with conn.cursor() as curs:
with curs.execute('select * from mytable) as selected:
for row in selected:
#do something useful
This will mean adding __enter__ and __exit__ methods to these
objects. I propose that __enter__ just return the object and __exit__
do something like:
1. for pyodbc.connect -- automatically close the connection
2. for cursor objects -- automatically commit (unless autocommit=false
in connect) and close the cursor
3. for execute -- not sure yet (maybe not as useful)