Ticket #11101: 11101.diff

File 11101.diff, 1.2 KB (added by ikelly, 5 years ago)
  • django/db/backends/oracle/base.py

     
    647647    # TODO: colorize this SQL code with style.SQL_KEYWORD(), etc.
    648648    return """
    649649DECLARE
    650     startvalue integer;
    651     cval integer;
     650    table_value integer;
     651    seq_value integer;
    652652BEGIN
    653     LOCK TABLE %(table)s IN SHARE MODE;
    654     SELECT NVL(MAX(%(column)s), 0) INTO startvalue FROM %(table)s;
    655     SELECT "%(sequence)s".nextval INTO cval FROM dual;
    656     cval := startvalue - cval;
    657     IF cval != 0 THEN
    658         EXECUTE IMMEDIATE 'ALTER SEQUENCE "%(sequence)s" MINVALUE 0 INCREMENT BY '||cval;
    659         SELECT "%(sequence)s".nextval INTO cval FROM dual;
    660         EXECUTE IMMEDIATE 'ALTER SEQUENCE "%(sequence)s" INCREMENT BY 1';
    661     END IF;
    662     COMMIT;
     653    SELECT NVL(MAX(%(column)s), 0) INTO table_value FROM %(table)s;
     654    SELECT last_number INTO seq_value FROM user_sequences
     655           WHERE sequence_name = '%(sequence)s';
     656    WHILE table_value > seq_value LOOP
     657        SELECT "%(sequence)s".nextval INTO seq_value FROM dual;
     658    END LOOP;
    663659END;
    664660/"""
    665661
Back to Top