1
0
mirror of https://github.com/django/django.git synced 2025-06-05 03:29:12 +00:00

[1.10.x] Fixed #27172 -- Closed database cursor explicitly in two doc examples

Backport of ccf7adb064a70eb1b1ec5857f1dd54988f5c983c from master.
This commit is contained in:
Chris Jerdonek 2016-09-07 03:14:29 -07:00 committed by Claude Paroz
parent fd183e1f81
commit d923733234
2 changed files with 16 additions and 18 deletions

View File

@ -67,7 +67,7 @@ returns a list of all ``OpinionPoll`` objects, each with an extra
class PollManager(models.Manager):
def with_counts(self):
from django.db import connection
cursor = connection.cursor()
with connection.cursor() as cursor:
cursor.execute("""
SELECT p.id, p.question, p.poll_date, COUNT(*)
FROM polls_opinionpoll p, polls_response r

View File

@ -250,10 +250,8 @@ For example::
from django.db import connection
def my_custom_sql(self):
cursor = connection.cursor()
with connection.cursor() as cursor:
cursor.execute("UPDATE bar SET foo = 1 WHERE baz = %s", [self.baz])
cursor.execute("SELECT foo FROM bar WHERE baz = %s", [self.baz])
row = cursor.fetchone()