Fixed #27789 -- Simplified query for sequence value on Oracle.

This commit is contained in:
Mariusz Felisiak 2017-01-30 14:03:42 +01:00 committed by Tim Graham
parent 068cd60366
commit 89501d9298
1 changed files with 3 additions and 4 deletions

View File

@ -34,7 +34,7 @@ BEGIN
SELECT NVL(last_number - cache_size, 0) INTO seq_value FROM user_sequences SELECT NVL(last_number - cache_size, 0) INTO seq_value FROM user_sequences
WHERE sequence_name = '%(sequence)s'; WHERE sequence_name = '%(sequence)s';
WHILE table_value > seq_value LOOP WHILE table_value > seq_value LOOP
SELECT "%(sequence)s".nextval INTO seq_value FROM dual; seq_value := "%(sequence)s".nextval;
END LOOP; END LOOP;
END; END;
/""" /"""
@ -69,8 +69,7 @@ BEFORE INSERT ON %(tbl_name)s
FOR EACH ROW FOR EACH ROW
WHEN (new.%(col_name)s IS NULL) WHEN (new.%(col_name)s IS NULL)
BEGIN BEGIN
SELECT "%(sq_name)s".nextval :new.%(col_name)s := "%(sq_name)s".nextval;
INTO :new.%(col_name)s FROM dual;
END; END;
/""" % args /""" % args
return sequence_sql, trigger_sql return sequence_sql, trigger_sql
@ -258,7 +257,7 @@ WHEN (new.%(col_name)s IS NULL)
def last_insert_id(self, cursor, table_name, pk_name): def last_insert_id(self, cursor, table_name, pk_name):
sq_name = self._get_sequence_name(table_name) sq_name = self._get_sequence_name(table_name)
cursor.execute('SELECT "%s".currval FROM dual' % sq_name) cursor.execute('"%s".currval' % sq_name)
return cursor.fetchone()[0] return cursor.fetchone()[0]
def lookup_cast(self, lookup_type, internal_type=None): def lookup_cast(self, lookup_type, internal_type=None):