Skip to content

Support With statement for cursor class #517

@Chaho12

Description

@Chaho12

Describe the feature

In dbapi.py, i notice that Connection class DO have __enter__, __exit__, but Cursor class does not.

Is there a reason for why it doesn't have those classes? so that users can use with with statement?

with connection.cursor() as cursor:
    cursor.execute("SELECT * FROM table")
    results = cursor.fetchall()

Describe alternatives you've considered

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions