コード例 #1
0
    def _getTables(self, xml):
        tables = []
        for table in xml.getElementsByTagName("table"):
            tmp = Table()
            for attributeName, attributeValue in table.attributes.items():
                if attributeName.lower() == "name":
                    tmp.name = attributeValue
                elif attributeName.lower() == "description":
                    tmp.description = attributeValue
                elif attributeName.lower() == "props":
                    for prop in attributeValue.split(", "):
                        if prop == "add":
                            tmp.add = True
                        elif prop == "edit":
                            tmp.edit = True
                        elif prop == "delete":
                            tmp.delete = True
                        else:
                            raise ValueError(
                                "Invalid format of props string: {}".format(
                                    attributeValue))
                elif attributeName.lower() == "ht_table_flags":
                    tmp.ht_table_flags = attributeValue
                elif attributeName.lower() == "access_level":
                    tmp.access_level = attributeValue
                else:
                    raise ValueError(
                        "Incorrect attribute name \"{}\" in tag \"{}\" ".
                        format(attributeName, table.nodeName))

            tmp.fields = self._getFields(table)
            tmp.constraints = self._getConstraints(table)
            tmp.indices = self._getIndices(table)
            tables.append(tmp)
        return tables
コード例 #2
0
    def _getDbTables(self, cur, schema_id):
        tables = []

        db_tables = cur.execute(
            """ SELECT * from dbd$tables
                                    WHERE schema_id = :id
                                    GROUP BY id""", {
                "id": schema_id
            }).fetchall()
        tables_metadata = self._getMetadata(cur, "dbd$tables")

        for table in db_tables:
            table_dictionary = dict(zip(tables_metadata, list(table)))
            tmp = Table(table_dictionary)

            if table_dictionary.get("id") is not None:
                tmp.fields = self._getDbFields(cur, table_dictionary["id"])
                tmp.constraints = self._getDbConstraints(
                    cur, table_dictionary["id"])
                tmp.indices = self._getDbIndices(cur, table_dictionary["id"])

            tables.append(tmp)

        return tables