Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement context manager for Cursors #190

Closed
gvenzl opened this issue Jun 20, 2018 · 1 comment
Closed

Implement context manager for Cursors #190

gvenzl opened this issue Jun 20, 2018 · 1 comment

Comments

@gvenzl
Copy link
Member

gvenzl commented Jun 20, 2018

Implement context manager for Cursor object to enable with statement.
Currently the with statement can't be used for cursors because they don't implement a context manager, i.e. the __enter__ and __exit__ attributes meaning that the following code will fail:

with conn.cursor() as c:
    c.execute("SELECT 'test' from dual")
    result = c.fetchall()
    print(result)

  File/Users/gvenzl/test/test.py”, line 23, in test
    with conn.cursor() as c:
AttributeError: __exit__

It would make sense to enable cursor object to be used in with statements that take care of closing the cursors automatically.

@anthony-tuininga
Copy link
Member

I agree that it would make sense to implement the context manager on cursors. Thanks @gvenzl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants