mirror of https://github.com/django/django.git
Test database creation/deletion now correctly quotes database names when creating/dropping them.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3673 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a547ef0d62
commit
56264160a2
|
@ -1,6 +1,6 @@
|
||||||
import sys, time
|
import sys, time
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction, backend
|
||||||
|
|
||||||
# The prefix to put on the default database name when creating
|
# The prefix to put on the default database name when creating
|
||||||
# the test database.
|
# the test database.
|
||||||
|
@ -29,7 +29,7 @@ def create_test_db(verbosity=1, autoclobber=False):
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
_set_autocommit(connection)
|
_set_autocommit(connection)
|
||||||
try:
|
try:
|
||||||
cursor.execute("CREATE DATABASE %s" % TEST_DATABASE_NAME)
|
cursor.execute("CREATE DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
sys.stderr.write("Got an error creating the test database: %s\n" % e)
|
sys.stderr.write("Got an error creating the test database: %s\n" % e)
|
||||||
if not autoclobber:
|
if not autoclobber:
|
||||||
|
@ -38,10 +38,10 @@ def create_test_db(verbosity=1, autoclobber=False):
|
||||||
try:
|
try:
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
print "Destroying old test database..."
|
print "Destroying old test database..."
|
||||||
cursor.execute("DROP DATABASE %s" % TEST_DATABASE_NAME)
|
cursor.execute("DROP DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME))
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
print "Creating test database..."
|
print "Creating test database..."
|
||||||
cursor.execute("CREATE DATABASE %s" % TEST_DATABASE_NAME)
|
cursor.execute("CREATE DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
sys.stderr.write("Got an error recreating the test database: %s\n" % e)
|
sys.stderr.write("Got an error recreating the test database: %s\n" % e)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
@ -73,6 +73,6 @@ def destroy_test_db(old_database_name, verbosity=1):
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
_set_autocommit(connection)
|
_set_autocommit(connection)
|
||||||
time.sleep(1) # To avoid "database is being accessed by other users" errors.
|
time.sleep(1) # To avoid "database is being accessed by other users" errors.
|
||||||
cursor.execute("DROP DATABASE %s" % TEST_DATABASE_NAME)
|
cursor.execute("DROP DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME))
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue