Django

Code

Changeset 6195

Show
Ignore:
Timestamp:
09/14/07 13:12:36 (1 year ago)
Author:
ikelly
Message:

Fixed #5218: Made Oracle create autoinc triggers using the correct name
of the AutoField? column rather than always assume "ID".

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management/sql.py

    r6013 r6195  
    303303    if opts.has_auto_field: 
    304304        # 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) 
    306307        if autoinc_sql: 
    307308            for stmt in autoinc_sql: 
     
    386387 
    387388            # 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'
    389390            if autoinc_sql: 
    390391                for stmt in autoinc_sql: 
  • django/trunk/django/db/backends/__init__.py

    r5978 r6195  
    5757    row. 
    5858    """ 
    59     def autoinc_sql(self, table): 
     59    def autoinc_sql(self, table, column): 
    6060        """ 
    6161        Returns any SQL needed to support auto-incrementing primary keys, or 
  • django/trunk/django/db/backends/oracle/base.py

    r5992 r6195  
    3232 
    3333class DatabaseOperations(BaseDatabaseOperations): 
    34     def autoinc_sql(self, table): 
     34    def autoinc_sql(self, table, column): 
    3535        # To simulate auto-incrementing primary keys in Oracle, we have to 
    3636        # create a sequence and a trigger. 
    3737        sq_name = get_sequence_name(table) 
    3838        tr_name = get_trigger_name(table) 
     39        tbl_name = self.quote_name(table) 
     40        col_name = self.quote_name(column) 
    3941        sequence_sql = 'CREATE SEQUENCE %s;' % sq_name 
    4042        trigger_sql = """ 
    41             CREATE OR REPLACE TRIGGER %
    42             BEFORE INSERT ON %
     43            CREATE OR REPLACE TRIGGER %(tr_name)
     44            BEFORE INSERT ON %(tbl_name)
    4345            FOR EACH ROW 
    44             WHEN (new.id IS NULL) 
     46            WHEN (new.%(col_name)s IS NULL) 
    4547                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() 
    4851        return sequence_sql, trigger_sql 
    4952 
  • django/trunk/django/db/models/fields/__init__.py

    r6193 r6195  
    434434        super(AutoField, self).contribute_to_class(cls, name) 
    435435        cls._meta.has_auto_field = True 
     436        cls._meta.auto_field = self 
    436437 
    437438    def formfield(self, **kwargs): 
  • django/trunk/django/db/models/options.py

    r5960 r6195  
    3434        self.meta = meta 
    3535        self.pk = None 
    36         self.has_auto_field = Fals
     36        self.has_auto_field, self.auto_field = False, Non
    3737        self.one_to_one_field = None 
    3838        self.parents = [] 
  • django/trunk/tests/regressiontests/model_regress/models.py

    r5876 r6195  
    2121        return self.headline 
    2222 
     23class 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 
    2328__test__ = {'API_TESTS': """ 
    2429(NOTE: Part of the regression test here is merely parsing the model