Author: russellm
Date: 2006-09-05 08:32:08 -0500 (Tue, 05 Sep 2006)
New Revision: 3723
Modified:
django/trunk/django/db/backends/sqlite3/base.py
django/trunk/django/test/utils.py
Log:
Fixes #2658 -- Modified SQLite cursor close() method for in-memory databases,
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.
Modified: django/trunk/django/db/backends/sqlite3/base.py
===================================================================
--- django/trunk/django/db/backends/sqlite3/base.py 2006-09-05 00:26:14 UTC
(rev 3722)
+++ django/trunk/django/db/backends/sqlite3/base.py 2006-09-05 13:32:08 UTC
(rev 3723)
@@ -62,7 +62,10 @@
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
Modified: django/trunk/django/test/utils.py
===================================================================
--- django/trunk/django/test/utils.py 2006-09-05 00:26:14 UTC (rev 3722)
+++ django/trunk/django/test/utils.py 2006-09-05 13:32:08 UTC (rev 3723)
@@ -95,10 +95,11 @@
# 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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---