DBMS Requirements: RangeJoinTable
Class RangeJoinTable {
bool connect(const char* aUserName, const char* aPassword);
bool disconnect();
bool openTable(const char* aTableName1, const char* aTableName2);
void setComparisionOp (CompOp aOp);
void* fetch();
bool closeTable();
}
enum CompOp {
GT, //greater than
LT, //less than
LE, //less than or equal to
GE, //greater than or equal to
}
RangeJoinTable Guidelines
- Assume both table has only two fields, both of type integer.
- Use DBAPI classes to implement the above methods.
- fetch() method should retrieve record using table1->fetch(), get record from table2->fetch() for matching f1 value (based on CompOp set) in table1.
- 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.
%%
RangeJoinTable Guidelines
int main() {
RangeJoinTable sTable;
sTable.connect("root", "manager");
sTable.openTable("T1", "T2");
sTable.setComparisonOp(LE);
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