Skip to content

Commit

Permalink
Fixes #2658 -- Modified SQLite cursor close() method for in-memory da…
Browse files Browse the repository at this point in the history
…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
freakboy3742 committed Sep 5, 2006
1 parent 6417d6c commit 6f87b17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion django/db/backends/sqlite3/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def _rollback(self):
self.connection.rollback()

def close(self):
if self.connection is not None:
from django.conf import settings
# If database is in memory, closing the connection destroys the database.
# To prevent accidental data loss, ignore close requests on an in-memory db.
if self.connection is not None and settings.DATABASE_NAME != ":memory:":
self.connection.close()
self.connection = None

Expand Down
7 changes: 4 additions & 3 deletions django/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ def destroy_test_db(old_database_name, verbosity=1):
# connected to it.
if verbosity >= 1:
print "Destroying test database..."
connection.close()
TEST_DATABASE_NAME = settings.DATABASE_NAME
settings.DATABASE_NAME = old_database_name

if settings.DATABASE_ENGINE != "sqlite3":
connection.close()
TEST_DATABASE_NAME = settings.DATABASE_NAME
settings.DATABASE_NAME = old_database_name
cursor = connection.cursor()
_set_autocommit(connection)
time.sleep(1) # To avoid "database is being accessed by other users" errors.
Expand Down

0 comments on commit 6f87b17

Please sign in to comment.