diff options
| author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2016-09-07 03:14:29 -0700 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-09-07 12:16:31 +0200 |
| commit | d923733234afd20304db763913020170709ef088 (patch) | |
| tree | 94093b83ffce8743d622cc7b7860ee87cda7d863 /docs/topics/db/sql.txt | |
| parent | fd183e1f819faa15a3205a1d9740ebfe3c8ebda0 (diff) | |
[1.10.x] Fixed #27172 -- Closed database cursor explicitly in two doc examples
Backport of ccf7adb064a70eb1b1ec5857f1dd54988f5c983c from master.
Diffstat (limited to 'docs/topics/db/sql.txt')
| -rw-r--r-- | docs/topics/db/sql.txt | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/docs/topics/db/sql.txt b/docs/topics/db/sql.txt index a7970928f1..14bf7f9725 100644 --- a/docs/topics/db/sql.txt +++ b/docs/topics/db/sql.txt @@ -250,12 +250,10 @@ For example:: from django.db import connection def my_custom_sql(self): - cursor = connection.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() + 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() return row |
