[CONPY-46] Cursors cannot act as a context manager Created: 2020-03-28  Updated: 2020-03-31  Resolved: 2020-03-31

Status: Closed
Project: MariaDB Connector/Python
Component/s: Generic
Affects Version/s: 0.9.55
Fix Version/s: 0.9.56

Type: New Feature Priority: Major
Reporter: Karl Levik Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None


 Description   

I noticed this feature request for the MySQL Python connector, and thought it might be useful for the MariaDB Python connector as well:
https://bugs.mysql.com/bug.php?id=89113

Most Python DB-API 2.0 compliant drivers can create cursors as a context manager, like so:

with conn.cursor() as cur:
    cur.execute(query)
    result = cur.fetchone()
print(result)

The cursor is created and assigned the identifier `cur`, and when exiting the scope, the cursor is automatically closed.



 Comments   
Comment by Georg Richter [ 2020-03-30 ]

I wonder if this should work for cursors only? How about connection?

Comment by Karl Levik [ 2020-03-30 ]

Connection seems to make a lot of sense, as well. I'm all for it. Yes, please!

Generated at Thu Feb 08 03:29:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.