From 17cd87a264d8719e82773ace080df25bad88cbef Mon Sep 17 00:00:00 2001 From: Ian Kelly Date: Fri, 14 Sep 2007 22:07:54 +0000 Subject: [PATCH] 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 --- django/db/backends/oracle/base.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index dbb1d032ebf..f9dd4f32ca3 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -354,7 +354,10 @@ class DatabaseOperations(BaseDatabaseOperations): for sequence_info in sequences: table_name = sequence_info['table'] 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) return sql else: @@ -368,13 +371,16 @@ class DatabaseOperations(BaseDatabaseOperations): for f in model._meta.fields: if isinstance(f, models.AutoField): sequence_name = get_sequence_name(model._meta.db_table) - output.append(query % {'sequence':sequence_name, - 'table':model._meta.db_table}) + column_name = self.quote_name(f.db_column or f.name) + 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. for f in model._meta.many_to_many: sequence_name = get_sequence_name(f.m2m_db_table()) - output.append(query % {'sequence':sequence_name, - 'table':f.m2m_db_table()}) + output.append(query % {'sequence': sequence_name, + 'table': f.m2m_db_table(), + 'column': self.quote_name('id')}) return output def start_transaction_sql(self): @@ -507,7 +513,7 @@ def _get_sequence_reset_sql(): cval integer; BEGIN 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; cval := startvalue - cval; IF cval != 0 THEN