__id__ = "$Id$"

class XTable:
    def __init__(self, name, tcnx):
        self.name = name
        self.tc = tcnx.cursor()
        self.nc = tcnx.ncursor()
        self.type = None
        self.attributes = []
        self.tlineage = []

    def getLineage(self):
        if self.tlineage != []:
            return self.tlineage

        self.nc.execute("SELECT srctable as table FROM trio_tables_lin WHERE tablename = '%s'" % self.name)
        for t in self.nc.fetchall():
            self.tlineage.append(t[0])
        return self.tlineage

    def getAttributes(self):
        c = self.tc.tdb.pdb.cursor()
        if self.attributes != []:
            return self.attributes

        c.execute("SELECT attrname, iscertain FROM trio_attribs WHERE tablename = %s ORDER BY colnum", [self.name])
        self.attributes = c.fetchall()
        return self.attributes

    def getType(self):
        self.nc.execute("SELECT type FROM trio_tables WHERE tablename = '%s'" % self.name)
        self.type = self.nc.fetchone()[0]
        return self.type
