From 85f924a9b92f5922376c1d3f1a4f1af1d957ef0e Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 4 Feb 2019 16:31:23 +0100 Subject: [PATCH] Refs #28859 -- Simplified fetch_returned_insert_id() by using int data type for binding variable on Oracle. --- django/db/backends/oracle/operations.py | 11 +++++------ django/db/backends/oracle/utils.py | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py index 11a271385f6..4d40614958a 100644 --- a/django/db/backends/oracle/operations.py +++ b/django/db/backends/oracle/operations.py @@ -227,17 +227,16 @@ END; return " DEFERRABLE INITIALLY DEFERRED" def fetch_returned_insert_id(self, cursor): - try: - value = cursor._insert_id_var.getvalue() - # cx_Oracle < 7 returns value, >= 7 returns list with single value. - return int(value[0] if isinstance(value, list) else value) - except (IndexError, TypeError): - # cx_Oracle < 6.3 returns None, >= 6.3 raises IndexError. + value = cursor._insert_id_var.getvalue() + if value is None or value == []: + # cx_Oracle < 6.3 returns None, >= 6.3 returns empty list. raise DatabaseError( 'The database did not return a new row id. Probably "ORA-1403: ' 'no data found" was raised internally but was hidden by the ' 'Oracle OCI library (see https://code.djangoproject.com/ticket/28859).' ) + # cx_Oracle < 7 returns value, >= 7 returns list with single value. + return value[0] if isinstance(value, list) else value def field_cast_sql(self, db_type, internal_type): if db_type and db_type.endswith('LOB'): diff --git a/django/db/backends/oracle/utils.py b/django/db/backends/oracle/utils.py index 3b26112071c..02e3f754a8b 100644 --- a/django/db/backends/oracle/utils.py +++ b/django/db/backends/oracle/utils.py @@ -9,9 +9,8 @@ class InsertIdVar: as a parameter, in order to receive the id of the row created by an insert statement. """ - def bind_parameter(self, cursor): - param = cursor.cursor.var(Database.NUMBER) + param = cursor.cursor.var(int) cursor._insert_id_var = param return param