mirror of
https://github.com/django/django.git
synced 2025-10-14 20:41:00 +00:00
Ensure cursors are closed when no longer needed.
This commit touchs various parts of the code base and test framework. Any found usage of opening a cursor for the sake of initializing a connection has been replaced with 'ensure_connection()'.
This commit is contained in:
parent
0837eacc4e
commit
3ffeb93186
31 changed files with 657 additions and 615 deletions
|
@ -30,11 +30,11 @@ class Article(models.Model):
|
|||
database query for the sake of demonstration.
|
||||
"""
|
||||
from django.db import connection
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
SELECT id, headline, pub_date
|
||||
FROM custom_methods_article
|
||||
WHERE pub_date = %s
|
||||
AND id != %s""", [connection.ops.value_to_db_date(self.pub_date),
|
||||
self.id])
|
||||
return [self.__class__(*row) for row in cursor.fetchall()]
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("""
|
||||
SELECT id, headline, pub_date
|
||||
FROM custom_methods_article
|
||||
WHERE pub_date = %s
|
||||
AND id != %s""", [connection.ops.value_to_db_date(self.pub_date),
|
||||
self.id])
|
||||
return [self.__class__(*row) for row in cursor.fetchall()]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue