Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.4.x] Fixed #20907 - Test failure on Oracle

Backport of the Oracle-specific part of commit a18e43c
from master. This commit made get_indexes more consistent across
backends.

Thanks Tim Graham for pointer to the commit, akaariai and ikelly
for the original commit.
  • Loading branch information...
commit 7826824aef42097e265ad5132bfbff4c64762dd7 1 parent d9dc981
@shaib shaib authored
Showing with 26 additions and 31 deletions.
  1. +26 −31 django/db/backends/oracle/introspection.py
View
57 django/db/backends/oracle/introspection.py
@@ -72,14 +72,14 @@ def get_relations(self, cursor, table_name):
FROM user_constraints, USER_CONS_COLUMNS ca, USER_CONS_COLUMNS cb,
user_tab_cols ta, user_tab_cols tb
WHERE user_constraints.table_name = %s AND
- ta.table_name = %s AND
+ ta.table_name = user_constraints.table_name AND
ta.column_name = ca.column_name AND
- ca.table_name = %s AND
+ ca.table_name = ta.table_name AND
user_constraints.constraint_name = ca.constraint_name AND
user_constraints.r_constraint_name = cb.constraint_name AND
cb.table_name = tb.table_name AND
cb.column_name = tb.column_name AND
- ca.position = cb.position""", [table_name, table_name, table_name])
+ ca.position = cb.position""", [table_name])
relations = {}
for row in cursor.fetchall():
@@ -87,36 +87,31 @@ def get_relations(self, cursor, table_name):
return relations
def get_indexes(self, cursor, table_name):
+ sql = """
+ SELECT LOWER(uic1.column_name) AS column_name,
+ CASE user_constraints.constraint_type
+ WHEN 'P' THEN 1 ELSE 0
+ END AS is_primary_key,
+ CASE user_indexes.uniqueness
+ WHEN 'UNIQUE' THEN 1 ELSE 0
+ END AS is_unique
+ FROM user_constraints, user_indexes, user_ind_columns uic1
+ WHERE user_constraints.constraint_type (+) = 'P'
+ AND user_constraints.index_name (+) = uic1.index_name
+ AND user_indexes.uniqueness (+) = 'UNIQUE'
+ AND user_indexes.index_name (+) = uic1.index_name
+ AND uic1.table_name = UPPER(%s)
+ AND uic1.column_position = 1
+ AND NOT EXISTS (
+ SELECT 1
+ FROM user_ind_columns uic2
+ WHERE uic2.index_name = uic1.index_name
+ AND uic2.column_position = 2
+ )
"""
- Returns a dictionary of fieldname -> infodict for the given table,
- where each infodict is in the format:
- {'primary_key': boolean representing whether it's the primary key,
- 'unique': boolean representing whether it's a unique index}
- """
- # This query retrieves each index on the given table, including the
- # first associated field name
- # "We were in the nick of time; you were in great peril!"
- sql = """\
-SELECT LOWER(all_tab_cols.column_name) AS column_name,
- CASE user_constraints.constraint_type
- WHEN 'P' THEN 1 ELSE 0
- END AS is_primary_key,
- CASE user_indexes.uniqueness
- WHEN 'UNIQUE' THEN 1 ELSE 0
- END AS is_unique
-FROM all_tab_cols, user_cons_columns, user_constraints, user_ind_columns, user_indexes
-WHERE all_tab_cols.column_name = user_cons_columns.column_name (+)
- AND all_tab_cols.table_name = user_cons_columns.table_name (+)
- AND user_cons_columns.constraint_name = user_constraints.constraint_name (+)
- AND user_constraints.constraint_type (+) = 'P'
- AND user_ind_columns.column_name (+) = all_tab_cols.column_name
- AND user_ind_columns.table_name (+) = all_tab_cols.table_name
- AND user_indexes.uniqueness (+) = 'UNIQUE'
- AND user_indexes.index_name (+) = user_ind_columns.index_name
- AND all_tab_cols.table_name = UPPER(%s)
-"""
cursor.execute(sql, [table_name])
indexes = {}
for row in cursor.fetchall():
- indexes[row[0]] = {'primary_key': row[1], 'unique': row[2]}
+ indexes[row[0]] = {'primary_key': bool(row[1]),
+ 'unique': bool(row[2])}
return indexes

0 comments on commit 7826824

Please sign in to comment.
Something went wrong with that request. Please try again.