Exemplo n.º 1
0
    def fetch_tables(self, schema):
        cursor = self.connection.cursor()

        tables_list = list()
        tables = cursor.execute(
            """
        select 
            t.name, 
            OBJECTPROPERTY(t.object_id, 'HasInsertTrigger') as addition, 
            OBJECTPROPERTY(t.object_id, 'HasUpdateTrigger') as edition, 
            t.temporal_type
        from sys.tables as t
        join sys.schemas as s
        on t.schema_id = s.schema_id
        where s.name = ?;""", (schema.name, )).fetchall()
        for tbl in tables:
            table = Dbc.Table()
            table.name = tbl[0]
            table.add = bool(tbl[1])
            table.edit = bool(tbl[2])
            table.temporal_mode = bool(tbl[3])
            table.indices = self.fetch_indices(schema.name, table.name)
            table.constraints = self.fetch_constraints(schema.name, table.name)
            table.fields = self.fetch_fields(table.name, schema)
            tables_list.append(table)

        return tables_list
Exemplo n.º 2
0
    def get_tables(self):
        """
        :return:    tables_list: list of tables in xml file.

        Parse a xml file to find tables.
        """
        tables_list = list()
        for table in self.xml_repr.getElementsByTagName("table"):
            tbl = Dbc.Table()
            for an, av in table.attributes.items():
                if an.lower() == "name":
                    tbl.name = av
                elif an.lower() == "description":
                    tbl.description = av
                elif an.lower() == "props":
                    for prop in av.split(", "):
                        if prop == "add":
                            tbl.add = True
                        elif prop == "edit":
                            tbl.edit = True
                        elif prop == "delete":
                            tbl.delete = True
                        elif prop == "temporal_mode":
                            tbl.temporal_mode = True
                        else:
                            raise WrongPropertyException(
                                ["delete", "temporal_mode", "edit", "add"],
                                prop)
                # elif an.lower() == "ht_table_flags":
                #     tbl.ht_table_flags = av
                # elif an.lower() == "access_level":
                #     tbl.access_level = av
                elif an.lower() == "ht_table_flags":
                    pass
                elif an.lower() == "access_level":
                    pass
                elif an.lower() == "means":
                    tbl.means = av
                else:
                    raise WrongAttributeException([
                        "props", "access_level", "ht_table_flags",
                        "description", "name"
                    ], an)
            tbl.fields = self.get_fields(table)
            tbl.indices = self.get_indices(table)
            tbl.constraints = self.get_constraints(table)
            tables_list.append(tbl)

        return tables_list
Exemplo n.º 3
0
    def fetch_tables(self):
        cursor = self.connection.cursor()

        tables_list = list()
        tables_attributes = cursor.execute("""\
        select id, name, description, can_add, can_edit, can_delete, temporal_mode, means from dbd$tables"""
                                           ).fetchall()
        for attr_tuple in tables_attributes:
            table = Dbc.Table()
            tid, table.name, table.description, table.add, table.edit, table.delete, table.temporal_mode, \
                table.means = attr_tuple
            table.add, table.edit, table.delete = map(
                bool, [table.add, table.edit, table.delete])
            table.fields = self.fetch_fields(tid)
            table.constraints = self.fetch_constraints(tid)
            table.indices = self.fetch_indices(tid)
            tables_list.append(table)

        return tables_list