'Constructor:
@param table: a Table object
@param tablename: a Str tablename
@param record: a Row object
@param query: a Query object
@param record_id: a record ID (if object is a Table)
@param record_ids: a list of record IDs (if object is a Table)
- these should be in ascending order
@param rtable: the resource table (for the recursive calls)'

def __init__(self, table=None, tablename=None, record=None, query=None, record_id=None, record_ids=None, rtable=None):

    db = current.db
    s3db = current.s3db
    self.records = []
    self.table = s3db.sit_trackable
    self.rtable = rtable
    if (table or tablename):
        if table:
            tablename = table._tablename
        else:
            table = s3db[tablename]
        fields = self.__get_fields(table)
        if (not fields):
            raise SyntaxError(('Not    a    trackable    type:    %s' % tablename))
        if record_ids:
            query = table._id.belongs(record_ids)
            limitby = (0, len(record_ids))
            orderby = table._id
        elif record_id:
            query = (table._id == record_id)
            limitby = (0, 1)
            orderby = None
        else:
            query = (table._id > 0)
            limitby = None
            orderby = table._id
        fields = [table[f] for f in fields]
        rows = db(query).select(limitby=limitby, orderby=orderby, *fields)
    elif record:
        fields = self.__get_fields(record)
        if (not fields):
            raise SyntaxError('Required    fields    not    present    in    the    row')
        rows = Rows(records=[record], compact=False)
    elif query:
        tablename = db._adapter.get_table(query)
        self.rtable = s3db[tablename]
        fields = self.__get_fields(self.rtable)
        if (not fields):
            raise SyntaxError(('Table    %s    is    not    a    trackable    type' % table._tablename))
        fields = [self.rtable[f] for f in fields]
        rows = db(query).select(*fields)
    else:
        raise SyntaxError('Invalid    parameters')
    records = []
    for r in rows:
        if self.__super_entity(r):
            table = s3db[r.instance_type]
            fields = self.__get_fields(table, super_entity=False)
            if (not fields):
                raise SyntaxError(('Table    %s    is    not    a    trackable    type' % table._tablename))
            fields = [table[f] for f in fields]
            row = db((table[UID] == r[UID])).select(limitby=(0, 1), *fields).first()
            if row:
                records.append(row)
        else:
            records.append(r)
    self.records = Rows(records=records, compact=False)
