Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Ian Kelly authored September 14, 2007

Showing 1 changed file with 12 additions and 6 deletions. Show diff stats Hide diff stats

  1. 18  django/db/backends/oracle/base.py
18  django/db/backends/oracle/base.py
@@ -354,7 +354,10 @@ def sql_flush(self, style, tables, sequences):
354 354
             for sequence_info in sequences:
355 355
                 table_name = sequence_info['table']
356 356
                 seq_name = get_sequence_name(table_name)
357  
-                query = _get_sequence_reset_sql() % {'sequence': seq_name, 'table': self.quote_name(table_name)}
  357
+                column_name = self.quote_name(sequence_info['column'] or 'id')
  358
+                query = _get_sequence_reset_sql() % {'sequence': seq_name,
  359
+                                                     'table': self.quote_name(table_name),
  360
+                                                     'column': column_name}
358 361
                 sql.append(query)
359 362
             return sql
360 363
         else:
@@ -368,13 +371,16 @@ def sequence_reset_sql(self, style, model_list):
368 371
             for f in model._meta.fields:
369 372
                 if isinstance(f, models.AutoField):
370 373
                     sequence_name = get_sequence_name(model._meta.db_table)
371  
-                    output.append(query % {'sequence':sequence_name,
372  
-                                           'table':model._meta.db_table})
  374
+                    column_name = self.quote_name(f.db_column or f.name)
  375
+                    output.append(query % {'sequence': sequence_name,
  376
+                                           'table': model._meta.db_table,
  377
+                                           'column': column_name})
373 378
                     break # Only one AutoField is allowed per model, so don't bother continuing.
374 379
             for f in model._meta.many_to_many:
375 380
                 sequence_name = get_sequence_name(f.m2m_db_table())
376  
-                output.append(query % {'sequence':sequence_name,
377  
-                                       'table':f.m2m_db_table()})
  381
+                output.append(query % {'sequence': sequence_name,
  382
+                                       'table': f.m2m_db_table(),
  383
+                                       'column': self.quote_name('id')})
378 384
         return output
379 385
 
380 386
     def start_transaction_sql(self):
@@ -507,7 +513,7 @@ def _get_sequence_reset_sql():
507 513
             cval integer;
508 514
         BEGIN
509 515
             LOCK TABLE %(table)s IN SHARE MODE;
510  
-            SELECT NVL(MAX(id), 0) INTO startvalue FROM %(table)s;
  516
+            SELECT NVL(MAX(%(column)s), 0) INTO startvalue FROM %(table)s;
511 517
             SELECT %(sequence)s.nextval INTO cval FROM dual;
512 518
             cval := startvalue - cval;
513 519
             IF cval != 0 THEN

0 notes on commit 17cd87a

Please sign in to comment.
Something went wrong with that request. Please try again.