mirror of https://github.com/django/django.git
Refs #26682 -- Added AutoField introspection on Oracle.
This commit is contained in:
parent
924a89e135
commit
9af6c97504
|
@ -11,6 +11,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||
has_select_for_update_skip_locked = True
|
||||
can_return_id_from_insert = True
|
||||
allow_sliced_subqueries = False
|
||||
can_introspect_autofield = True
|
||||
supports_subqueries_in_group_by = False
|
||||
supports_transactions = True
|
||||
supports_timezones = False
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import warnings
|
||||
from collections import namedtuple
|
||||
|
||||
import cx_Oracle
|
||||
|
||||
from django.db.backends.base.introspection import (
|
||||
BaseDatabaseIntrospection, FieldInfo, TableInfo,
|
||||
BaseDatabaseIntrospection, FieldInfo as BaseFieldInfo, TableInfo,
|
||||
)
|
||||
from django.utils.deprecation import RemovedInDjango21Warning
|
||||
|
||||
FieldInfo = namedtuple('FieldInfo', BaseFieldInfo._fields + ('is_autofield',))
|
||||
|
||||
|
||||
class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
# Maps type objects to Django Field types.
|
||||
|
@ -32,9 +35,11 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||
precision, scale = description[4:6]
|
||||
if scale == 0:
|
||||
if precision > 11:
|
||||
return 'BigIntegerField'
|
||||
return 'BigAutoField' if description.is_autofield else 'BigIntegerField'
|
||||
elif precision == 1:
|
||||
return 'BooleanField'
|
||||
elif description.is_autofield:
|
||||
return 'AutoField'
|
||||
else:
|
||||
return 'IntegerField'
|
||||
elif scale == -127:
|
||||
|
@ -61,12 +66,16 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||
CASE
|
||||
WHEN char_used IS NULL THEN data_length
|
||||
ELSE char_length
|
||||
END as internal_size
|
||||
END as internal_size,
|
||||
CASE
|
||||
WHEN identity_column = 'YES' THEN 1
|
||||
ELSE 0
|
||||
END as is_autofield
|
||||
FROM user_tab_cols
|
||||
WHERE table_name = UPPER(%s)""", [table_name])
|
||||
field_map = {
|
||||
column: (internal_size, default if default != 'NULL' else None)
|
||||
for column, default, internal_size in cursor.fetchall()
|
||||
column: (internal_size, default if default != 'NULL' else None, is_autofield)
|
||||
for column, default, internal_size, is_autofield in cursor.fetchall()
|
||||
}
|
||||
self.cache_bust_counter += 1
|
||||
cursor.execute("SELECT * FROM {} WHERE ROWNUM < 2 AND {} > 0".format(
|
||||
|
@ -75,14 +84,14 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||
description = []
|
||||
for desc in cursor.description:
|
||||
name = desc[0]
|
||||
internal_size, default = field_map[name]
|
||||
internal_size, default, is_autofield = field_map[name]
|
||||
name = name % {} # cx_Oracle, for some reason, doubles percent signs.
|
||||
description.append(FieldInfo(*(
|
||||
(name.lower(),) +
|
||||
desc[1:3] +
|
||||
(internal_size, desc[4] or 0, desc[5] or 0) +
|
||||
desc[6:] +
|
||||
(default,)
|
||||
(default, is_autofield)
|
||||
)))
|
||||
return description
|
||||
|
||||
|
|
|
@ -195,6 +195,9 @@ Management Commands
|
|||
* The new :option:`diffsettings --output` option allows formatting the output
|
||||
in a unified diff format.
|
||||
|
||||
* On Oracle, :djadmin:`inspectdb` can now introspect ``AutoField`` if the
|
||||
column is created as an identity column.
|
||||
|
||||
Migrations
|
||||
~~~~~~~~~~
|
||||
|
||||
|
|
Loading…
Reference in New Issue