Beispiel #1
0
    def _getIndices(self, xml):
        if xml.nodeName != "table":
            raise ValueError("Is not a table")

        indexes = []
        for index in xml.getElementsByTagName("index"):
            tmp = Index()
            if index.hasChildNodes():
                for item in index.getElementsByTagName("item"):
                    pass
            else:
                item = Item()
                item.name = index.getAttribute("field")
                tmp.fields.append(item.name)
            for attributeName, attributeValue in index.attributes.items():
                if attributeName.lower() == "field":
                    pass
                elif attributeName.lower() == "props":
                    for prop in attributeValue.split(", "):
                        if prop == "fulltext":
                            tmp.fulltext = True
                        elif prop == "uniqueness":
                            tmp.uniqueness = True
                        else:
                            raise ValueError(
                                "Invalid format of props string: {}".format(
                                    attributeValue))
                else:
                    raise ValueError(
                        "Incorrect attribute name \"{}\" in tag \"{}\" ".
                        format(attributeName, index.nodeName))
            indexes.append(tmp)
        return indexes
Beispiel #2
0
    def _getDbIndices(self, cur, table_id):
        indices = []

        db_indices = cur.execute(
            """ SELECT * from dbd$indices
                                    WHERE table_id = :id""", {
                "id": table_id
            }).fetchall()

        for index in db_indices:
            tmp = Index()

            for item in self._getDbIndexDetails(cur, index[0]):
                tmp.fields.append(item.name)

            if index[2] is not None:
                tmp.name = str(index[2].encode('utf-8'))
            tmp.fulltext = index[3]
            if index[4] != "simple":
                tmp.uniqueness = index[4]

            indices.append(tmp)

        return indices