Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixes #2658 -- Modified SQLite cursor close() method for in-memory da…

…tabases, making the lifespan of an in-memory database equal to the life of the process, rather than the life of the cursor. Thanks, Ned Batchelder.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3723 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6f87b17a0d0da75767d0bbf05d52f787e897c599 1 parent 6417d6c
Russell Keith-Magee authored September 05, 2006
5  django/db/backends/sqlite3/base.py
@@ -62,7 +62,10 @@ def _rollback(self):
62 62
             self.connection.rollback()
63 63
 
64 64
     def close(self):
65  
-        if self.connection is not None:
  65
+        from django.conf import settings
  66
+        # If database is in memory, closing the connection destroys the database.
  67
+        # To prevent accidental data loss, ignore close requests on an in-memory db.
  68
+        if self.connection is not None and settings.DATABASE_NAME != ":memory:":
66 69
             self.connection.close()
67 70
             self.connection = None
68 71
 
7  django/test/utils.py
@@ -95,10 +95,11 @@ def destroy_test_db(old_database_name, verbosity=1):
95 95
     # connected to it.
96 96
     if verbosity >= 1:
97 97
         print "Destroying test database..."
  98
+    connection.close()
  99
+    TEST_DATABASE_NAME = settings.DATABASE_NAME
  100
+    settings.DATABASE_NAME = old_database_name
  101
+
98 102
     if settings.DATABASE_ENGINE != "sqlite3":
99  
-        connection.close()
100  
-        TEST_DATABASE_NAME = settings.DATABASE_NAME
101  
-        settings.DATABASE_NAME = old_database_name
102 103
         cursor = connection.cursor()
103 104
         _set_autocommit(connection)
104 105
         time.sleep(1) # To avoid "database is being accessed by other users" errors.

0 notes on commit 6f87b17

Please sign in to comment.
Something went wrong with that request. Please try again.