Code

Ticket #11101: 11101.diff

File 11101.diff, 1.2 KB (added by ikelly, 3 years ago)
Line 
1Index: django/db/backends/oracle/base.py
2===================================================================
3--- django/db/backends/oracle/base.py   (revision 14509)
4+++ django/db/backends/oracle/base.py   (working copy)
5@@ -647,19 +647,15 @@
6     # TODO: colorize this SQL code with style.SQL_KEYWORD(), etc.
7     return """
8 DECLARE
9-    startvalue integer;
10-    cval integer;
11+    table_value integer;
12+    seq_value integer;
13 BEGIN
14-    LOCK TABLE %(table)s IN SHARE MODE;
15-    SELECT NVL(MAX(%(column)s), 0) INTO startvalue FROM %(table)s;
16-    SELECT "%(sequence)s".nextval INTO cval FROM dual;
17-    cval := startvalue - cval;
18-    IF cval != 0 THEN
19-        EXECUTE IMMEDIATE 'ALTER SEQUENCE "%(sequence)s" MINVALUE 0 INCREMENT BY '||cval;
20-        SELECT "%(sequence)s".nextval INTO cval FROM dual;
21-        EXECUTE IMMEDIATE 'ALTER SEQUENCE "%(sequence)s" INCREMENT BY 1';
22-    END IF;
23-    COMMIT;
24+    SELECT NVL(MAX(%(column)s), 0) INTO table_value FROM %(table)s;
25+    SELECT last_number INTO seq_value FROM user_sequences
26+           WHERE sequence_name = '%(sequence)s';
27+    WHILE table_value > seq_value LOOP
28+        SELECT "%(sequence)s".nextval INTO seq_value FROM dual;
29+    END LOOP;
30 END;
31 /"""
32