Exemplo n.º 1
0
    def fetch_domains(self):
        cursor = self.connection.cursor()

        domain_list = list()
        domain_attributes = cursor.execute("""\
        select name, description, data_type_id, align, width, length, precision, show_null, summable, case_sensitive, \
        show_lead_nulls, thousands_separator, char_length, scale from dbd$domains"""
                                           ).fetchall()
        for attr_tuple in domain_attributes:
            domain = Dbc.Domain()
            domain.name, domain.description, domain.type, domain.align, domain.width, domain.length, \
                domain.precision, domain.show_null, domain.summable, domain.case_sensitive, domain.show_lead_nulls, \
                domain.thousands_separator, domain.char_length, domain.scale = attr_tuple

            domain.show_null, domain.show_lead_nulls, domain.thousands_separator, domain.summable, \
                domain.case_sensitive = map(bool, [domain.show_null, domain.show_lead_nulls, domain.thousands_separator,
                                                   domain.summable, domain.case_sensitive])
            domain.char_length = str(
                domain.char_length) if domain.char_length else None
            domain.length = str(domain.length) if domain.length else None
            domain.scale = str(domain.scale) if domain.scale else None
            domain.precision = str(
                domain.precision) if domain.precision else None
            domain.width = str(domain.width) if domain.width else None

            domain.type = cursor.execute(
                """select type_id from dbd$data_types where dbd$data_types.id = ?""",
                (domain.type, )).fetchone()[0]
            domain_list.append(domain)

        return domain_list
Exemplo n.º 2
0
    def fetch_fields(self, table_name, schema):
        cursor = self.connection.cursor()

        field_list = list()
        fields = cursor.execute("""
        select 
            COLUMN_NAME as name, 
            t.name as dom,
            ORDINAL_POSITION as position, 
            sc.is_identity as edit,
            sc.is_hidden as show_in_grid,
            sc.is_computed as autocalculated,
            sc.is_nullable as required,
            col.DATA_TYPE,
            sc.scale,
            sc.precision,
            sc.max_length
        from INFORMATION_SCHEMA.TABLES as tbl
        left join INFORMATION_SCHEMA.COLUMNS as col
        on col.TABLE_NAME = tbl.TABLE_NAME
        left join sys.columns as sc
        on sc.object_id = object_id(tbl.table_schema + '.' + tbl.table_name) and sc.NAME = col.COLUMN_NAME
        left join sys.types as t
        on col.DATA_TYPE = t.name
        where tbl.TABLE_NAME = ?;""", (table_name,)).fetchall()

        # НЕ РАБОТАЕТ (SQL type - 150 not supported yet)
        # prop.value as descript,
        # left join sys.extended_properties prop
        # on prop.major_id = sc.object_id and prop.minor_id = sc.column_id and prop.NAME = 'MS_Description'

        domain_list = list()
        for fld in fields:
            field = Dbc.Field()
            field.name = fld[0]
            field.domain = fld[1]
            field.position = str(fld[2])
            field.edit = fld[3]
            field.show_in_grid = fld[4]
            field.autocalculated = fld[5]
            field.required = fld[6]
            field.input = not(field.autocalculated or field.edit)
            domain = Dbc.Domain()
            domain.char_length = str(fld[10])
            domain.precision = str(fld[9])
            domain.scale = str(fld[8])
            domain.type = TYPES[fld[7]]
            domain_list.append(domain)

            field.domain = domain
            field_list.append(field)
        # schema.domains += domain_list
        return field_list
Exemplo n.º 3
0
    def get_domains(self):
        """
        :return:    domain_list: list of domains.

        Parse an xml file to find domains in.
        """
        domain_list = list()
        for domain in self.xml_repr.getElementsByTagName("domain"):
            dom = Dbc.Domain()
            for an, av in domain.attributes.items():
                if an.lower() == "name":
                    dom.name = av
                elif an.lower() == "description":
                    dom.description = av
                elif an.lower() == "type":
                    dom.type = av
                elif an.lower() == "align":
                    dom.align = av
                elif an.lower() == "width":
                    dom.width = av
                elif an.lower() == "props":
                    for prop in av.split(", "):
                        if prop == "show_null":
                            dom.show_null = True
                        elif prop == "summable":
                            dom.summable = True
                        elif prop == "case_sensitive":
                            dom.case_sensitive = True
                        elif prop == "show_lead_nulls":
                            dom.show_lead_nulls = True
                        elif prop == "thousand_separator":
                            dom.thousands_separator = True
                        else:
                            raise WrongPropertyException(
                                ["show_null", "summable", "case_sensitive", "show_lead_nulls", "thousands_separator"],
                                prop)
                elif an.lower() == "char_length":
                    dom.char_length = av
                elif an.lower() == "length":
                    dom.length = av
                elif an.lower() == "precision":
                    dom.precision = av
                elif an.lower() == "scale":
                    dom.scale = av
                else:
                    raise WrongAttributeException(
                        ["props", "scale", "length", "char_length", "precision", "width", "align",
                         "type", "description", "name"], an)
            domain_list.append(dom)

        return domain_list