From 29ff2bb4cbc7ffa3193ba0cec48308cf0f4c1295 Mon Sep 17 00:00:00 2001
From: Adrian Holovaty <adrian@holovaty.com>
Date: Mon, 10 Oct 2005 20:14:56 +0000
Subject: [PATCH] Improved django.core.management.get_sql_delete to close
 database connection explicitly when it's done, to avoid locking issues

git-svn-id: http://code.djangoproject.com/svn/django/trunk@823 bcc190cf-cafb-0310-a4f2-bffc1f526a37
---
 django/core/management.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/django/core/management.py b/django/core/management.py
index afb498ae63..046031e311 100644
--- a/django/core/management.py
+++ b/django/core/management.py
@@ -144,6 +144,10 @@ def get_sql_delete(mod):
         for row in cursor.fetchall():
             output.append("DELETE FROM auth_admin_log WHERE content_type_id = %s;" % row[0])
 
+    # Close database connection explicitly, in case this output is being piped
+    # directly into a database client, to avoid locking issues.
+    db.db.close()
+
     return output[::-1] # Reverse it, to deal with table dependencies.
 get_sql_delete.help_doc = "Prints the DROP TABLE SQL statements for the given model module name(s)."
 get_sql_delete.args = APP_ARGS