Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 17cd87a264d8719e82773ace080df25bad88cbef 1 parent dfdbf9e
@ikelly ikelly authored
Showing with 12 additions and 6 deletions.
  1. +12 −6 django/db/backends/oracle/base.py
View
18 django/db/backends/oracle/base.py
@@ -354,7 +354,10 @@ def sql_flush(self, style, tables, sequences):
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 @@ def sequence_reset_sql(self, style, model_list):
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
Please sign in to comment.
Something went wrong with that request. Please try again.