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
def _getDbFields(self, cur, table_id): fields = [] db_fields = cur.execute( """ SELECT * from dbd$fields WHERE table_id = :id""", { "id": table_id }).fetchall() field_metadata = self._getMetadata(cur, "dbd$fields") for field in db_fields: field_dictionary = dict(zip(field_metadata, list(field))) tmp = Field(field_dictionary) if field_dictionary["domain_id"] is not None: tmp.domain = self._getDbDomainName( cur, domain_id=field_dictionary["domain_id"]) fields.append(tmp) return fields