mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #17671 - Cursors are now context managers.
This commit is contained in:
committed by
Anssi Kääriäinen
parent
04a2a6b0f9
commit
99c87f1410
@@ -111,6 +111,25 @@ In addition, the widgets now display a help message when the browser and
|
||||
server time zone are different, to clarify how the value inserted in the field
|
||||
will be interpreted.
|
||||
|
||||
Using database cursors as context managers
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Prior to Python 2.7, database cursors could be used as a context manager. The
|
||||
specific backend's cursor defined the behavior of the context manager. The
|
||||
behavior of magic method lookups was changed with Python 2.7 and cursors were
|
||||
no longer usable as context managers.
|
||||
|
||||
Django 1.7 allows a cursor to be used as a context manager that is a shortcut
|
||||
for the following, instead of backend specific behavior.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
c = connection.cursor()
|
||||
try:
|
||||
c.execute(...)
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
Minor features
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user