Exemplo n.º 1
0
    def fetch_indices(self, schema_name, table_name):
        cursor = self.connection.cursor()

        indices_list = list()
        indices = cursor.execute("""
        select 
            ind.name as index_name, 
            ind.is_unique, 
            fti.object_id as is_fulltext, 
            c.name as field_name
        from sys.indexes as ind
        left join sys.fulltext_indexes as fti
        on ind.object_id = fti.object_id
        join sys.index_columns as ic
        on ind.object_id = ic.object_id and ind.index_id = ic.index_id
        join sys.columns as c
        on ind.object_id = c.object_id and ic.column_id = c.column_id
        where ind.object_id = OBJECT_ID(?);""",
                                 ("{schema_name}.{table_name}".format(schema_name=schema_name,
                                                                      table_name=table_name),)).fetchall()
        for ind in indices:
            index = Dbc.Index()
            index.name = ind[0]
            index.uniqueness = ind[1]
            index.fulltext = bool(ind[2])
            index.field = ind[3]
            indices_list.append(index)

        return indices_list
Exemplo n.º 2
0
    def fetch_indices(self, table_id):
        cursor = self.connection.cursor()

        indices_list = list()
        indices_attributes = cursor.execute(
            """\
        select id, name, local, kind\
        from dbd$indices\
        where dbd$indices.table_id = ?""", (table_id, )).fetchall()
        for attr_tuple in indices_attributes:
            index = Dbc.Index()
            if attr_tuple[3] == "fulltext":
                index.fulltext, index.uniqueness = True, False
            elif attr_tuple[3] == "uniqueness":
                index.fulltext, index.uniqueness = False, True
            else:
                index.fulltext, index.uniqueness = False, False
            index.name, index.local = attr_tuple[1:-1]
            index.field = cursor.execute(
                """\
            select name from dbd$fields \
            where dbd$fields.id = (\
            select field_id from dbd$index_details\
            where dbd$index_details.index_id = ?)""",
                (attr_tuple[0], )).fetchone()[0]
            indices_list.append(index)

        return indices_list
Exemplo n.º 3
0
    def get_indices(table):
        """
        :param      table: Dbc.Table() to find indices in.

        :return:    indices_list: list of indices in table.

        Parse table to find indices in.
        """
        if table.nodeName != "table":
            raise WrongNodeException("table", table.nodeName)

        indices_list = list()
        for index in table.getElementsByTagName("index"):
            idx = Dbc.Index()
            for an, av in index.attributes.items():
                if an.lower() == "name":
                    idx.name = av
                elif an.lower() == "field":
                    idx.field = av
                elif an.lower() == "props":
                    for prop in av.split(", "):
                        if prop == "fulltext":
                            idx.fulltext = True
                        elif prop == "uniqueness":
                            idx.uniqueness = True
                        elif prop == "local":
                            idx.local = True
                        else:
                            raise WrongPropertyException(["fulltext", "uniqueness", "local"], prop)
                else:
                    raise WrongAttributeException(["field", "name", "props"], an)
            indices_list.append(idx)

        return indices_list