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

        fields = []
        for field in xml.getElementsByTagName("field"):
            tmp = Field()
            domain = Domain()
            for attributeName, attributeValue in field.attributes.items():
                if attributeName.lower() == "name":
                    tmp.name = attributeValue
                elif attributeName.lower() == "rname":
                    tmp.rname = attributeValue
                elif attributeName == "domain":
                    tmp.domain = attributeValue
                elif attributeName.lower() == "domain.name":
                    domain.name = attributeValue
                elif attributeName.lower() == "domain.char_length":
                    domain.char_length = attributeValue
                elif attributeName.lower() == "domain.precision":
                    domain.precision = attributeValue
                elif attributeName.lower() == "domain.scale":
                    domain.scale = attributeValue
                elif attributeName.lower() == "domain.type":
                    domain.type = attributeValue
                elif attributeName.lower() == "description":
                    tmp.description = attributeValue
                elif attributeName.lower() == "props":
                    for prop in attributeValue.split(", "):
                        if prop == "input":
                            tmp.input = True
                        elif prop == "edit":
                            tmp.edit = True
                        elif prop == "show_in_grid":
                            tmp.show_in_grid = True
                        elif prop == "show_in_details":
                            tmp.show_in_details = True
                        elif prop == "is_mean":
                            tmp.is_mean = True
                        elif prop == "autocalculated":
                            tmp.autocalculated = True
                        elif prop == "required":
                            tmp.required = True
                        else:
                            raise ValueError(
                                "Invalid format of props string: {}".format(
                                    attributeValue))
                else:
                    raise ValueError(
                        "Incorrect attribute name \"{}\" in tag \"{}\" ".
                        format(attributeName, field.nodeName))
            if tmp.domain is None:
                tmp.domain = domain
            fields.append(tmp)
        return fields
Exemple #2
0
    def _getDomains(self):
        domains = []
        for domain in self.xml.getElementsByTagName("domain"):
            tmp = Domain()

            for attributeName, attributeValue in domain.attributes.items():
                if attributeName.lower() == "name":
                    tmp.name = attributeValue
                elif attributeName.lower() == "description":
                    tmp.description = attributeValue
                elif attributeName.lower() == "type":
                    tmp.type = attributeValue
                    tmp.type_id = postgres_utils.get_type_in_postgres(tmp)
                elif attributeName.lower() == "align":
                    tmp.align = attributeValue
                elif attributeName.lower() == "width":
                    tmp.width = attributeValue
                elif attributeName.lower() == "precision":
                    tmp.precision = attributeValue
                elif attributeName.lower() == "props":
                    for prop in attributeValue.split(", "):
                        if prop == "show_null":
                            tmp.show_null = True
                        elif prop == "summable":
                            tmp.summable = True
                        elif prop == "case_sensitive":
                            tmp.case_sensitive = True
                        elif prop == "show_lead_nulls":
                            tmp.show_lead_nulls = True
                        elif prop == "thousands_separator":
                            tmp.thousands_separator = True
                        else:
                            raise ValueError(
                                "Invalid format of props string: {}".format(
                                    attributeValue))
                elif attributeName.lower() == "char_length":
                    tmp.char_length = attributeValue
                elif attributeName.lower() == "length":
                    tmp.length = attributeValue
                elif attributeName.lower() == "scale":
                    tmp.scale = attributeValue
                else:
                    raise ValueError(
                        "Incorrect attribute name \"{}\" in tag \"{}\" ".
                        format(attributeName, domain.nodeName))

            domains.append(tmp)
        return domains
Exemple #3
0
    def _getDbDomains(self, cur):
        domains = []

        db_domains = cur.execute("SELECT * from dbd$domains").fetchall()
        domain_metadata = self._getMetadata(cur, "dbd$domains")

        for domain in db_domains:
            domain_dictionary = dict(zip(domain_metadata, list(domain)))
            tmp = Domain(domain_dictionary)
            data_type = cur.execute(
                "SELECT * FROM dbd$data_types WHERE id = :type_id", {
                    "type_id": tmp.data_type_id
                }).fetchall()
            tmp.type = data_type[0][1]
            domains.append(tmp)

        return domains