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