DBMS Requirements: SortTable

Class SortTable {

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

bool disconnect();

bool openTable(const char* aTableName);

void setDistinct();

bool sort();

void* fetch();

bool closeTable();

}

SortTable Guidelines

  1. Assume table has only one field of type integer.
  2. Use DBAPI classes to implement the above methods.
  3. sort() method should retrieve all the record pointers using table->fetch() and sort it.
  4. Based on the table->numTuples(), compute total memory required and allocate using malloc() to store the record pointers during sort().
  5. fetch() should return pointer to the first element in the sorted array. Subsequent fetch() should return the next element and so on.
  6. If setDistinct() method is called before calling sort(), then sorted array should not have duplicate entries. It needs to be discarded.
  7. Implement atleast two sorting algorithms and give performance comparision with the two algorithms used.

%%

SortTable Usage

int main() {

bool ret;

SortTable sTable;

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

ret = sTable.openTable("T1");

sTable.setDistinct();

sTable.sort();

void* record;

printf("Sorted Records\n");

while (true) {

record = sTable.fetch();

if (record == NULL) break;

printf("Record Value %d\n", *(int*) record);

}

sTable.closeTable();

sTable.disconnect();

return 0;

}

Assumption: Table T1 with field f1 of type int already exists in database.