Fixed #11050 -- Oracle now passes all but one introspection unit test.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10743 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Matt Boersma 2009-05-11 20:55:40 +00:00
parent 369568b8c7
commit 7b81dd4779
1 changed files with 27 additions and 30 deletions

View File

@ -24,16 +24,19 @@ 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):
""" """
@ -76,33 +79,27 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
# 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