mirror of https://github.com/django/django.git
Refactored get_tablespace_sql() to DatabaseOperations.tablespace_sql(). Refs #5106
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5966 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
13061bf20b
commit
d4f218bd91
|
@ -237,7 +237,7 @@ def sql_model_create(model, style, known_models=set()):
|
||||||
if tablespace and backend.supports_tablespaces and (f.unique or f.primary_key) and backend.autoindexes_primary_keys:
|
if tablespace and backend.supports_tablespaces and (f.unique or f.primary_key) and backend.autoindexes_primary_keys:
|
||||||
# We must specify the index tablespace inline, because we
|
# We must specify the index tablespace inline, because we
|
||||||
# won't be generating a CREATE INDEX statement for this field.
|
# won't be generating a CREATE INDEX statement for this field.
|
||||||
field_output.append(backend.get_tablespace_sql(tablespace, inline=True))
|
field_output.append(connection.ops.tablespace_sql(tablespace, inline=True))
|
||||||
if f.rel:
|
if f.rel:
|
||||||
if f.rel.to in known_models:
|
if f.rel.to in known_models:
|
||||||
field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \
|
field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \
|
||||||
|
@ -263,7 +263,7 @@ def sql_model_create(model, style, known_models=set()):
|
||||||
full_statement.append(' %s%s' % (line, i < len(table_output)-1 and ',' or ''))
|
full_statement.append(' %s%s' % (line, i < len(table_output)-1 and ',' or ''))
|
||||||
full_statement.append(')')
|
full_statement.append(')')
|
||||||
if opts.db_tablespace and backend.supports_tablespaces:
|
if opts.db_tablespace and backend.supports_tablespaces:
|
||||||
full_statement.append(backend.get_tablespace_sql(opts.db_tablespace))
|
full_statement.append(connection.ops.tablespace_sql(opts.db_tablespace))
|
||||||
full_statement.append(';')
|
full_statement.append(';')
|
||||||
final_output.append('\n'.join(full_statement))
|
final_output.append('\n'.join(full_statement))
|
||||||
|
|
||||||
|
@ -313,7 +313,7 @@ def many_to_many_sql_for_model(model, style):
|
||||||
if not isinstance(f.rel, generic.GenericRel):
|
if not isinstance(f.rel, generic.GenericRel):
|
||||||
tablespace = f.db_tablespace or opts.db_tablespace
|
tablespace = f.db_tablespace or opts.db_tablespace
|
||||||
if tablespace and backend.supports_tablespaces and backend.autoindexes_primary_keys:
|
if tablespace and backend.supports_tablespaces and backend.autoindexes_primary_keys:
|
||||||
tablespace_sql = ' ' + backend.get_tablespace_sql(tablespace, inline=True)
|
tablespace_sql = ' ' + connection.ops.tablespace_sql(tablespace, inline=True)
|
||||||
else:
|
else:
|
||||||
tablespace_sql = ''
|
tablespace_sql = ''
|
||||||
table_output = [style.SQL_KEYWORD('CREATE TABLE') + ' ' + \
|
table_output = [style.SQL_KEYWORD('CREATE TABLE') + ' ' + \
|
||||||
|
@ -345,7 +345,7 @@ def many_to_many_sql_for_model(model, style):
|
||||||
table_output.append(')')
|
table_output.append(')')
|
||||||
if opts.db_tablespace and backend.supports_tablespaces:
|
if opts.db_tablespace and backend.supports_tablespaces:
|
||||||
# f.db_tablespace is only for indices, so ignore its value here.
|
# f.db_tablespace is only for indices, so ignore its value here.
|
||||||
table_output.append(backend.get_tablespace_sql(opts.db_tablespace))
|
table_output.append(connection.ops.tablespace_sql(opts.db_tablespace))
|
||||||
table_output.append(';')
|
table_output.append(';')
|
||||||
final_output.append('\n'.join(table_output))
|
final_output.append('\n'.join(table_output))
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ def custom_sql_for_model(model):
|
||||||
|
|
||||||
def sql_indexes_for_model(model, style):
|
def sql_indexes_for_model(model, style):
|
||||||
"Returns the CREATE INDEX SQL statements for a single model"
|
"Returns the CREATE INDEX SQL statements for a single model"
|
||||||
from django.db import backend
|
from django.db import backend, connection
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
for f in model._meta.fields:
|
for f in model._meta.fields:
|
||||||
|
@ -394,7 +394,7 @@ def sql_indexes_for_model(model, style):
|
||||||
unique = f.unique and 'UNIQUE ' or ''
|
unique = f.unique and 'UNIQUE ' or ''
|
||||||
tablespace = f.db_tablespace or model._meta.db_tablespace
|
tablespace = f.db_tablespace or model._meta.db_tablespace
|
||||||
if tablespace and backend.supports_tablespaces:
|
if tablespace and backend.supports_tablespaces:
|
||||||
tablespace_sql = ' ' + backend.get_tablespace_sql(tablespace)
|
tablespace_sql = ' ' + connection.ops.tablespace_sql(tablespace)
|
||||||
else:
|
else:
|
||||||
tablespace_sql = ''
|
tablespace_sql = ''
|
||||||
output.append(
|
output.append(
|
||||||
|
|
|
@ -166,3 +166,10 @@ class BaseDatabaseOperations(object):
|
||||||
Returns the SQL statement required to start a transaction.
|
Returns the SQL statement required to start a transaction.
|
||||||
"""
|
"""
|
||||||
return "BEGIN;"
|
return "BEGIN;"
|
||||||
|
|
||||||
|
def tablespace_sql(self, tablespace, inline=False):
|
||||||
|
"""
|
||||||
|
Returns the tablespace SQL, or None if the backend doesn't use
|
||||||
|
tablespaces.
|
||||||
|
"""
|
||||||
|
return None
|
||||||
|
|
|
@ -70,6 +70,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
def random_function_sql(self):
|
def random_function_sql(self):
|
||||||
return 'RAND()'
|
return 'RAND()'
|
||||||
|
|
||||||
|
def tablespace_sql(self, tablespace, inline=False):
|
||||||
|
return "ON %s" % quote_name(tablespace)
|
||||||
|
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
|
||||||
|
@ -103,9 +106,6 @@ dictfetchone = util.dictfetchone
|
||||||
dictfetchmany = util.dictfetchmany
|
dictfetchmany = util.dictfetchmany
|
||||||
dictfetchall = util.dictfetchall
|
dictfetchall = util.dictfetchall
|
||||||
|
|
||||||
def get_tablespace_sql(tablespace, inline=False):
|
|
||||||
return "ON %s" % quote_name(tablespace)
|
|
||||||
|
|
||||||
OPERATOR_MAPPING = {
|
OPERATOR_MAPPING = {
|
||||||
'exact': '= %s',
|
'exact': '= %s',
|
||||||
'iexact': 'LIKE %s',
|
'iexact': 'LIKE %s',
|
||||||
|
|
|
@ -115,6 +115,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
def start_transaction_sql(self):
|
def start_transaction_sql(self):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def tablespace_sql(self, tablespace, inline=False):
|
||||||
|
return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""), quote_name(tablespace))
|
||||||
|
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
|
||||||
|
@ -231,9 +234,6 @@ def get_field_cast_sql(db_type):
|
||||||
else:
|
else:
|
||||||
return "%s%s"
|
return "%s%s"
|
||||||
|
|
||||||
def get_tablespace_sql(tablespace, inline=False):
|
|
||||||
return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""), quote_name(tablespace))
|
|
||||||
|
|
||||||
def get_drop_sequence(table):
|
def get_drop_sequence(table):
|
||||||
return "DROP SEQUENCE %s;" % quote_name(get_sequence_name(table))
|
return "DROP SEQUENCE %s;" % quote_name(get_sequence_name(table))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue