'Retrieve any constraints or keys (unique, pk, fk, check, index) across
one or more columns.'

def get_constraints(self, cursor, table_name):

    constraints = {}
    cursor.execute(('PRAGMA    index_list(%s)' % self.connection.ops.quote_name(table_name)))
    for row in cursor.fetchall():
        (number, index, unique) = row[:3]
        cursor.execute(('PRAGMA    index_info(%s)' % self.connection.ops.quote_name(index)))
        for (index_rank, column_rank, column) in cursor.fetchall():
            if (index not in constraints):
                constraints[index] = {'columns': [], 'primary_key': False, 'unique': bool(unique), 'foreign_key': False, 'check': False, 'index': True}
            constraints[index]['columns'].append(column)
        if (constraints[index]['index'] and (not constraints[index]['unique'])):
            constraints[index]['type'] = Index.suffix
            cursor.execute(("SELECT    sql    FROM    sqlite_master    WHERE    type='index'    AND    name=%s" % self.connection.ops.quote_name(index)))
            orders = []
            for (sql,) in cursor.fetchall():
                order_info = sql.split('(')[(-1)].split(')')[0].split(',')
                orders = [('DESC' if info.endswith('DESC') else 'ASC') for info in order_info]
            constraints[index]['orders'] = orders
    pk_column = self.get_primary_key_column(cursor, table_name)
    if pk_column:
        constraints['__primary__'] = {'columns': [pk_column], 'primary_key': True, 'unique': False, 'foreign_key': False, 'check': False, 'index': False}
    cursor.execute(('PRAGMA    foreign_key_list(%s)' % self.connection.ops.quote_name(table_name)))
    for row in cursor.fetchall():
        (id_, seq, table, from_, to) = row[:5]
        constraints[('fk_%d' % id_)] = {'columns': [from_], 'primary_key': False, 'unique': False, 'foreign_key': (table, to), 'check': False, 'index': False}
    return constraints
