Skip to content

Commit

Permalink
[1.0.X] Fixed #11050 -- Oracle now passes all but one introspection u…
Browse files Browse the repository at this point in the history
…nit test.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10744 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
mboersma committed May 11, 2009
1 parent 9b86444 commit 0f98f0b
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions django/db/backends/oracle/introspection.py
Expand Up @@ -24,17 +24,20 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
def get_table_list(self, cursor): def get_table_list(self, cursor):
"Returns a list of table names in the current database." "Returns a list of table names in the current database."
cursor.execute("SELECT TABLE_NAME FROM USER_TABLES") cursor.execute("SELECT TABLE_NAME FROM USER_TABLES")
return [row[0].upper() for row in cursor.fetchall()] return [row[0].lower() for row in cursor.fetchall()]


def get_table_description(self, cursor, table_name): def get_table_description(self, cursor, table_name):
"Returns a description of the table, with the DB-API cursor.description interface." "Returns a description of the table, with the DB-API cursor.description interface."
cursor.execute("SELECT * FROM %s WHERE ROWNUM < 2" % self.connection.ops.quote_name(table_name)) cursor.execute("SELECT * FROM %s WHERE ROWNUM < 2" % self.connection.ops.quote_name(table_name))
return cursor.description description = []
for desc in cursor.description:
description.append((desc[0].lower(),) + desc[1:])
return description


def table_name_converter(self, name): def table_name_converter(self, name):
"Table name comparison is case insensitive under Oracle" "Table name comparison is case insensitive under Oracle"
return name.upper() return name.lower()

def _name_to_index(self, cursor, table_name): def _name_to_index(self, cursor, table_name):
""" """
Returns a dictionary of {field_name: field_index} for the given table. Returns a dictionary of {field_name: field_index} for the given table.
Expand Down Expand Up @@ -76,33 +79,27 @@ def get_indexes(self, cursor, table_name):
# This query retrieves each index on the given table, including the # This query retrieves each index on the given table, including the
# first associated field name # first associated field name
# "We were in the nick of time; you were in great peril!" # "We were in the nick of time; you were in great peril!"
sql = """ sql = """\
WITH primarycols AS ( SELECT LOWER(all_tab_cols.column_name) AS column_name,
SELECT user_cons_columns.table_name, user_cons_columns.column_name, 1 AS PRIMARYCOL CASE user_constraints.constraint_type
FROM user_cons_columns, user_constraints WHEN 'P' THEN 1 ELSE 0
WHERE user_cons_columns.constraint_name = user_constraints.constraint_name AND END AS is_primary_key,
user_constraints.constraint_type = 'P' AND CASE user_indexes.uniqueness
user_cons_columns.table_name = %s), WHEN 'UNIQUE' THEN 1 ELSE 0
uniquecols AS ( END AS is_unique
SELECT user_ind_columns.table_name, user_ind_columns.column_name, 1 AS UNIQUECOL FROM all_tab_cols, user_cons_columns, user_constraints, user_ind_columns, user_indexes
FROM user_indexes, user_ind_columns WHERE all_tab_cols.column_name = user_cons_columns.column_name (+)
WHERE uniqueness = 'UNIQUE' AND AND all_tab_cols.table_name = user_cons_columns.table_name (+)
user_indexes.index_name = user_ind_columns.index_name AND AND user_cons_columns.constraint_name = user_constraints.constraint_name (+)
user_ind_columns.table_name = %s) AND user_constraints.constraint_type (+) = 'P'
SELECT allcols.column_name, primarycols.primarycol, uniquecols.UNIQUECOL AND user_ind_columns.column_name (+) = all_tab_cols.column_name
FROM (SELECT column_name FROM primarycols UNION SELECT column_name FROM AND user_ind_columns.table_name (+) = all_tab_cols.table_name
uniquecols) allcols, AND user_indexes.uniqueness (+) = 'UNIQUE'
primarycols, uniquecols AND user_indexes.index_name (+) = user_ind_columns.index_name
WHERE allcols.column_name = primarycols.column_name (+) AND AND all_tab_cols.table_name = UPPER(%s)
allcols.column_name = uniquecols.column_name (+) """
""" cursor.execute(sql, [table_name])
cursor.execute(sql, [table_name, table_name])
indexes = {} indexes = {}
for row in cursor.fetchall(): for row in cursor.fetchall():
# row[1] (idx.indkey) is stored in the DB as an array. It comes out as
# a string of space-separated integers. This designates the field
# indexes (1-based) of the fields that have indexes on the table.
# Here, we skip any indexes across multiple fields.
indexes[row[0]] = {'primary_key': row[1], 'unique': row[2]} indexes[row[0]] = {'primary_key': row[1], 'unique': row[2]}
return indexes return indexes

0 comments on commit 0f98f0b

Please sign in to comment.