Refs #28859 -- Simplified fetch_returned_insert_id() by using int data type for binding variable on Oracle.

This commit is contained in:
Mariusz Felisiak 2019-02-04 16:31:23 +01:00 committed by GitHub
parent 3634560fa9
commit 85f924a9b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

@ -227,17 +227,16 @@ END;
return " DEFERRABLE INITIALLY DEFERRED" return " DEFERRABLE INITIALLY DEFERRED"
def fetch_returned_insert_id(self, cursor): def fetch_returned_insert_id(self, cursor):
try: value = cursor._insert_id_var.getvalue()
value = cursor._insert_id_var.getvalue() if value is None or value == []:
# cx_Oracle < 7 returns value, >= 7 returns list with single value. # cx_Oracle < 6.3 returns None, >= 6.3 returns empty list.
return int(value[0] if isinstance(value, list) else value)
except (IndexError, TypeError):
# cx_Oracle < 6.3 returns None, >= 6.3 raises IndexError.
raise DatabaseError( raise DatabaseError(
'The database did not return a new row id. Probably "ORA-1403: ' 'The database did not return a new row id. Probably "ORA-1403: '
'no data found" was raised internally but was hidden by the ' 'no data found" was raised internally but was hidden by the '
'Oracle OCI library (see https://code.djangoproject.com/ticket/28859).' '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): def field_cast_sql(self, db_type, internal_type):
if db_type and db_type.endswith('LOB'): if db_type and db_type.endswith('LOB'):

View File

@ -9,9 +9,8 @@ class InsertIdVar:
as a parameter, in order to receive the id of the row created by an as a parameter, in order to receive the id of the row created by an
insert statement. insert statement.
""" """
def bind_parameter(self, cursor): def bind_parameter(self, cursor):
param = cursor.cursor.var(Database.NUMBER) param = cursor.cursor.var(int)
cursor._insert_id_var = param cursor._insert_id_var = param
return param return param