Changeset 6195
- Timestamp:
- 09/14/07 13:12:36 (1 year ago)
- Files:
-
- django/trunk/django/core/management/sql.py (modified) (2 diffs)
- django/trunk/django/db/backends/__init__.py (modified) (1 diff)
- django/trunk/django/db/backends/oracle/base.py (modified) (1 diff)
- django/trunk/django/db/models/fields/__init__.py (modified) (1 diff)
- django/trunk/django/db/models/options.py (modified) (1 diff)
- django/trunk/tests/regressiontests/model_regress/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/management/sql.py
r6013 r6195 303 303 if opts.has_auto_field: 304 304 # Add any extra SQL needed to support auto-incrementing primary keys. 305 autoinc_sql = connection.ops.autoinc_sql(opts.db_table) 305 auto_column = opts.auto_field.db_column or opts.auto_field.name 306 autoinc_sql = connection.ops.autoinc_sql(opts.db_table, auto_column) 306 307 if autoinc_sql: 307 308 for stmt in autoinc_sql: … … 386 387 387 388 # Add any extra SQL needed to support auto-incrementing PKs 388 autoinc_sql = connection.ops.autoinc_sql(f.m2m_db_table() )389 autoinc_sql = connection.ops.autoinc_sql(f.m2m_db_table(), 'id') 389 390 if autoinc_sql: 390 391 for stmt in autoinc_sql: django/trunk/django/db/backends/__init__.py
r5978 r6195 57 57 row. 58 58 """ 59 def autoinc_sql(self, table ):59 def autoinc_sql(self, table, column): 60 60 """ 61 61 Returns any SQL needed to support auto-incrementing primary keys, or django/trunk/django/db/backends/oracle/base.py
r5992 r6195 32 32 33 33 class DatabaseOperations(BaseDatabaseOperations): 34 def autoinc_sql(self, table ):34 def autoinc_sql(self, table, column): 35 35 # To simulate auto-incrementing primary keys in Oracle, we have to 36 36 # create a sequence and a trigger. 37 37 sq_name = get_sequence_name(table) 38 38 tr_name = get_trigger_name(table) 39 tbl_name = self.quote_name(table) 40 col_name = self.quote_name(column) 39 41 sequence_sql = 'CREATE SEQUENCE %s;' % sq_name 40 42 trigger_sql = """ 41 CREATE OR REPLACE TRIGGER % s42 BEFORE INSERT ON % s43 CREATE OR REPLACE TRIGGER %(tr_name)s 44 BEFORE INSERT ON %(tbl_name)s 43 45 FOR EACH ROW 44 WHEN (new. idIS NULL)46 WHEN (new.%(col_name)s IS NULL) 45 47 BEGIN 46 SELECT %s.nextval INTO :new.id FROM dual; 47 END;/""" % (tr_name, self.quote_name(table), sq_name) 48 SELECT %(sq_name)s.nextval 49 INTO :new.%(col_name)s FROM dual; 50 END;/""" % locals() 48 51 return sequence_sql, trigger_sql 49 52 django/trunk/django/db/models/fields/__init__.py
r6193 r6195 434 434 super(AutoField, self).contribute_to_class(cls, name) 435 435 cls._meta.has_auto_field = True 436 cls._meta.auto_field = self 436 437 437 438 def formfield(self, **kwargs): django/trunk/django/db/models/options.py
r5960 r6195 34 34 self.meta = meta 35 35 self.pk = None 36 self.has_auto_field = False36 self.has_auto_field, self.auto_field = False, None 37 37 self.one_to_one_field = None 38 38 self.parents = [] django/trunk/tests/regressiontests/model_regress/models.py
r5876 r6195 21 21 return self.headline 22 22 23 class Movie(models.Model): 24 #5218: Test models with non-default primary keys / AutoFields 25 movie_id = models.AutoField(primary_key=True) 26 name = models.CharField(max_length=60) 27 23 28 __test__ = {'API_TESTS': """ 24 29 (NOTE: Part of the regression test here is merely parsing the model
