DBMS Requirements: EquiJoinTable

Class EquiJoinTable {

bool connect(const char* aUserName, const char* aPassword);

bool disconnect();

bool openTable(const char* aTableName1, const char* aTableName2);

void* fetch();

bool closeTable();

}

EquiJoinTable Guidelines

  1. Assume both table has only two fields, both of type integer with hash index on first field on both tables.
  2. Use DBAPI classes to implement the above methods.
  3. fetch() method should retrieve record using table1->fetch(), get record from table2->fetch() for matching f1 value in table1.
  4. After fetch is called on both the tables, populate buffer to hold values of t1.f1, t1.f2, t2.f2 and return pointer to this buffer.

%%

EquiJoinTable Usage

int main() {

EquiJoinTable sTable;

sTable.connect("root", "manager");

sTable.openTable("T1", "T2");

char* record;

while (true) {

record = (char*) sTable.fetch();

if (record == NULL) break;

printf("Tuple t1.f1=%d t1.f2=%d t2.f2=%d n",

*(int*) record,

*(int*) (record + sizeof(int)),

*(int*) (record + sizeof(int) * 2));

}

sTable.closeTable();

sTable.disconnect();

return 0;

}

Assumption: Table T1, T2 with field f1 and f2, both of type integer already exists in database