Refs #24245 -- Added introspection for database defaults on Oracle.
This commit is contained in:
parent
6f43b2b8a5
commit
e17f40f4b5
|
@ -4,7 +4,7 @@ from collections import namedtuple
|
|||
TableInfo = namedtuple('TableInfo', ['name', 'type'])
|
||||
|
||||
# Structure returned by the DB-API cursor.description interface (PEP 249)
|
||||
FieldInfo = namedtuple('FieldInfo', 'name type_code display_size internal_size precision scale null_ok')
|
||||
FieldInfo = namedtuple('FieldInfo', 'name type_code display_size internal_size precision scale null_ok default')
|
||||
|
||||
|
||||
class BaseDatabaseIntrospection(object):
|
||||
|
|
|
@ -10,7 +10,7 @@ from django.utils.datastructures import OrderedSet
|
|||
from django.utils.deprecation import RemovedInDjango21Warning
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
FieldInfo = namedtuple('FieldInfo', FieldInfo._fields + ('extra', 'default'))
|
||||
FieldInfo = namedtuple('FieldInfo', FieldInfo._fields + ('extra',))
|
||||
InfoLine = namedtuple('InfoLine', 'col_name data_type max_len num_prec num_scale extra column_default')
|
||||
|
||||
|
||||
|
@ -89,8 +89,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||
to_int(field_info[col_name].num_prec) or line[4],
|
||||
to_int(field_info[col_name].num_scale) or line[5],
|
||||
line[6],
|
||||
field_info[col_name].extra,
|
||||
field_info[col_name].column_default,
|
||||
field_info[col_name].extra,
|
||||
)
|
||||
))
|
||||
)
|
||||
|
|
|
@ -22,7 +22,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||
has_bulk_insert = True
|
||||
supports_tablespaces = True
|
||||
supports_sequence_reset = False
|
||||
can_introspect_default = False # Pending implementation by an interested person.
|
||||
can_introspect_max_length = False
|
||||
can_introspect_time_field = False
|
||||
atomic_transactions = False
|
||||
|
|
|
@ -60,6 +60,13 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||
|
||||
def get_table_description(self, cursor, table_name):
|
||||
"Returns a description of the table, with the DB-API cursor.description interface."
|
||||
# user_tab_columns gives data default for columns
|
||||
cursor.execute("""
|
||||
SELECT column_name, data_default
|
||||
FROM user_tab_cols
|
||||
WHERE table_name = UPPER(%s)""", [table_name])
|
||||
columns_default = {column: default if default != 'NULL' else None for column, default in cursor.fetchall()}
|
||||
|
||||
self.cache_bust_counter += 1
|
||||
cursor.execute("SELECT * FROM {} WHERE ROWNUM < 2 AND {} > 0".format(
|
||||
self.connection.ops.quote_name(table_name),
|
||||
|
@ -67,8 +74,9 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||
description = []
|
||||
for desc in cursor.description:
|
||||
name = force_text(desc[0]) # cx_Oracle always returns a 'str' on both Python 2 and 3
|
||||
default = columns_default[name]
|
||||
name = name % {} # cx_Oracle, for some reason, doubles percent signs.
|
||||
description.append(FieldInfo(*(name.lower(),) + desc[1:]))
|
||||
description.append(FieldInfo(*(name.lower(),) + desc[1:] + (default,)))
|
||||
return description
|
||||
|
||||
def table_name_converter(self, name):
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import warnings
|
||||
from collections import namedtuple
|
||||
|
||||
from django.db.backends.base.introspection import (
|
||||
BaseDatabaseIntrospection, FieldInfo, TableInfo,
|
||||
|
@ -9,8 +8,6 @@ from django.db.backends.base.introspection import (
|
|||
from django.utils.deprecation import RemovedInDjango21Warning
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
FieldInfo = namedtuple('FieldInfo', FieldInfo._fields + ('default',))
|
||||
|
||||
|
||||
class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
# Maps type codes to Django Field types.
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import re
|
||||
import warnings
|
||||
from collections import namedtuple
|
||||
|
||||
from django.db.backends.base.introspection import (
|
||||
BaseDatabaseIntrospection, FieldInfo, TableInfo,
|
||||
|
@ -8,7 +7,6 @@ from django.db.backends.base.introspection import (
|
|||
from django.utils.deprecation import RemovedInDjango21Warning
|
||||
|
||||
field_size_re = re.compile(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$')
|
||||
FieldInfo = namedtuple('FieldInfo', FieldInfo._fields + ('default',))
|
||||
|
||||
|
||||
def get_field_size(name):
|
||||
|
|
Loading…
Reference in New Issue