Changeset 5974
- Timestamp:
- 08/19/07 21:20:33 (1 year ago)
- Files:
-
- django/trunk/django/core/management/commands/syncdb.py (modified) (1 diff)
- django/trunk/django/core/management/sql.py (modified) (9 diffs)
- django/trunk/django/db/backends/ado_mssql/base.py (modified) (4 diffs)
- django/trunk/django/db/backends/dummy/base.py (modified) (2 diffs)
- django/trunk/django/db/backends/__init__.py (modified) (1 diff)
- django/trunk/django/db/backends/mysql/base.py (modified) (4 diffs)
- django/trunk/django/db/backends/mysql_old/base.py (modified) (4 diffs)
- django/trunk/django/db/backends/oracle/base.py (modified) (4 diffs)
- django/trunk/django/db/backends/postgresql/base.py (modified) (3 diffs)
- django/trunk/django/db/backends/postgresql_psycopg2/base.py (modified) (3 diffs)
- django/trunk/django/db/backends/sqlite3/base.py (modified) (4 diffs)
- django/trunk/django/db/models/query.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/management/commands/syncdb.py
r5920 r5974 35 35 # so we know what needs to be added. 36 36 table_list = table_list() 37 if backend.uses_case_insensitive_names:37 if connection.features.uses_case_insensitive_names: 38 38 table_name_converter = str.upper 39 39 else: django/trunk/django/core/management/sql.py
r5967 r5974 16 16 def installed_models(table_list): 17 17 "Returns a set of all models that are installed, given a list of existing table names." 18 from django.db import backend, models18 from django.db import connection, models 19 19 all_models = [] 20 20 for app in models.get_apps(): 21 21 for model in models.get_models(app): 22 22 all_models.append(model) 23 if backend.uses_case_insensitive_names:23 if connection.features.uses_case_insensitive_names: 24 24 converter = lambda x: x.upper() 25 25 else: … … 111 111 else: 112 112 table_names = [] 113 if backend.uses_case_insensitive_names:113 if connection.features.uses_case_insensitive_names: 114 114 table_name_converter = str.upper 115 115 else: … … 139 139 output.append('%s %s;' % (style.SQL_KEYWORD('DROP TABLE'), 140 140 style.SQL_TABLE(qn(model._meta.db_table)))) 141 if backend.supports_constraints and model in references_to_delete:141 if connection.features.supports_constraints and model in references_to_delete: 142 142 for rel_class, f in references_to_delete[model]: 143 143 table = rel_class._meta.db_table … … 233 233 style.SQL_COLTYPE(col_type)] 234 234 field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or ''))) 235 if f.unique and (not f.primary_key or backend.allows_unique_and_pk):235 if f.unique and (not f.primary_key or connection.features.allows_unique_and_pk): 236 236 field_output.append(style.SQL_KEYWORD('UNIQUE')) 237 237 if f.primary_key: 238 238 field_output.append(style.SQL_KEYWORD('PRIMARY KEY')) 239 if tablespace and backend.supports_tablespaces and (f.unique or f.primary_key) and backend.autoindexes_primary_keys:239 if tablespace and connection.features.supports_tablespaces and (f.unique or f.primary_key) and connection.features.autoindexes_primary_keys: 240 240 # We must specify the index tablespace inline, because we 241 241 # won't be generating a CREATE INDEX statement for this field. … … 265 265 full_statement.append(' %s%s' % (line, i < len(table_output)-1 and ',' or '')) 266 266 full_statement.append(')') 267 if opts.db_tablespace and backend.supports_tablespaces:267 if opts.db_tablespace and connection.features.supports_tablespaces: 268 268 full_statement.append(connection.ops.tablespace_sql(opts.db_tablespace)) 269 269 full_statement.append(';') … … 288 288 qn = connection.ops.quote_name 289 289 final_output = [] 290 if backend.supports_constraints:290 if connection.features.supports_constraints: 291 291 opts = model._meta 292 292 if model in pending_references: … … 317 317 if not isinstance(f.rel, generic.GenericRel): 318 318 tablespace = f.db_tablespace or opts.db_tablespace 319 if tablespace and backend.supports_tablespaces and backend.autoindexes_primary_keys:319 if tablespace and connection.features.supports_tablespaces and connection.features.autoindexes_primary_keys: 320 320 tablespace_sql = ' ' + connection.ops.tablespace_sql(tablespace, inline=True) 321 321 else: … … 348 348 tablespace_sql)) 349 349 table_output.append(')') 350 if opts.db_tablespace and backend.supports_tablespaces:350 if opts.db_tablespace and connection.features.supports_tablespaces: 351 351 # f.db_tablespace is only for indices, so ignore its value here. 352 352 table_output.append(connection.ops.tablespace_sql(opts.db_tablespace)) … … 396 396 qn = connection.ops.quote_name 397 397 for f in model._meta.fields: 398 if f.db_index and not ((f.primary_key or f.unique) and backend.autoindexes_primary_keys):398 if f.db_index and not ((f.primary_key or f.unique) and connection.features.autoindexes_primary_keys): 399 399 unique = f.unique and 'UNIQUE ' or '' 400 400 tablespace = f.db_tablespace or model._meta.db_tablespace 401 if tablespace and backend.supports_tablespaces:401 if tablespace and connection.features.supports_tablespaces: 402 402 tablespace_sql = ' ' + connection.ops.tablespace_sql(tablespace) 403 403 else: django/trunk/django/db/backends/ado_mssql/base.py
r5970 r5974 5 5 """ 6 6 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabase Operations, util7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 8 8 try: 9 9 import adodbapi as Database … … 49 49 Database.convertVariantToPython = variantToPython 50 50 51 class DatabaseFeatures(BaseDatabaseFeatures): 52 supports_tablespaces = True 53 51 54 class DatabaseOperations(BaseDatabaseOperations): 52 55 def date_extract_sql(self, lookup_type, field_name): … … 80 83 81 84 class DatabaseWrapper(BaseDatabaseWrapper): 85 features = DatabaseFeatures() 82 86 ops = DatabaseOperations() 83 87 … … 93 97 self.connection = Database.connect(conn_string) 94 98 return self.connection.cursor() 95 96 allows_group_by_ordinal = True97 allows_unique_and_pk = True98 autoindexes_primary_keys = True99 needs_datetime_string_cast = True100 needs_upper_for_iops = False101 supports_constraints = True102 supports_tablespaces = True103 uses_case_insensitive_names = False104 99 105 100 OPERATOR_MAPPING = { django/trunk/django/db/backends/dummy/base.py
r5970 r5974 22 22 pass 23 23 24 class DatabaseOperations(object):24 class ComplainOnGetattr(object): 25 25 def __getattr__(self, *args, **kwargs): 26 26 complain() 27 27 28 28 class DatabaseWrapper(object): 29 ops = DatabaseOperations() 29 ops = ComplainOnGetattr() 30 features = ComplainOnGetattr() 30 31 cursor = complain 31 32 _commit = complain … … 38 39 pass # close() 39 40 40 supports_constraints = False41 supports_tablespaces = False42 43 41 OPERATOR_MAPPING = {} django/trunk/django/db/backends/__init__.py
r5971 r5974 39 39 from django.db.backends import util 40 40 return util.CursorDebugWrapper(cursor, self) 41 42 class BaseDatabaseFeatures(object): 43 allows_group_by_ordinal = True 44 allows_unique_and_pk = True 45 autoindexes_primary_keys = True 46 needs_datetime_string_cast = True 47 needs_upper_for_iops = False 48 supports_constraints = True 49 supports_tablespaces = False 50 uses_case_insensitive_names = False 41 51 42 52 class BaseDatabaseOperations(object): django/trunk/django/db/backends/mysql/base.py
r5970 r5974 5 5 """ 6 6 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabase Operations, util7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 8 8 try: 9 9 import MySQLdb as Database … … 53 53 # standard util.CursorDebugWrapper can be used. Also, using sql_mode 54 54 # TRADITIONAL will automatically cause most warnings to be treated as errors. 55 56 class DatabaseFeatures(BaseDatabaseFeatures): 57 autoindexes_primary_keys = False 55 58 56 59 class DatabaseOperations(BaseDatabaseOperations): … … 117 120 118 121 class DatabaseWrapper(BaseDatabaseWrapper): 122 features = DatabaseFeatures() 119 123 ops = DatabaseOperations() 120 124 … … 176 180 return self.server_version 177 181 178 allows_group_by_ordinal = True179 allows_unique_and_pk = True180 autoindexes_primary_keys = False181 needs_datetime_string_cast = True # MySQLdb requires a typecast for dates182 needs_upper_for_iops = False183 supports_constraints = True184 supports_tablespaces = False185 uses_case_insensitive_names = False186 187 182 OPERATOR_MAPPING = { 188 183 'exact': '= %s', django/trunk/django/db/backends/mysql_old/base.py
r5970 r5974 5 5 """ 6 6 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabase Operations, util7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 8 8 from django.utils.encoding import force_unicode 9 9 try: … … 64 64 return getattr(self.cursor, attr) 65 65 66 class DatabaseFeatures(BaseDatabaseFeatures): 67 autoindexes_primary_keys = False 68 66 69 class DatabaseOperations(BaseDatabaseOperations): 67 70 def date_extract_sql(self, lookup_type, field_name): … … 127 130 128 131 class DatabaseWrapper(BaseDatabaseWrapper): 132 features = DatabaseFeatures() 129 133 ops = DatabaseOperations() 130 134 … … 195 199 return self.server_version 196 200 197 allows_group_by_ordinal = True198 allows_unique_and_pk = True199 autoindexes_primary_keys = False200 needs_datetime_string_cast = True # MySQLdb requires a typecast for dates201 needs_upper_for_iops = False202 supports_constraints = True203 supports_tablespaces = False204 uses_case_insensitive_names = False205 206 201 OPERATOR_MAPPING = { 207 202 'exact': '= %s', django/trunk/django/db/backends/oracle/base.py
r5970 r5974 5 5 """ 6 6 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabase Operations, util7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 8 8 from django.utils.datastructures import SortedDict 9 9 from django.utils.encoding import smart_str, force_unicode … … 21 21 DatabaseError = Database.Error 22 22 IntegrityError = Database.IntegrityError 23 24 class DatabaseFeatures(BaseDatabaseFeatures): 25 allows_group_by_ordinal = False 26 allows_unique_and_pk = False # Suppress UNIQUE/PK for Oracle (ORA-02259) 27 needs_datetime_string_cast = False 28 needs_upper_for_iops = True 29 supports_tablespaces = True 30 uses_case_insensitive_names = True 23 31 24 32 class DatabaseOperations(BaseDatabaseOperations): … … 129 137 130 138 class DatabaseWrapper(BaseDatabaseWrapper): 139 features = DatabaseFeatures() 131 140 ops = DatabaseOperations() 132 141 … … 151 160 cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") 152 161 return cursor 153 154 allows_group_by_ordinal = False155 allows_unique_and_pk = False # Suppress UNIQUE/PK for Oracle (ORA-02259)156 autoindexes_primary_keys = True157 needs_datetime_string_cast = False158 needs_upper_for_iops = True159 supports_constraints = True160 supports_tablespaces = True161 uses_case_insensitive_names = True162 162 163 163 class FormatStylePlaceholderCursor(Database.Cursor): django/trunk/django/db/backends/postgresql/base.py
r5972 r5974 6 6 7 7 from django.utils.encoding import smart_str, smart_unicode 8 from django.db.backends import BaseDatabaseWrapper, util8 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, util 9 9 from django.db.backends.postgresql.operations import DatabaseOperations 10 10 try: … … 57 57 return getattr(self.cursor, attr) 58 58 59 class DatabaseFeatures(BaseDatabaseFeatures): 60 pass # This backend uses all the defaults. 61 59 62 class DatabaseWrapper(BaseDatabaseWrapper): 63 features = DatabaseFeatures() 60 64 ops = DatabaseOperations() 61 65 … … 87 91 self.ops.postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] 88 92 return cursor 89 90 allows_group_by_ordinal = True91 allows_unique_and_pk = True92 autoindexes_primary_keys = True93 needs_datetime_string_cast = True94 needs_upper_for_iops = False95 supports_constraints = True96 supports_tablespaces = False97 uses_case_insensitive_names = False98 93 99 94 def typecast_string(s): django/trunk/django/db/backends/postgresql_psycopg2/base.py
r5973 r5974 5 5 """ 6 6 7 from django.db.backends import BaseDatabaseWrapper 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures 8 8 from django.db.backends.postgresql.operations import DatabaseOperations 9 9 try: … … 19 19 psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) 20 20 21 class DatabaseFeatures(BaseDatabaseFeatures): 22 needs_datetime_string_cast = False 23 21 24 class DatabaseWrapper(BaseDatabaseWrapper): 25 features = DatabaseFeatures() 22 26 ops = DatabaseOperations() 23 27 … … 50 54 return cursor 51 55 52 allows_group_by_ordinal = True53 allows_unique_and_pk = True54 autoindexes_primary_keys = True55 needs_datetime_string_cast = False56 needs_upper_for_iops = False57 supports_constraints = True58 supports_tablespaces = False59 uses_case_insensitive_names = False60 61 56 OPERATOR_MAPPING = { 62 57 'exact': '= %s', django/trunk/django/db/backends/sqlite3/base.py
r5970 r5974 3 3 """ 4 4 5 from django.db.backends import BaseDatabaseWrapper, BaseDatabase Operations, util5 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 6 6 try: 7 7 try: … … 34 34 Database.register_converter("decimal", util.typecast_decimal) 35 35 Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal) 36 37 class DatabaseFeatures(BaseDatabaseFeatures): 38 supports_constraints = False 36 39 37 40 class DatabaseOperations(BaseDatabaseOperations): … … 71 74 72 75 class DatabaseWrapper(BaseDatabaseWrapper): 76 features = DatabaseFeatures() 73 77 ops = DatabaseOperations() 74 78 … … 111 115 def convert_query(self, query, num_params): 112 116 return query % tuple("?" * num_params) 113 114 allows_group_by_ordinal = True115 allows_unique_and_pk = True116 autoindexes_primary_keys = True117 needs_datetime_string_cast = True118 needs_upper_for_iops = False119 supports_constraints = False120 supports_tablespaces = False121 uses_case_insensitive_names = False122 117 123 118 def _sqlite_extract(lookup_type, dt): django/trunk/django/db/models/query.py
r5967 r5974 652 652 field_name = qn(self._field.column) 653 653 654 if backend.allows_group_by_ordinal:654 if connection.features.allows_group_by_ordinal: 655 655 group_by = '1' 656 656 else: … … 664 664 665 665 has_resolve_columns = hasattr(self, 'resolve_columns') 666 needs_datetime_string_cast = backend.needs_datetime_string_cast666 needs_datetime_string_cast = connection.features.needs_datetime_string_cast 667 667 dates = [] 668 668 # It would be better to use self._field here instead of DateTimeField(), … … 797 797 field_cast_sql = '%s%s' 798 798 field_sql = field_cast_sql % (table_prefix, field_name) 799 if lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith') and backend.needs_upper_for_iops:799 if lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith') and connection.features.needs_upper_for_iops: 800 800 format = 'UPPER(%s) %s' 801 801 else:
