summaryrefslogtreecommitdiff
path: root/django/db/backends
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2010-08-09 21:22:37 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2010-08-09 21:22:37 +0000
commit6001ba016a3db4701d56abc6d30868d4e5d88dbf (patch)
tree7a42c57d802484300c2384d3cd3a968de1804383 /django/db/backends
parentc7bd48cb9f645e5ff07d1e68b86130e3bb2b043f (diff)
downloaddjango-soc2010/query-refactor.tar.gz
[soc2010/query-refactor] Merged up to trunk r13556, resolved merge conflictsarchive/soc2010/query-refactorsoc2010/query-refactor
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13565 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends')
-rw-r--r--django/db/backends/creation.py17
-rw-r--r--django/db/backends/oracle/creation.py6
-rw-r--r--django/db/backends/postgresql/creation.py2
-rw-r--r--django/db/backends/postgresql/operations.py9
-rw-r--r--django/db/backends/sqlite3/creation.py6
5 files changed, 18 insertions, 22 deletions
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index 999d1cb5fe..c10ad9da31 100644
--- a/django/db/backends/creation.py
+++ b/django/db/backends/creation.py
@@ -359,12 +359,17 @@ class BaseDatabaseCreation(object):
can_rollback = self._rollback_works()
self.connection.settings_dict["SUPPORTS_TRANSACTIONS"] = can_rollback
- call_command('syncdb', verbosity=verbosity, interactive=False, database=self.connection.alias)
+ # Report syncdb messages at one level lower than that requested.
+ # This ensures we don't get flooded with messages during testing
+ # (unless you really ask to be flooded)
+ call_command('syncdb', verbosity=max(verbosity - 1, 0), interactive=False, database=self.connection.alias)
if settings.CACHE_BACKEND.startswith('db://'):
- from django.core.cache import parse_backend_uri
- _, cache_name, _ = parse_backend_uri(settings.CACHE_BACKEND)
- call_command('createcachetable', cache_name)
+ from django.core.cache import parse_backend_uri, cache
+ from django.db import router
+ if router.allow_syncdb(self.connection.alias, cache.cache_model_class):
+ _, cache_name, _ = parse_backend_uri(settings.CACHE_BACKEND)
+ call_command('createcachetable', cache_name, database=self.connection.alias)
# Get a cursor (even though we don't need one yet). This has
# the side effect of initializing the test database.
@@ -397,10 +402,8 @@ class BaseDatabaseCreation(object):
if autoclobber or confirm == 'yes':
try:
if verbosity >= 1:
- print "Destroying old test database..."
+ print "Destroying old test database '%s'..." % self.connection.alias
cursor.execute("DROP DATABASE %s" % qn(test_database_name))
- if verbosity >= 1:
- print "Creating test database..."
cursor.execute("CREATE DATABASE %s %s" % (qn(test_database_name), suffix))
except Exception, e:
sys.stderr.write("Got an error recreating the test database: %s\n" % e)
diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py
index e6e242b9f7..8167640aac 100644
--- a/django/db/backends/oracle/creation.py
+++ b/django/db/backends/oracle/creation.py
@@ -61,8 +61,6 @@ class DatabaseCreation(BaseDatabaseCreation):
cursor = self.connection.cursor()
if self._test_database_create():
- if verbosity >= 1:
- print 'Creating test database...'
try:
self._execute_test_db_creation(cursor, parameters, verbosity)
except Exception, e:
@@ -72,10 +70,8 @@ class DatabaseCreation(BaseDatabaseCreation):
if autoclobber or confirm == 'yes':
try:
if verbosity >= 1:
- print "Destroying old test database..."
+ print "Destroying old test database '%s'..." % self.connection.alias
self._execute_test_db_destruction(cursor, parameters, verbosity)
- if verbosity >= 1:
- print "Creating test database..."
self._execute_test_db_creation(cursor, parameters, verbosity)
except Exception, e:
sys.stderr.write("Got an error recreating the test database: %s\n" % e)
diff --git a/django/db/backends/postgresql/creation.py b/django/db/backends/postgresql/creation.py
index e3587f0e37..9984716389 100644
--- a/django/db/backends/postgresql/creation.py
+++ b/django/db/backends/postgresql/creation.py
@@ -64,7 +64,7 @@ class DatabaseCreation(BaseDatabaseCreation):
# a second index that specifies their operator class, which is
# needed when performing correct LIKE queries outside the
# C locale. See #12234.
- db_type = f.db_type()
+ db_type = f.db_type(connection=self.connection)
if db_type.startswith('varchar'):
output.append(get_index_sql('%s_%s_like' % (db_table, f.column),
' varchar_pattern_ops'))
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index e5dd0fdd11..d55aae93bc 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -55,7 +55,8 @@ class DatabaseOperations(BaseDatabaseOperations):
def last_insert_id(self, cursor, table_name, pk_name):
# Use pg_get_serial_sequence to get the underlying sequence name
# from the table name and column name (available since PostgreSQL 8)
- cursor.execute("SELECT CURRVAL(pg_get_serial_sequence('%s','%s'))" % (table_name, pk_name))
+ cursor.execute("SELECT CURRVAL(pg_get_serial_sequence('%s','%s'))" % (
+ self.quote_name(table_name), pk_name))
return cursor.fetchone()[0]
def no_limit_value(self):
@@ -97,7 +98,7 @@ class DatabaseOperations(BaseDatabaseOperations):
column_name = 'id'
sql.append("%s setval(pg_get_serial_sequence('%s','%s'), 1, false);" % \
(style.SQL_KEYWORD('SELECT'),
- style.SQL_TABLE(table_name),
+ style.SQL_TABLE(self.quote_name(table_name)),
style.SQL_FIELD(column_name))
)
return sql
@@ -119,7 +120,7 @@ class DatabaseOperations(BaseDatabaseOperations):
if isinstance(f, models.BaseAutoField):
output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
(style.SQL_KEYWORD('SELECT'),
- style.SQL_TABLE(model._meta.db_table),
+ style.SQL_TABLE(qn(model._meta.db_table)),
style.SQL_FIELD(f.column),
style.SQL_FIELD(qn(f.column)),
style.SQL_FIELD(qn(f.column)),
@@ -131,7 +132,7 @@ class DatabaseOperations(BaseDatabaseOperations):
if not f.rel.through:
output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
(style.SQL_KEYWORD('SELECT'),
- style.SQL_TABLE(model._meta.db_table),
+ style.SQL_TABLE(qn(f.m2m_db_table())),
style.SQL_FIELD('id'),
style.SQL_FIELD(qn('id')),
style.SQL_FIELD(qn('id')),
diff --git a/django/db/backends/sqlite3/creation.py b/django/db/backends/sqlite3/creation.py
index 03897078a2..a65db1160b 100644
--- a/django/db/backends/sqlite3/creation.py
+++ b/django/db/backends/sqlite3/creation.py
@@ -43,14 +43,12 @@ class DatabaseCreation(BaseDatabaseCreation):
if test_database_name and test_database_name != ":memory:":
# Erase the old test database
if verbosity >= 1:
- print "Destroying old test database..."
+ print "Destroying old test database '%s'..." % self.connection.alias
if os.access(test_database_name, os.F_OK):
if not autoclobber:
confirm = raw_input("Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: " % test_database_name)
if autoclobber or confirm == 'yes':
try:
- if verbosity >= 1:
- print "Destroying old test database..."
os.remove(test_database_name)
except Exception, e:
sys.stderr.write("Got an error deleting the old test database: %s\n" % e)
@@ -58,8 +56,6 @@ class DatabaseCreation(BaseDatabaseCreation):
else:
print "Tests cancelled."
sys.exit(1)
- if verbosity >= 1:
- print "Creating test database..."
else:
test_database_name = ":memory:"
return test_database_name