const Status QU_Select(const string & result, const int projCnt, const attrInfo projNames[], const attrInfo *attr, const Operator op, const char *attrValue) { // Qu_Select sets up things and then calls ScanSelect to do the actual work cout << "Doing QU_Select " << endl; Status s; AttrDesc attrDesc; AttrDesc* projAttrInfo = new AttrDesc[projCnt]; int length = 0; for(int i = 0; i < projCnt; i++){ s = attrCat->getInfo(projNames[i].relName, projNames[i].attrName, projAttrInfo[i]); if(s != OK) return s; length += projAttrInfo[i].attrLen; } if(attr == NULL) { s = ScanSelect(result, projCnt, projAttrInfo,NULL, op, NULL, length); if(s != OK) return s; } else { s=attrCat->getInfo(attr->relName, attr->attrName, attrDesc); if(s != OK) return s; int i; float f; switch(attrDesc.attrType) { case INTEGER: { i = atoi(attrValue); attrValue = (char *)&i; break; } case FLOAT: { f = atof(attrValue); attrValue = (char *)&f; break; } case STRING: { //do nothing break; } } s = ScanSelect(result, projCnt, projAttrInfo, &attrDesc, op, attrValue, length); if(s != OK) return s; } delete projAttrInfo; return s; }
const Status QU_Select(const string & result, const int projCnt, const attrInfo projNames[], const attrInfo *attr, const Operator op, const char *attrValue) { // Qu_Select sets up things and then calls ScanSelect to do the actual work cout << "Doing QU_Select " << endl; Status status; // go through the projection list and look up each in the // attr cat to get an AttrDesc structure (for offset, length, etc) AttrDesc attrDescArray[projCnt]; for (int i = 0; i < projCnt; i++) { Status status = attrCat->getInfo(projNames[i].relName, projNames[i].attrName, attrDescArray[i]); if (status != OK) { return status; } } // get output record length from attrdesc structures int reclen = 0; for (int i = 0; i < projCnt; i++) { reclen += attrDescArray[i].attrLen; } if (attr){ // get AttrDesc structure for the select attribute AttrDesc attrDesc1; status = attrCat->getInfo(attr->relName, attr->attrName, attrDesc1); if (status != OK) { return status; } return ScanSelect(result, projCnt, attrDescArray, &attrDesc1, op, attrValue, reclen); } else { return ScanSelect(result, projCnt, attrDescArray, NULL, op, attrValue, reclen); } }
const Status QU_Select(const string & result, const int projCnt, const attrInfo projNames[], const attrInfo *attr, //If null, unconditional scan const Operator op, const char *attrValue) { // Qu_Select sets up things and then calls ScanSelect to do the actual work cout << "Doing QU_Select " << endl; Status status; AttrDesc projNames_Descs[projCnt]; for (int i = 0; i < projCnt; i++) { status = attrCat->getInfo(projNames[i].relName, projNames[i].attrName, projNames_Descs[i]); if (status != OK) return status; } AttrDesc *attrDescWhere = NULL; int attrValueLen = 0; if(attr != NULL) { attrDescWhere = new AttrDesc; status = attrCat->getInfo(attr->relName, attr->attrName, *attrDescWhere); attrValueLen = attrDescWhere->attrLen; if (status != OK) return status; } return ScanSelect( result, projCnt, projNames_Descs, attrDescWhere, op, attrValue, attrValueLen); }
const Status QU_Select(const string & result, const int projCnt, const attrInfo projNames[], const attrInfo *attr, const Operator op, const char *attrValue) { // Qu_Select sets up things and then calls ScanSelect to do the actual work cout << "Doing QU_Select " << endl; Status status; AttrDesc attrDesc; int intval; float floatval; const char *filter; AttrDesc* projDescs = new AttrDesc[projCnt]; for(int i = 0; i < projCnt; i++){ if((status = attrCat->getInfo(projNames[i].relName, projNames[i].attrName, projDescs[i])) != OK){ return status; } } if(attr == NULL){//unconditonal selection }else if((status =attrCat-> getInfo(attr->relName, attr->attrName, attrDesc)) != OK){ return status; } //get output record length from attrdesc strucres int reclen = 0; for (int i = 0; i < projCnt; i++){ reclen += projDescs[i].attrLen; } if(attr == NULL){ if ((status = ScanSelect(result, projCnt, projDescs,NULL, op, NULL, reclen)) != OK){ return status; } }else{ switch(attrDesc.attrType){ case INTEGER: intval = atoi(attrValue); filter = (char *)&intval; break; case FLOAT: floatval = atof(attrValue); filter = (char *)&floatval; break; default: filter = attrValue; break; } if((status = ScanSelect(result, projCnt, projDescs, &attrDesc, op, filter, reclen)) != OK){ return status; } } delete [] projDescs; return OK; }
/* * Selects records from the specified relation using a * HeapFileScan. The project list is defined by * the parameters projCnt and projNames and is done on-the-fly. * <i>The search value is always supplied as the character string attrValue. * If attr is NULL, an unconditional scan of the input table should be performed.</i> * * @param result * @param projCnt * @param projNames[] * @param attr * @param op * @param attrValue * @return: OK on success * an error code otherwise */ const Status QU_Select(const string & result, const int projCnt, const attrInfo projNames[], const attrInfo *attr, const Operator op, const char *attrValue) { Status status; AttrDesc attrDesc; AttrDesc* projNamesDesc; int reclen; Operator myOp; const char* filter; reclen = 0; //an array of attrDesc to hold all the descriptions for the projection projNamesDesc = new AttrDesc[projCnt]; //tabulate the total length of the projection record for (int i = 0; i < projCnt; i++) { Status status = attrCat->getInfo(projNames[i].relName, projNames[i].attrName, projNamesDesc[i]); reclen += projNamesDesc[i].attrLen; if (status != OK) { return status; } } //implementation of select operation if (attr != NULL) { //SELECT ALL //get info for attr //e.g. attr op attrvalue status = attrCat->getInfo(string(attr->relName), string(attr->attrName), attrDesc); int tmpInt; float tmpFloat; //convert to proper data type switch (attr->attrType) { case INTEGER: tmpInt = atoi(attrValue); filter = (char*)&tmpInt; break; case FLOAT: tmpFloat = atof(attrValue); filter = (char*)&tmpFloat; break; case STRING: filter = attrValue; break; } myOp = op; //if null than there is no where clause //select all tuple for projection attributes } else { //default attrDesc for an unconditional scan strcpy(attrDesc.relName, projNames[0].relName); strcpy(attrDesc.attrName, projNames[0].attrName); attrDesc.attrOffset = 0; attrDesc.attrLen = 0; attrDesc.attrType = STRING; filter = NULL; myOp = EQ; } //now that the book keeping is done call ScanSelect to actually build the result table status = ScanSelect(result, projCnt, projNamesDesc, &attrDesc, myOp, filter, reclen); if (status != OK) { return status; } return OK; }