CLASS Scan

#include <scan.h>

Scan provide a tuple-by-tuple interface for accessing the content of a HeapFile object.

Relative Methods

Scan *HeapFile::OpenScan(Status &status)

BTreeFileScan *BTreeFile::OpenSearchScan(const void *lowKey = NULL, const void *highKey = NULL) Status BTreeFileScan::GetNext (RecordID & rid, void* keyptr)  

Methods

Status GetNext(RecordID &rid, char *recPtr, int &len)

Retrieve the next record from the HeapFile related with this scan. The content of the record will be copied into the memory location pointed to by recPtr. len will be set to the length of the record in bytes and rid will be set to the record id of the record. Return OK if a record is returned succesfully (including the last record). Return DONE if there are no more records. Return FAIL if something failed.

It will also update the currRid of Scan to the next rid. So, you can rpeatedly call this function  to retrieve all the records in a heapfile.
 

Status MoveTo(RecordID rid)
Set the current RecordID being scanned to the RecordID with record id rid. Calling GetNext() after MoveTo(rid) will return the record with record id rid. Return OK if successful and FAIL otherwise.
Example

Here is a typical example how Scan class is used.

typedef struct Record {
    int i;
    float f;
} Record;
Status s;
HeapFile *f = new HeapFile("foo", s); // Open an existing HeapFile of type Record
if (s != OK)
{
    cerr << "Cannot open HeapFile foo\n";
}

Scan *scan = f->OpenScan(s);
if (s != OK)
{
    cerr << "Cannot open scan on foo\n";
}

int len;
Record r;
RecordID rid;
while (scan->GetNext(rid, (char *)&r, len) == OK)
{
    cout << r.i << " " << r.j << "\n";
}