Ticket #6628: oracle8i_inspectdb.patch

File oracle8i_inspectdb.patch, 3.6 KB (added by psycoman, 17 years ago)
  • introspection.py

     
    3030    cursor.execute("""
    3131SELECT ta.column_id - 1, tb.table_name, tb.column_id - 1
    3232FROM   user_constraints, USER_CONS_COLUMNS ca, USER_CONS_COLUMNS cb,
    33        user_tab_cols ta, user_tab_cols tb
     33       user_tab_columns ta, user_tab_columns tb
    3434WHERE  user_constraints.table_name = %s AND
    3535       ta.table_name = %s AND
    3636       ta.column_name = ca.column_name AND
     
    5757    # first associated field name
    5858    # "We were in the nick of time; you were in great peril!"
    5959    sql = """
    60 WITH primarycols AS (
    61  SELECT user_cons_columns.table_name, user_cons_columns.column_name, 1 AS PRIMARYCOL
    62  FROM   user_cons_columns, user_constraints
    63  WHERE  user_cons_columns.constraint_name = user_constraints.constraint_name AND
    64         user_constraints.constraint_type = 'P' AND
    65         user_cons_columns.table_name = %s),
    66  uniquecols AS (
    67  SELECT user_ind_columns.table_name, user_ind_columns.column_name, 1 AS UNIQUECOL
    68  FROM   user_indexes, user_ind_columns
    69  WHERE  uniqueness = 'UNIQUE' AND
    70         user_indexes.index_name = user_ind_columns.index_name AND
    71         user_ind_columns.table_name = %s)
    72 SELECT allcols.column_name, primarycols.primarycol, uniquecols.UNIQUECOL
    73 FROM   (SELECT column_name FROM primarycols UNION SELECT column_name FROM
    74 uniquecols) allcols,
    75       primarycols, uniquecols
    76 WHERE  allcols.column_name = primarycols.column_name (+) AND
    77       allcols.column_name = uniquecols.column_name (+)
     60SELECT allcols.column_name,
     61    primarycols.primarycol,
     62    uniquecols.UNIQUECOL
     63FROM
     64    (SELECT column_name
     65    FROM
     66        (SELECT user_cons_columns.table_name,
     67            user_cons_columns.column_name   ,
     68            1 AS PRIMARYCOL
     69        FROM user_cons_columns,
     70            user_constraints
     71        WHERE user_cons_columns.constraint_name = user_constraints.constraint_name
     72        AND user_constraints.constraint_type    = 'P'
     73        AND user_cons_columns.table_name        = %s
     74        ) primarycols
     75
     76    UNION
     77
     78    SELECT column_name
     79    FROM
     80        (SELECT user_ind_columns.table_name,
     81            user_ind_columns.column_name   ,
     82            1 AS UNIQUECOL
     83        FROM user_indexes,
     84            user_ind_columns
     85        WHERE uniqueness                = 'UNIQUE'
     86        AND user_indexes.index_name     = user_ind_columns.index_name
     87        AND user_ind_columns.table_name = %s
     88        )uniquecols
     89    ) allcols                           ,
     90    (SELECT user_cons_columns.table_name,
     91        user_cons_columns.column_name   ,
     92        1 AS PRIMARYCOL
     93    FROM user_cons_columns,
     94        user_constraints
     95    WHERE user_cons_columns.constraint_name = user_constraints.constraint_name
     96    AND user_constraints.constraint_type    = 'P'
     97    AND user_cons_columns.table_name        = %s
     98    ) primarycols                      ,
     99    (SELECT user_ind_columns.table_name,
     100        user_ind_columns.column_name   ,
     101        1 AS UNIQUECOL
     102    FROM user_indexes,
     103        user_ind_columns
     104    WHERE uniqueness                = 'UNIQUE'
     105    AND user_indexes.index_name     = user_ind_columns.index_name
     106    AND user_ind_columns.table_name = %s
     107    ) uniquecols
     108WHERE allcols.column_name = primarycols.column_name (+)
     109AND allcols.column_name   = uniquecols.column_name (+)
    78110    """
    79     cursor.execute(sql, [table_name, table_name])
     111    cursor.execute(sql, [table_name, table_name,table_name, table_name])
    80112    indexes = {}
    81113    for row in cursor.fetchall():
    82114        # row[1] (idx.indkey) is stored in the DB as an array. It comes out as
Back to Top