'Returns a dictionary of {field_index: (field_index_other_table, other_table)}
representing all relationships to the given table. Indexes are 0-based.'

def get_relations(self, cursor, table_name):

    cursor.execute('\n                SELECT    ta.column_id    -    1,    tb.table_name,    tb.column_id    -    1\n                FROM            user_constraints,    USER_CONS_COLUMNS    ca,    USER_CONS_COLUMNS    cb,\n                                            user_tab_cols    ta,    user_tab_cols    tb\n                WHERE        user_constraints.table_name    =    %s    AND\n                                            ta.table_name    =    %s    AND\n                                            ta.column_name    =    ca.column_name    AND\n                                            ca.table_name    =    %s    AND\n                                            user_constraints.constraint_name    =    ca.constraint_name    AND\n                                            user_constraints.r_constraint_name    =    cb.constraint_name    AND\n                                            cb.table_name    =    tb.table_name    AND\n                                            cb.column_name    =    tb.column_name    AND\n                                            ca.position    =    cb.position', [table_name, table_name, table_name])
    relations = {}
    for row in cursor.fetchall():
        relations[row[0]] = (row[2], row[1])
    return relations
