Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

boulder-oracle-sprint: Fixed fixtures_regress test case by implementing

get_sql_sequence_reset() in the Oracle backend.  Thanks, Ian Kelly.


git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4995 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f44429224a874dac9028f56d6803d1f1dc1b382f 1 parent 0b57189
Boulder Sprinters authored
Showing with 28 additions and 2 deletions.
  1. +28 −2 django/db/backends/oracle/base.py
View
30 django/db/backends/oracle/base.py
@@ -225,8 +225,34 @@ def get_sequence_name(table):
def get_sql_sequence_reset(style, model_list):
"Returns a list of the SQL statements to reset sequences for the given models."
- # TODO: Run ALTER statements to reset Oracle sequence w/out dropping it.
- return []
+ from django.db import models
+ output = []
+ query = """
+ DECLARE
+ startvalue integer;
+ cval integer;
+ BEGIN
+ SELECT NVL(MAX(id), 0) INTO startvalue FROM %(table)s;
+ SELECT %(sequence)s.nextval INTO cval FROM dual;
+ cval := startvalue - cval;
+ IF cval != 0 THEN
+ EXECUTE IMMEDIATE 'ALTER SEQUENCE %(sequence)s MINVALUE 0 INCREMENT BY '||cval;
+ SELECT %(sequence)s.nextval INTO cval FROM dual;
+ EXECUTE IMMEDIATE 'ALTER SEQUENCE %(sequence)s INCREMENT BY 1';
+ END IF;
+ END; """
+ for model in model_list:
+ for f in model._meta.fields:
+ if isinstance(f, models.AutoField):
+ sequence_name = get_sequence_name(model._meta.db_table)
+ query1 = query % {'sequence':sequence_name, 'table':model._meta.db_table}
+ output.append(query1)
+ 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())
+ query2 = query % {'sequence':sequence_name, 'table':f.m2m_db_table()}
+ output.append(query2)
+ return output
def get_trigger_name(table):
name_length = get_max_name_length() - 3
Please sign in to comment.
Something went wrong with that request. Please try again.