def __init__(self, filtr=None, query=None): """ Construct a virtual sctid set :param filtr: One of a textual SQL filter, a generator for SCTID's or None (wild card) :param query: A complete query -- result of and, or or minus """ Set.__init__(self, Sctids) _Instance.__init__(self, Sctids) RF2_Substrate_Common.__init__(self) self._val = self self._type = sctId if query is not None: self._query = query else: if filtr is not None and not isinstance(filtr, str): sctid_list = filtr if isinstance(filtr, Container) else [filtr] if sctid_list: filtr = 'id IN (' + ','.join(str(e) for e in sctid_list) + ')' else: filtr = ' False ' self._query = self._db.buildQuery(**self._build_parms(filtr))
def __init__(self, rf: bool=False, atts: Sctids=None, eq: bool=True, ecv: Sctids=None, query=None, _mt_instance=None): """ Construct a set of quads from :param rf: reverse flag. If true ecv applies to source. If false, destination :param atts: attributes (types) :param eq: If true, test for equal, if false, for not equal :param ecv: sources / destinations for testing :param query: query to use instead of constructing. Still need rf :return: """ Set.__init__(self, Quads) _Instance.__init__(self, RF2_Quad) RF2_Substrate_Common.__init__(self) self._val = self self._type = Quads if _mt_instance: self._query = "SELECT id AS rid, sourceId AS id, typeId, destinationId, gid FROM %s WHERE 0" % \ (RelationshipDB.fname() + "_ext") self.rf = False self._len = 0 else: self._len = None # number of elements if query: self._query = query else: self._query = "SELECT id AS rid, sourceId" + (" AS id," if not rf else ",") self._query += " typeId, destinationId" + (" AS id," if rf else ",") self._query += " gid FROM %s" % RelationshipDB.fname() + '_ext' self._query += " WHERE " if atts is not None: self._query += (("typeId IN (%s)" % atts.as_sql()) if eq else ("typeId NOT IN (%s)" % atts.as_sql())) + " AND " if ecv is not None: self._query += (("sourceId IN (%s)" % ecv.as_sql()) if rf else ("destinationId IN (%s)" % ecv.as_sql())) + " AND " self._query += "active=1 AND locked=0" self.rf = rf