Fixed an Oracle sqlflush / sequence reset column name bug exposed by the new test case in [6195].

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6230 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Ian Kelly 2007-09-14 22:07:54 +00:00
parent dfdbf9ec1e
commit 17cd87a264
1 changed files with 12 additions and 6 deletions

View File

@ -354,7 +354,10 @@ class DatabaseOperations(BaseDatabaseOperations):
for sequence_info in sequences: for sequence_info in sequences:
table_name = sequence_info['table'] table_name = sequence_info['table']
seq_name = get_sequence_name(table_name) seq_name = get_sequence_name(table_name)
query = _get_sequence_reset_sql() % {'sequence': seq_name, 'table': self.quote_name(table_name)} column_name = self.quote_name(sequence_info['column'] or 'id')
query = _get_sequence_reset_sql() % {'sequence': seq_name,
'table': self.quote_name(table_name),
'column': column_name}
sql.append(query) sql.append(query)
return sql return sql
else: else:
@ -368,13 +371,16 @@ class DatabaseOperations(BaseDatabaseOperations):
for f in model._meta.fields: for f in model._meta.fields:
if isinstance(f, models.AutoField): if isinstance(f, models.AutoField):
sequence_name = get_sequence_name(model._meta.db_table) sequence_name = get_sequence_name(model._meta.db_table)
output.append(query % {'sequence':sequence_name, column_name = self.quote_name(f.db_column or f.name)
'table':model._meta.db_table}) output.append(query % {'sequence': sequence_name,
'table': model._meta.db_table,
'column': column_name})
break # Only one AutoField is allowed per model, so don't bother continuing. break # Only one AutoField is allowed per model, so don't bother continuing.
for f in model._meta.many_to_many: for f in model._meta.many_to_many:
sequence_name = get_sequence_name(f.m2m_db_table()) sequence_name = get_sequence_name(f.m2m_db_table())
output.append(query % {'sequence':sequence_name, output.append(query % {'sequence': sequence_name,
'table':f.m2m_db_table()}) 'table': f.m2m_db_table(),
'column': self.quote_name('id')})
return output return output
def start_transaction_sql(self): def start_transaction_sql(self):
@ -507,7 +513,7 @@ def _get_sequence_reset_sql():
cval integer; cval integer;
BEGIN BEGIN
LOCK TABLE %(table)s IN SHARE MODE; LOCK TABLE %(table)s IN SHARE MODE;
SELECT NVL(MAX(id), 0) INTO startvalue FROM %(table)s; SELECT NVL(MAX(%(column)s), 0) INTO startvalue FROM %(table)s;
SELECT %(sequence)s.nextval INTO cval FROM dual; SELECT %(sequence)s.nextval INTO cval FROM dual;
cval := startvalue - cval; cval := startvalue - cval;
IF cval != 0 THEN IF cval != 0 THEN