Closed SaintNerevar closed 2 years ago
Fixed, The algorithm in documentation is updated to the following:
int BlockAccess::renameAttribute(char *relName, char *oldName, char *newName) {
// Search for the relation with name relName in relation catalog using Linear Search
Attribute attrValueRelName;
strcpy(attrValueRelName.sVal, relName);
RecId searchIndex = {-1, -1};
RelCacheTable::setSearchIndex(RELCAT_RELID, &searchIndex);
RecId relcatRecId = linearSearch(RELCAT_RELID, "RelName", attrValueRelName, EQ);
// If relation with name relName does not exits (relcatRecId == {-1,-1})
// return E_RELNOTEXIST;
/***
Iterating over all Attribute Catalog Entry record corresponding to relation to find the required attribute
***/
// Reset the Search Index by using RelCacheTable and setting value to {-1, -1}
searchIndex = {-1, -1};
RelCacheTable::setSearchIndex(ATTRCAT_RELID, &searchIndex);
// Define RecId attrId {-1, -1} - used to check if an attribute of oldName exists or not.
RecId attrId{-1, -1};
Attribute attrcatEntryRecord[ATTRCAT_NO_ATTRS];
while (true) {
RecId attrcatEntryRecId = linearSearch(ATTRCAT_RELID, "RelName", relationName, EQ);
if (attrcatEntryRecId.block == -1) {
break;
}
// Get the attribute catalog record from the attribute catalog
// Hint: instantiate RecBuffer Class with appropriate block number and use getRecord method to store the record into attrcatEntryRecord.
// if (strcmp(attrcatEntryRecord[1].sVal, oldName) == 0) attrId = attrcatEntryRecId;
// if (strcmp(attrcatEntryRecord[1].sVal, newName) == 0) return E_ATTREXIST;
}
// if (attrId.block == -1) return E_ATTRNOTEXIST;
// Update the entry corresponding to the attribute in the Attribute Catalog Relation.
/* Hint: Instantiate RecBuffer class by passing appropriate block number = attrId.block
Get the record corresponding to the entry by using getRecord method by passing attrId.slot
as argument.
Use setRecord method to set the record back after updating the entry appropriately.
*/
// return SUCCESS
}
Few corrections in BlockAccess::renameAttribute()
This doesn't seem right.
The way it is right now, this algorithm is quite confusing. Attaching my implementation in case it helps.