コード例 #1
0
t_rc SYSM_MetaManager::InsertRelationMetadata(char * relName, int recSize, int numOfAttributes, int numOfIndexes) {

	if (!this->sysm->isOpen) return (SYSM_NOTOPENEDDATABASE);

	t_rc rc;
	REM_RecordFileHandle rfh;
	RelMet relMeta;

	if (GetRelationMetadata(relName,relMeta) == OK) return (SYSM_RELATIONEXISTS);

	std::string relPath(this->sysm->path + this->sysm->openedDBName + "\\rel.met");

	rc = this->rfm->OpenRecordFile(relPath.c_str(), rfh);
	if (rc != OK) return rc;

	char * pData = new char[REL_SIZE];
	REM_RecordID rid;

	memcpy(&pData[REL_NAME_OFFSET],relName,REL_NAME_SIZE);
	memcpy(&pData[REL_REC_SIZE_OFFSET],&recSize,sizeof(int));
	memcpy(&pData[REL_ATTR_NUM_OFFSET],&numOfAttributes,sizeof(int));
	memcpy(&pData[REL_INX_NUM_OFFSET],&numOfIndexes,sizeof(int));
		
	rc = rfh.InsertRecord(pData,rid);
	if (rc != OK) return rc;
		
	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;

	return (OK);
}
コード例 #2
0
t_rc SYSM_MetaManager::InsertAttributeMetadata(char * relName, char * attrName, int attrOffset, t_attrType attrType, int attrLength, int indexNum) {

	if (!this->sysm->isOpen) return (SYSM_NOTOPENEDDATABASE);

	t_rc rc;
	REM_RecordID rid;
	REM_RecordFileHandle rfh;
	AttrMet attrMeta;
	std::string attrPath(this->sysm->path + this->sysm->openedDBName + "\\attr.met");

	if (GetAttributeMetadata(relName,attrName,attrMeta) == OK) return (SYSM_ATTRIBUTEEXISTS);

	rc = this->rfm->OpenRecordFile(attrPath.c_str(), rfh);
	if (rc != OK) return rc;
		
	char * pData = new char[ATTR_SIZE];

	memcpy(&pData[ATTR_REL_NAME_OFFSET],relName,REL_NAME_SIZE);
	memcpy(&pData[ATTR_NAME_OFFSET],attrName,ATTR_NAME_SIZE);
	memcpy(&pData[ATTR_OFFSET_OFFSET],&attrOffset,sizeof(int));
	memcpy(&pData[ATTR_TYPE_OFFSET],&attrType,sizeof(t_attrType));
	memcpy(&pData[ATTR_LENGTH_OFFSET],&attrLength,sizeof(int));
	memcpy(&pData[ATTR_INX_NO_OFFSET],&indexNum,sizeof(int));

	rc = rfh.InsertRecord(pData,rid);
	if (rc != OK) return rc;

	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;
		
	return (OK);

}
コード例 #3
0
ファイル: SSQLM.cpp プロジェクト: Ctsavas/My_Projects
//Εκτελει την εντολη delete from where του DML
t_rc SSQLM::runDelete(string tableName, queue<std::string> comp)
{
	t_rc rc;
	string path = "data/";
	path.append(sysm->getCurdbName());
	path.append("/");
	path.append(tableName);
	queue<REM_RecordID> ridQ;

	//Βαλε στο ridQ ολα τα records που ικανοποιουν τις συνθηκες comp
	rc = executeWhere(tableName, comp, ridQ);
	if(rc!=OK) return rc;
	STORM_StorageManager *sm = new STORM_StorageManager();
	REM_RecordFileManager rm = REM_RecordFileManager(sm);
	REM_RecordFileHandle rfh;
	rc = rm.OpenRecordFile(path.c_str(),rfh);
	if(rc != OK) return rc;
	int destinationSize = ridQ.size();
	//Για καθε rid της ουρας που ικανοποιει τις συνθηκες
	for(int i=0;i<destinationSize;i++)
	{
		//Διαγραψε το
		rc = rfh.DeleteRecord(ridQ.front());
		if(rc!=OK) return rc;
		ridQ.pop();
	}
	rm.CloseRecordFile(rfh);
	return OK;
}
コード例 #4
0
t_rc SSQLM_DML_Manager::Update(const char *tName, vector<REM_RecordID> ridsFromWhere, char *setAttribute){

	STORM_StorageManager *stormgr = new STORM_StorageManager();				
	REM_RecordFileManager *remrfm = new REM_RecordFileManager(stormgr);	
	REM_RecordFileHandle *remrfh = new REM_RecordFileHandle();	
	REM_RecordHandle remrh;
	char pathname[50];
	char *pData;
	int offset,size,indexID;
	char *type;
	char *nextToken;

	int setAttrLength = strlen(setAttribute);
	char *setAttributeCondition = (char*)malloc(setAttrLength);
	strcpy(setAttributeCondition,setAttribute);

	char *setAttributeKey;
	char *setValue;
	setAttributeKey = strtok_s(setAttributeCondition,"= ", &nextToken);
	setValue = strtok_s(NULL,"= ", &nextToken);

	t_rc rc = FindAttributeInAttrmet(tName,setAttributeKey,offset,type,size,indexID);
	if (rc != OK) { return rc; }

	_snprintf_s(pathname,sizeof(pathname),"%s/%s",dbName,tName);
	rc = remrfm->OpenRecordFile(pathname,*remrfh);
	if (rc != OK) { return rc; }

	for(int i = 0; i < (int)ridsFromWhere.size(); i++){

		rc = remrfh->ReadRecord(ridsFromWhere[i],remrh);
		if (rc != OK) { return rc; }

		rc = remrh.GetData(pData);
		if (rc != OK) { return rc; }

		for(int j = 0; j < size; j++){
			pData[j+offset] = setValue[j];
		}

		rc = remrfh->UpdateRecord(remrh);
		if (rc != OK) { return rc; }

		rc = remrfh->FlushPages();
		if (rc != OK) { return rc; }
	}

	rc = remrfm->CloseRecordFile(*remrfh);
	if (rc != OK) { return rc; }

	delete remrfh;
	delete remrfm;
	delete stormgr;

	return OK;
}
コード例 #5
0
t_rc SYSM_UserManager::DeleteUser(char * username, char * password) {
	t_rc rc;

	if (!this->isLoggedIn) return (SYSM_NOTLOGGEDIN);
	if (this->CheckPrivilege("all") != OK) return (SYSM_NOTALLOWEDUSER);

	std::string t_path(this->path);
	t_path.append("users");

	AttrMet u_meta;
	rc = this->smm->GetAttributeMetadata("users", "username", u_meta);
	if (rc != OK) return rc;

	AttrMet p_meta;
	rc = this->smm->GetAttributeMetadata("users", "password", p_meta);
	if (rc != OK) return rc;

	REM_RecordFileHandle rfh;
	rc = this->rfm->OpenRecordFile((char *) t_path.c_str(),rfh);
	if (rc != OK) return rc;

	REM_RecordFileScan rfs;
	rc = rfs.OpenRecordScan(rfh,u_meta.type,u_meta.length,u_meta.offset,EQ_OP,username);
	if (rc != OK) return rc;

	REM_RecordHandle rh;
	while ((rc = rfs.GetNextRecord(rh)) == OK) {
		char * pData;
		rc = rh.GetData(pData);
		if (rc != OK) return rc;

		char * aData = new char[p_meta.length];
		memcpy(aData,&pData[p_meta.offset],p_meta.length);

		if (strcmp(aData,password) == 0) {
			REM_RecordID rid;
			rc = rh.GetRecordID(rid);
			if (rc != OK) return rc;

			rc = rfh.DeleteRecord(rid);
			if (rc != OK) return rc;
		}
	}

	rc = rfs.CloseRecordScan();
	if (rc != OK) return rc;

	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;

	rc = this->RemoveAllPrivileges(username);
	if (rc != OK) return rc;

	return (OK);
}
コード例 #6
0
t_rc SYSM_UserManager::InsertUser(char * username, char * password) {
	t_rc rc;

	if (!this->isLoggedIn) return (SYSM_NOTLOGGEDIN);
	if (this->CheckPrivilege("all") != OK) return (SYSM_NOTALLOWEDUSER);

	std::string t_path(this->path);
	t_path.append("users");

	AttrMet u_meta;
	rc = this->smm->GetAttributeMetadata("users", "username", u_meta);
	if (rc != OK) return rc;

	AttrMet p_meta;
	rc = this->smm->GetAttributeMetadata("users", "password", p_meta);
	if (rc != OK) return rc;

	REM_RecordFileHandle rfh;
	rc = this->rfm->OpenRecordFile((char *) t_path.c_str(),rfh);
	if (rc != OK) return rc;

	REM_RecordFileScan rfs;
	rc = rfs.OpenRecordScan(rfh,u_meta.type,u_meta.length,u_meta.offset,EQ_OP,username);
	if (rc != OK) return rc;

	REM_RecordHandle rh;
	if (rfs.GetNextRecord(rh) == OK) return (SYSM_USEREXISTS);
	
	RelMet r_meta;
	rc = this->smm->GetRelationMetadata("users",r_meta);
	if (rc != OK) return rc;

	rc = rfs.CloseRecordScan();
	if (rc != OK) return rc;

	char * pData = new char[r_meta.rs];
	memcpy(&pData[u_meta.offset],username,u_meta.length);
	memcpy(&pData[p_meta.offset],password,p_meta.length);

	REM_RecordID rid;
	rc = rfh.InsertRecord(pData,rid);
	if (rc != OK) return rc;

	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;

	return (OK);
}
コード例 #7
0
t_rc REM_RecordFileManager::CloseRecordFile(REM_RecordFileHandle &rfh)
{
	t_rc rc;
	//Flashing Pages before closing 
	rc = rfh.FlushPages();
	if(rc!=OK){DisplayReturnCode(rc); exit(-1);}
	//Closing the open file
	rc = a_storage_manager->CloseFile(*a_file_handle);
	if(rc!=OK){DisplayReturnCode(rc); exit(-1);}
	return rc= (OK);
}
コード例 #8
0
t_rc SYSM_UserManager::RemoveAllPrivileges (char * username) {
	t_rc rc;

	if (!this->isLoggedIn) return (SYSM_NOTLOGGEDIN);
	if (this->CheckPrivilege("all") != OK) return (SYSM_NOTALLOWEDUSER);

	std::string t_path(this->path);
	t_path.append("privileges");

	AttrMet u_meta;
	rc = this->smm->GetAttributeMetadata("privileges", "username", u_meta);
	if (rc != OK) return rc;

	REM_RecordFileHandle rfh;
	rc = this->rfm->OpenRecordFile((char *) t_path.c_str(),rfh);
	if (rc != OK) return rc;

	REM_RecordFileScan rfs;
	rc = rfs.OpenRecordScan(rfh,u_meta.type,u_meta.length,u_meta.offset,EQ_OP,username);
	if (rc != OK) return rc;

	REM_RecordHandle rh;
	while ((rc = rfs.GetNextRecord(rh)) == OK) {
		
		REM_RecordID rid;
		rc = rh.GetRecordID(rid);
		if (rc != OK) return rc;

		rc = rfh.DeleteRecord(rid);
		if (rc != OK) return rc;
	}

	rc = rfs.CloseRecordScan();
	if (rc != OK) return rc;

	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;

	return (OK);
}
コード例 #9
0
//Insert command
t_rc SSQLM_Manager::Insert(const char *tableName, t_relInfo relInfo, vector<t_attrInfo> attrInfo, vector<char *> values) {
	t_rc rc;
	REM_RecordFileHandle rfh;

	rc = rfm.OpenRecordFile(tableName, rfh);
	if(rc != OK)
		return rc;

	char *record;
	rc = GetRecord(attrInfo, relInfo, values, record);
	if(rc != OK)
		return rc;

	REM_RecordID rid;
	rc = rfh.InsertRecord(record, rid);
	if(rc != OK)
		return rc;

	rc = rfm.CloseRecordFile(rfh);
	if(rc != OK)
		return rc;

	return OK;
}
コード例 #10
0
//Insert the exact field of each record into the indexing
t_rc SSQLM_Manager::InsertIndexEntries(REM_RecordFileHandle &rfh, int attrOffset/*, INXM_IndexHandle ih*/) {
	t_rc rc;
	int numReservedPages = rfh.sfh.GetNumReservedPages();
	int numberofSlots = rfh.rfsh.nrecords;

	REM_RecordID rid;
	REM_RecordHandle rh;
	int slot = 0;
	int pageID = 2;
	char *data;

	if(numReservedPages < 2)
		return SSQLM_NOENTRYTOINDEX;

	if(numberofSlots == 0)
		return SSQLM_NOENTRYTOINDEX;

	for( ; pageID <= numReservedPages; pageID++) {
		for( ; slot <= rfh.rfsh.recordsPerPage; slot++) {
			if(slot >(rfh.rfsh.nrecords - 1))
				return OK;

			rc = rid.SetPageID(pageID);
			if(rc != OK)
				return rc;

			rc = rid.SetSlot(slot);
			if(rc != OK)
				return rc;

			rc = rfh.ReadRecord(rid, rh);
			if(rc != OK)
				return rc;

			rc = rh.GetData(data);
			if(rc != OK)
				return rc;

			/*rc = ih.InsertEntry(data[attrOffset], rid);
			if(rc != OK)
				return rc;
*/
		}
	}
}
コード例 #11
0
ファイル: main.cpp プロジェクト: csdashes/DB-Implementation
void testREM() {
	STORM_StorageManager mgr;
	STORM_FileHandle fh;
	t_rc rc;
	STORM_PageHandle ph;

	
	
	
	REM_RecordFileManager *rmgr = new REM_RecordFileManager(&mgr);
	
	REM_RecordFileHandle rfh;
	
	rc = rmgr->CreateRecordFile("test.dat", 40);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rc = rmgr->OpenRecordFile("test.dat", rfh);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	REM_RecordID rid1, rid2, rid3;
	int pageID, slot;
	
	//================================================================================	
	rc = rfh.InsertRecord("check my list yo", rid1);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rc = rid1.GetPageID(pageID);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rc = rid1.GetSlot(slot);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	printf("Page ID = %d,  Slot = %d\n", pageID, slot);
	
	rc = rfh.InsertRecord("check my list yo 2", rid2);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
		
	rc = rid2.GetPageID(pageID);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rc = rid2.GetSlot(slot);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	printf("Page ID = %d,  Slot = %d\n", pageID, slot);

	rc = rfh.InsertRecord("check my list yo 3", rid3);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
		
	rc = rid3.GetPageID(pageID);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rc = rid3.GetSlot(slot);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	printf("Page ID = %d,  Slot = %d\n", pageID, slot);
	//================================================================================	
	//================================================================================	
	REM_RecordHandle rh;
	char *pData;
	
	rc = rfh.ReadRecord(rid1, rh);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rh.GetData(pData);
	printf("This is data : %s ||| from rid %d\n", pData, 1);

	rc = rfh.ReadRecord(rid2, rh);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rh.GetData(pData);
	printf("This is data : %s ||| from rid %d\n", pData, 2);

	rc = rfh.ReadRecord(rid3, rh);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rh.GetData(pData);
	printf("This is data : %s ||| from rid %d\n", pData, 3);	
	
	//================================================================================	
	//================================================================================	
	
	REM_RecordFileScan fs;
	
	
	rc = fs.OpenRecordScan(rfh, TYPE_STRING, 18, 0, EQ_OP, (char*)"check my list yo 2");
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rc = fs.GetNextRecord(rh);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rh.GetData(pData);
	printf("This is data : %s ||| from File Scan \n", pData);
	
	rc = fs.GetNextRecord(rh);
	if (rc != OK) {DisplayReturnCode(rc);}

	rh.GetData(pData);
	printf("This is data : %s ||| from File Scan 2\n", pData);

	
	//================================================================================	
	//================================================================================	
	
	rfh.DeleteRecord(rid1);
	
	rc = rfh.ReadRecord(rid1, rh);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rh.GetData(pData);
	printf("This is data : %s ||| from rid %d\n", pData, 1);
	//================================================================================	
	//================================================================================	
	memcpy(pData, "koka kolas!", 40);
	
	rfh.UpdateRecord(rh);
	
	rc = rfh.ReadRecord(rid1, rh);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rh.GetData(pData);
	printf("This is data : %s ||| from rid %d\n", pData, 1);	
	//================================================================================	
	
	rc = rmgr->CloseRecordFile(rfh);
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
	rc = rmgr->DestroyRecordFile("test.dat");
	if (rc != OK) {DisplayReturnCode(rc);exit(-1);}	
	
}
コード例 #12
0
t_rc SYSM_UserManager::AddPrivilege (char * username, char * dbname) {
	t_rc rc;

	if (!this->isLoggedIn) return (SYSM_NOTLOGGEDIN);
	if (this->CheckPrivilege("all") != OK) return (SYSM_NOTALLOWEDUSER);

	std::string t_path(this->path);
	t_path.append("privileges");

	AttrMet u_meta;
	rc = this->smm->GetAttributeMetadata("privileges", "username", u_meta);
	if (rc != OK) return rc;

	AttrMet db_meta;
	rc = this->smm->GetAttributeMetadata("privileges", "dbname", db_meta);
	if (rc != OK) return rc;

	REM_RecordFileHandle rfh;
	rc = this->rfm->OpenRecordFile((char *) t_path.c_str(),rfh);
	if (rc != OK) return rc;

	REM_RecordFileScan rfs;
	rc = rfs.OpenRecordScan(rfh,u_meta.type,u_meta.length,u_meta.offset,EQ_OP,username);
	if (rc != OK) return rc;

	REM_RecordHandle rh;
	while ((rc = rfs.GetNextRecord(rh)) == OK) {
		
		if (strcmp(dbname,"grand") == 0) {
			REM_RecordID rid;
			rc = rh.GetRecordID(rid);
			if (rc != OK) return rc;

			rc = rfh.DeleteRecord(rid);
			if (rc != OK) return rc;

		} else {
			char * pData;
			rc = rh.GetData(pData);
			if (rc != OK) return rc;

			char * aData = new char[db_meta.length];
			memcpy(aData,&pData[db_meta.offset],db_meta.length);

			if (strcmp(aData,dbname) == 0) return (SYSM_PRIVEXISTS);
		}
	}
	
	RelMet r_meta;
	rc = this->smm->GetRelationMetadata("privileges",r_meta);
	if (rc != OK) return rc;

	rc = rfs.CloseRecordScan();
	if (rc != OK) return rc;

	char * pData = new char[r_meta.rs];
	memcpy(&pData[u_meta.offset],username,u_meta.length);
	memcpy(&pData[db_meta.offset],dbname,db_meta.length);

	REM_RecordID rid;
	rc = rfh.InsertRecord(pData,rid);
	if (rc != OK) return rc;

	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;

	return (OK);
}
コード例 #13
0
t_rc SSQLM_DML_Manager::Delete(const char *tName, REM_RecordID ridsToDelete, char *recordsToDelete){

	STORM_StorageManager *stormgr = new STORM_StorageManager();				
	REM_RecordFileManager *remrfm = new REM_RecordFileManager(stormgr);		
	REM_RecordFileHandle *remrfh = new REM_RecordFileHandle();					
//	char *data;
	char pathname[50];

	_snprintf_s(pathname,sizeof(pathname),"%s/%s",dbName,tName);
	t_rc rc = remrfm->OpenRecordFile(pathname,*remrfh);
	if (rc != OK) { return rc; }

	//for(int i = 0; i < ridsToDelete.size(); i++){

		rc = remrfh->DeleteRecord(ridsToDelete);
		if (rc != OK) { return rc; }
	//}

	rc = remrfh->FlushPages();
	if (rc != OK) { return rc; }

	bool hasIndexes;

	rc = CheckIfTableHasIndexes(tName,hasIndexes);
	if (rc != OK) { return rc; }

	if(hasIndexes){

		REM_RecordFileScan *rfs = new REM_RecordFileScan();
		int tNameLength = strlen(tName);
		REM_RecordHandle rh;

		rc = rfs->OpenRecordScan(*attrmet,TYPE_STRING,tNameLength, 0, EQ_OP, (char*)tName);
		if (rc != OK) {return rc; }

		int offset = 0;
		int size = 0;
		char *type;
		int indexNo = 0;
		while( rfs->GetNextRecord(rh) != REM_FSEOF ){
		
			char *pp;
			rh.GetData(pp);

			//Get the index id, offset, type and size of the attribute
			rc = GetAttrInfo(pp,offset,type,size,indexNo);

			//if there is index for this attribute
			if( indexNo != -1 ){

				// Retrieve the index entry from the attribute data
				INXM_IndexHandle ih;
				REM_RecordID rid;
				_snprintf_s(pathname,sizeof(pathname),"%s/%s",dbName,tName);

				rc = im->OpenIndex(pathname,indexNo,ih);
				if (rc != OK) { return rc; }

				char *indexEntry;
				indexEntry = (char*)malloc(size);

				int j;
				for( j=0; j<size; j++){
					indexEntry[j] = recordsToDelete[j+offset];
				}
				indexEntry[j] = '\0';
			
				// Delete the entry from the index file with id = indexNo
				if(strcmp(type,"TYPE_INT") == 0){
					int coca = atoi(indexEntry);
					int *key = new int(coca);

					rc = ih.DeleteEntry( key, rid );
					if (rc != OK) { return rc; }
				}
				else{
					rc = ih.DeleteEntry( indexEntry, rid);
					if (rc != OK) { return rc; }
				}

				rc = im->CloseIndex(ih);
				if (rc != OK) { return rc; }

			}
		}
		rc = rfs->CloseRecordScan();
	}

	return OK;
}
コード例 #14
0
t_rc SYSM_MetaManager::DeleteAttributeMetadata(char * relName, char * attrName) {

	if (!this->sysm->isOpen) return (SYSM_NOTOPENEDDATABASE);

	t_rc rc;
	REM_RecordFileHandle rfh;
	std::string attrPath(this->sysm->path + this->sysm->openedDBName + "\\attr.met");

	rc = this->rfm->OpenRecordFile(attrPath.c_str(), rfh);
	if (rc != OK) return rc;

	REM_RecordFileScan rfs;
	rc = rfs.OpenRecordScan(rfh,TYPE_STRING,ATTR_NAME_SIZE,ATTR_NAME_OFFSET,EQ_OP,attrName);
	if (rc != OK) {
		rc = this->rfm->CloseRecordFile(rfh);
		if (rc != OK) return rc;

		return (SYSM_ATTRIBUTEDOESNOTEXISTS);
	}

	bool done = false;
	REM_RecordHandle rh;
	while (rfs.GetNextRecord(rh) == OK) {
		
		REM_RecordFileScan temp_rfs;
		rc = temp_rfs.OpenRecordScan(rfh,TYPE_STRING,REL_NAME_SIZE,ATTR_REL_NAME_OFFSET,EQ_OP,relName);
		if (rc != OK) return rc;

		REM_RecordHandle temp_rh;
		while (temp_rfs.GetNextRecord(temp_rh) == OK) {
			
			REM_RecordID rid, temp_rid;
			rc = rh.GetRecordID(rid);
			if (rc != OK) return rc;

			rc = temp_rh.GetRecordID(temp_rid);
			if (rc != OK) return rc;

			int pageID, temp_pageID;
			rc = rid.GetPageID(pageID);
			if (rc != OK) return rc;

			rc = temp_rid.GetPageID(temp_pageID);
			if (rc != OK) return rc;

			int slot, temp_slot;
			rc = rid.GetSlot(slot);
			if (rc != OK) return rc;

			rc = temp_rid.GetSlot(temp_slot);
			if (rc != OK) return rc;

			if ((pageID == temp_pageID) && (slot == temp_slot)) {
				rc = rfh.DeleteRecord(rid);
				if (rc != OK) return rc;

				done = true;
				break;
			}
		}

		rc = temp_rfs.CloseRecordScan();
		if (rc != OK) return rc;

		if (done) break;
	}

	rc = rfs.CloseRecordScan();
	if (rc != OK) return rc;

	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;

	if (!done) return (SYSM_ATTRIBUTEDOESNOTEXISTS);
	return (OK);
}
コード例 #15
0
ファイル: SSQLM.cpp プロジェクト: Ctsavas/My_Projects
//Εκτελει την εντολη update tableName where του DML
t_rc SSQLM::runUpdate(string tableName, string attrName, string VALUE, queue<std::string> comp)
{
	t_rc rc;
	struct relAttr RAttr;

	//παρε τη στηλη που δωθηκε στα ορισματα
	getAttr((char*)tableName.c_str(), (char*)attrName.c_str(), RAttr);
	queue<REM_RecordID> ridQ;

	//Ενημερωσε την ουρα με τα rids που ικανοποιουν τις συνθηκες
	rc = executeWhere(tableName, comp, ridQ);
	if(rc!=OK) return rc;
	int sizeToRun = ridQ.size();
	REM_RecordHandle rh;
	relMet relm;
	SSQLM::getTable(tableName.c_str(),relm);
	STORM_StorageManager *sm = new STORM_StorageManager();
	REM_RecordFileManager rm(sm);
	REM_RecordFileHandle rfh;
	string path="data/";
	path.append(sysm->getCurdbName());
	path.append("/");
	path.append(tableName);
	rc = rm.OpenRecordFile(path.c_str(), rfh);
	if(rc!=OK) return rc;

	//Για καθε rid στην ουρα, ικανοποιει τις συνθηκες
	for(int i=0; i<sizeToRun; i++)
	{
		//Παρε τα δεδομενα του, επεξεργασου τα καταλληλα και αντικαταστησε την εγγραφη με μια καινουργια
		rc = rfh.ReadRecord(ridQ.front(),rh);
		if(rc!=OK) return rc;
		
		char* data;
		rc = rh.GetData(data);
		if(rc!=OK) return rc;
		char* toadd = new char[relm.record_Length];
		memcpy(toadd, data, relm.record_Length);
		if(RAttr.type == TYPE_INT)
		{
			int thechar = atoi(VALUE.c_str());
			memcpy(toadd + RAttr.offset,&thechar,RAttr.attr_Length);
		}
		else if(RAttr.type == TYPE_STRING)
		{
			char* thechar = (char*) VALUE.c_str();
			memcpy(toadd + RAttr.offset,thechar,RAttr.attr_Length);
		}
		REM_RecordID uselessRid; //Δε με ενδιαφερει να ξερω το rid του εισαχθεν record
		
		rc = rfh.InsertRecord(toadd, uselessRid);
		if(rc!=OK) return rc;

		rc = rfh.DeleteRecord(ridQ.front());
		if(rc!=OK) return rc;
		
		ridQ.pop();
	}
	rc = rm.CloseRecordFile(rfh);
	return rc;
}
コード例 #16
0
ファイル: SSQLM.cpp プロジェクト: Ctsavas/My_Projects
//Εκτελει την εντολη insert into tableName του DML
t_rc SSQLM::runInsert(char name[30], char values[30][256]){

	std::string path = "data/";
	char* curDbName = sysm->getCurdbName();
	path += curDbName;
	path = path + "/" + name;
	struct stat st; //για να δούμε εάν υπάρχει ο πίνακας ή όχι
	if(stat(path.c_str(),&st) != 0) //εάν δεν υπάρχει ο πίνακας
		return SSQLM_TABLE_DOESNT_EXIST;

	//υπάρχει  ο πίνακας ας γίνει η εισαγωγή.
	
	//πρέπει να πάρω τις πληροφορίες για τις δομές rel.met και attr.met
	
	REM_RecordFileScan rfs;
	t_rc rc = rfs.OpenRecordScan(sysm->relMet,TYPE_STRING,30,0,EQ_OP,name);
	if(rc!=OK) return rc;
	REM_RecordHandle rh;
	rc = rfs.GetNextRecord(rh); //αρκεί μία φορά....
	if(rc!=OK) return rc;
	relMet relRec;
	char *data = new char[sizeof(relMet)];
	rc = rh.GetData(data);
	if(rc!=OK) return rc;
	memcpy(&relRec,data,sizeof(relMet));
	
	rc = rfs.CloseRecordScan();
	if(rc!=OK) return rc;

	int recordLength = relRec.record_Length;
	int attrCount = relRec.num_Columns;
	
	/*
		
		Σε περίπτωση που γεμίσουν οι σελίδες δεν ξανα μπαίνουν τα δεδομένα από την πρώτη σελίδα
		και πέρα εγγράφοντας ό,τι δεδομένα υπήρχαν προηγουμένως(ακόμα και αυτά που δεν έχουν
		διαγραφεί). Οι εγγραφές για τα attributes μπαίνουν σειριακά στο attr.met. Δηλαδή
		το δεύτερο attribute δεν μπορεί να βρίσκεται σε recordID που είναι μικρότερο(πιο αριστερά)
		από το recordID του πρώτου attribute.

	*/

	rc = rfs.OpenRecordScan(sysm->attrMet,TYPE_STRING,30,0,EQ_OP,name);
	if(rc!=OK) return rc;
	int i;
	char *recordData = new char[recordLength]; //εδώ θα μπουν τα δεδομένα του record
	for(i=0;i<attrCount;i++){
		
		SYSM::relAttrStr attrRec;
		rc = rfs.GetNextRecord(rh); //αρκεί μία φορά....
		if(rc!=OK) return rc;
		char *data;
		rc = rh.GetData(data);
		if(rc!=OK) return rc;
		memcpy(&attrRec,data,sizeof(attrRec));
		//πήραμε το struct για το (i+1)-oστό attribute
		if(attrRec.type == TYPE_STRING)
			memcpy(recordData + attrRec.offset, values[i], attrRec.attr_Length);
		else if(attrRec.type == TYPE_INT){
			int intData = atoi(values[i]);
			memcpy(recordData + attrRec.offset, &intData, attrRec.attr_Length);
		}
		//ενημερώσαμε το recordData.
	}
	rc = rfs.CloseRecordScan();
	if(rc!=OK) return rc;

	//έχουμε το recordData, ας το εισάγουμε.

	STORM_StorageManager *sm = new STORM_StorageManager();
	REM_RecordFileManager rfm(sm);
	REM_RecordFileHandle rfh;
	REM_RecordID rid;

    rc = rfm.OpenRecordFile(path.c_str(),rfh);
	if(rc!=OK) return rc;

	rc = rfh.InsertRecord(recordData,rid);
	if(rc!=OK) return rc;

	rc = rfm.CloseRecordFile(rfh);
	if(rc!=OK) return rc;
	delete[] recordData;
	return OK;
}
コード例 #17
0
t_rc SSQLM_DML_Manager::Insert(const char *tName,const char *record){
	
	char pathname[50];												//	Gia na eisagoume ena record ston pinaka
	REM_RecordFileHandle *rfh = new REM_RecordFileHandle();			//	anoigoume to arxeio tou pinaka,
	REM_RecordID rid;												//	kanoume thn eisagwgh, kai epeita prepei na
																	//	elegksoume ean yparxoun indexes tous opoious
																	//	prepei na enhmerwsoume.
	// Open the table file
	_snprintf_s(pathname,sizeof(pathname),"%s/%s",dbName,tName);
	t_rc rc = rfm->OpenRecordFile(pathname,*rfh);
	if (rc != OK) { return rc; }

	// Insert the new record							
	rc = rfh->InsertRecord(record,rid);								//	8a xrhsimopoihsoume auto to rid gia na kanoume
	if (rc != OK) { return rc; }									//	thn eisagwgh stous indexers (ean yparxoun)

	// Close the table file
	rc = rfm->CloseRecordFile(*rfh);
	if (rc != OK) { return rc; }

	// CHECK IF THERE ARE INDEXES									//	Gia na elegksoume ean yparxoun indexes,
	bool has_indexes;

	rc = CheckIfTableHasIndexes(tName,has_indexes);
	if (rc != OK) { return rc; }

	// In case the number of indexes is different than 0, we have to insert entry in every index file
	// First we find the ids of the index files by looking into the attr.met file
	if( has_indexes ){

		REM_RecordFileScan *rfs = new REM_RecordFileScan();
		int tNameLength = strlen(tName);
		REM_RecordHandle rh;

		rc = rfs->OpenRecordScan(*attrmet,TYPE_STRING,tNameLength, 0, EQ_OP, (char*)tName);
		if (rc != OK) {return rc; }

		int offset = 0;
		int size = 0;
		char *type;
		int indexNo = 0;
		while( rfs->GetNextRecord(rh) != REM_FSEOF ){
		
			char*pp;
			rh.GetData(pp);

			//Get the index id, offset, type and size of the attribute
			rc = GetAttrInfo(pp,offset,type,size,indexNo);

			//if there is index for this attribute
			if( indexNo != -1 ){

				// Retrieve the index entry from the attribute data
				INXM_IndexHandle ih;
				_snprintf_s(pathname,sizeof(pathname),"%s/%s",dbName,tName);

				char *indexEntry;
				indexEntry = (char*)malloc(size);

				int j;
				for( j=0; j<size; j++){
					indexEntry[j] = record[j+offset];
				}
				indexEntry[j] = '\0';
				rc = im->OpenIndex(pathname,indexNo,ih);
				if (rc != OK) { return rc; }
			
				// Insert the entry into index file with id = indexNo
				if(strcmp(type,"TYPE_INT") == 0){
					int coca = atoi(indexEntry);
					int *key = new int(coca);

					rc = ih.InsertEntry( key, rid);
					if (rc != OK) { return rc; }
				}
				else{
					rc = ih.InsertEntry( indexEntry, rid);
					if (rc != OK) { return rc; }
				}

				rc = im->CloseIndex(ih);
				if (rc != OK) { return rc; }

			}
		}
		rc = rfs->CloseRecordScan();
	}	
	return OK;
}
コード例 #18
0
t_rc SYSM_MetaManager::DeleteRelationMetadata(char * rel_Name) {

	if (!this->sysm->isOpen) return (SYSM_NOTOPENEDDATABASE);

	t_rc rc;
	REM_RecordFileHandle rfh;
	std::string relPath(this->sysm->path + this->sysm->openedDBName + "\\rel.met");

	rc = this->rfm->OpenRecordFile(relPath.c_str(), rfh);
	if (rc != OK) return rc;

	REM_RecordFileScan rfs;
	rc = rfs.OpenRecordScan(rfh,TYPE_STRING,REL_NAME_SIZE,REL_NAME_OFFSET,EQ_OP,rel_Name);
	if (rc != OK) {
		rc = this->rfm->CloseRecordFile(rfh);
		if (rc != OK) return rc;
		
		return (SYSM_RELATIONDOESNOTEXISTS);
	}

	REM_RecordHandle rh;
	if (rfs.GetNextRecord(rh) != OK) return (SYSM_RELATIONDOESNOTEXISTS);

	REM_RecordID rid;
	rc = rh.GetRecordID(rid);
	if (rc != OK) return rc;

	rc = rfh.DeleteRecord(rid);
	if (rc != OK) return rc;

	rc = rfs.CloseRecordScan();
	if (rc != OK) return rc;

	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;

	std::string attrPath(this->sysm->path + this->sysm->openedDBName + "\\attr.met");
	rc = this->rfm->OpenRecordFile(attrPath.c_str(),rfh);
	if (rc != OK) return rc;

	rc = rfs.OpenRecordScan(rfh,TYPE_STRING,REL_NAME_SIZE,ATTR_REL_NAME_OFFSET,EQ_OP,rel_Name);
	if (rc != OK) {
		rc = this->rfm->CloseRecordFile(rfh);
		if (rc != OK) return rc;
		
		return (OK);
	}

	while (rfs.GetNextRecord(rh) == OK) {
		rc = rh.GetRecordID(rid);
		if (rc != OK) return rc;

		rc = rfh.DeleteRecord(rid);
		if (rc != OK) return rc;
	}

	rc = rfs.CloseRecordScan();
	if (rc != OK) return rc;

	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;

	return (OK);
}
コード例 #19
0
t_rc SYSM_MetaManager::UpdateRelationMetadata(char * p_Rel_Name, char * n_Rel_Name, int n_Rec_Size, int n_Num_Of_Attributes, int numOfIndexes) {

	if (!this->sysm->isOpen) return (SYSM_NOTOPENEDDATABASE);

	t_rc rc;
	REM_RecordFileHandle rfh;
	std::string relPath(this->sysm->path + this->sysm->openedDBName + "\\rel.met");

	rc = this->rfm->OpenRecordFile(relPath.c_str(), rfh);
	if (rc != OK) {
		rc = this->rfm->CloseRecordFile(rfh);
		if (rc != OK) return rc;
		
		return (SYSM_RELATIONDOESNOTEXISTS);
	}

	REM_RecordFileScan rfs;
	rc = rfs.OpenRecordScan(rfh,TYPE_STRING,REL_NAME_SIZE,REL_NAME_OFFSET,EQ_OP,p_Rel_Name);
	if (rc != OK) return rc;

	REM_RecordHandle rh;
	if (rfs.GetNextRecord(rh) != OK) return (SYSM_RELATIONDOESNOTEXISTS);
	
	char * pData;
	REM_RecordID rid;

	rc = rh.GetData(pData);
	if (rc != OK) return rc;

	memcpy(&pData[REL_NAME_OFFSET],n_Rel_Name,REL_NAME_SIZE);
	memcpy(&pData[REL_REC_SIZE_OFFSET],&n_Rec_Size,sizeof(int));
	memcpy(&pData[REL_ATTR_NUM_OFFSET],&n_Num_Of_Attributes,sizeof(int));
	memcpy(&pData[REL_INX_NUM_OFFSET],&numOfIndexes,sizeof(int));

	rc = rfh.UpdateRecord(rh);
	if (rc != OK) return rc;

	rc = rfs.CloseRecordScan();
	if (rc != OK) return rc;

	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;

	if (strcmp(p_Rel_Name,n_Rel_Name) != 0) {
		std::string attrPath(this->sysm->path + this->sysm->openedDBName + "\\attr.met");
		rc = this->rfm->OpenRecordFile(attrPath.c_str(),rfh);
		if (rc != OK) return rc;

		rfs.OpenRecordScan(rfh,TYPE_STRING,REL_NAME_SIZE,ATTR_REL_NAME_OFFSET,EQ_OP,p_Rel_Name);
		if (rc != OK) {
			rc = this->rfm->CloseRecordFile(rfh);
			if (rc != OK) return rc;

			return (OK);
		}

		while (rfs.GetNextRecord(rh) == OK) {
			char * pData;
			rc = rh.GetData(pData);
			if (rc != OK) return rc;

			memcpy(&pData[ATTR_REL_NAME_OFFSET],n_Rel_Name,REL_NAME_SIZE);

			rc = rfh.UpdateRecord(rh);
			if (rc != OK) return rc;
		}

		rc = rfs.CloseRecordScan();
		if (rc != OK) return rc;

		rc = this->rfm->CloseRecordFile(rfh);
		if (rc != OK) return rc;
	}

	return (OK);
}
コード例 #20
0
t_rc SYSM_MetaManager::UpdateAttributeMetadata(char * p_RelName, char * p_AttrName, 
	char * n_RelName, char * n_AttrName, int n_AttrOffset, t_attrType n_AttrType, int n_AttrLength, int indexNum) {

	if (!this->sysm->isOpen) return (SYSM_NOTOPENEDDATABASE);

	t_rc rc;
	REM_RecordFileHandle rfh;
	std::string attrPath(this->sysm->path + this->sysm->openedDBName + "\\attr.met");

	rc = this->rfm->OpenRecordFile(attrPath.c_str(), rfh);
	if (rc != OK) return rc;

	REM_RecordFileScan rfs;
	rc = rfs.OpenRecordScan(rfh,TYPE_STRING,ATTR_NAME_SIZE,ATTR_NAME_OFFSET,EQ_OP,p_AttrName);
	if (rc != OK) {
		rc = this->rfm->CloseRecordFile(rfh);
		if (rc != OK) return rc;
		
		return (SYSM_ATTRIBUTEDOESNOTEXISTS);
	}

	bool done = false;
	REM_RecordHandle rh;
	while (rfs.GetNextRecord(rh) == OK) {
		
		REM_RecordFileScan temp_rfs;
		rc = temp_rfs.OpenRecordScan(rfh,TYPE_STRING,REL_NAME_SIZE,ATTR_REL_NAME_OFFSET,EQ_OP,p_RelName);
		if (rc != OK) return rc;

		REM_RecordHandle temp_rh;
		while (temp_rfs.GetNextRecord(temp_rh) == OK) {
			
			REM_RecordID rid, temp_rid;
			rc = rh.GetRecordID(rid);
			if (rc != OK) return rc;

			rc = temp_rh.GetRecordID(temp_rid);
			if (rc != OK) return rc;

			int pageID, temp_pageID;
			rc = rid.GetPageID(pageID);
			if (rc != OK) return rc;

			rc = temp_rid.GetPageID(temp_pageID);
			if (rc != OK) return rc;

			int slot, temp_slot;
			rc = rid.GetSlot(slot);
			if (rc != OK) return rc;

			rc = temp_rid.GetSlot(temp_slot);
			if (rc != OK) return rc;

			if ((pageID == temp_pageID) && (slot == temp_slot)) {
				char * pData;
				rc = rh.GetData(pData);
				if (rc != OK) return rc;

				memcpy(&pData[ATTR_REL_NAME_OFFSET],n_RelName,REL_NAME_SIZE);
				memcpy(&pData[ATTR_NAME_OFFSET],n_AttrName,ATTR_NAME_SIZE);
				memcpy(&pData[ATTR_OFFSET_OFFSET],&n_AttrOffset,sizeof(int));
				memcpy(&pData[ATTR_TYPE_OFFSET],&n_AttrType,sizeof(t_attrType));
				memcpy(&pData[ATTR_LENGTH_OFFSET],&n_AttrLength,sizeof(int));
				memcpy(&pData[ATTR_INX_NO_OFFSET],&indexNum,sizeof(int));

				rc = rfh.UpdateRecord(rh);
				if (rc != OK) return rc;

				done = true;
				break;
			}
		}

		rc = temp_rfs.CloseRecordScan();
		if (rc != OK) return rc;

		if (done) break;
	}

	rc = rfs.CloseRecordScan();
	if (rc != OK) return rc;

	rc = this->rfm->CloseRecordFile(rfh);
	if (rc != OK) return rc;

	if (done) return (OK);
	return (SYSM_ATTRIBUTEDOESNOTEXISTS);

}
コード例 #21
0
t_rc SSQLM_Manager::CompareAttributes(t_attrInfo comparisonAttribute, t_attrInfo convertionAttribute, t_compOp compOp, vector<char *> &pData) {
	t_rc rc;
	REM_RecordFileHandle rfhCompare;
	REM_RecordFileHandle rfhConvertion;
	REM_RecordHandle rhCompare;
	REM_RecordHandle rhConvertion;
	REM_RecordID ridCompare;
	REM_RecordID ridConvertion;
	if(comparisonAttribute.indexNo != -1) {
		/*INXM_IndexHandle indesHandle;
		INXM_IndexScan indexScan;
		

		std::stringstream ss;
		ss << comparisonAttribute.relName << "." << comparisonAttribute.indexNo;
		
		rc = inxm.OpenIndex(ss.str(), comparisonAttribute.indexNo, indexHandle);
		if(rc != OK)
			return rc;

		rc = indexScan.OpenIndexScan(indexHandle, compOp, 

*/

	}else {
		if(comparisonAttribute.relName != convertionAttribute.relName) {
			rc = rfm.OpenRecordFile(comparisonAttribute.relName, rfhCompare);
			if(rc != OK)
				return rc;
			rc = rfm.OpenRecordFile(convertionAttribute.relName, rfhConvertion);
			if(rc != OK)
				return rc;

			REM_RecordFileScan fileScan;
		
			int slotCompare = 0;
			int pageIDCompare = 2;
			int slotConvertion = 0;
			int pageIDConvertion = 2;

			for( ;pageIDCompare <= rfhCompare.sfh.GetNumReservedPages(); pageIDCompare++) {
				for( ;slotCompare <= rfhCompare.rfsh.nrecords; slotCompare++) {
					rc = ridCompare.SetPageID(pageIDCompare);
					if(rc != OK)
						return rc;
					
					rc = ridCompare.SetSlot(slotCompare);
					if(rc != OK)
						return rc;

					rc = rfhCompare.ReadRecord(ridCompare, rhCompare);
					if(rc != OK)
						return rc;

					char *dataCompare;
					rc = rhCompare.GetData(dataCompare);
					if(rc != OK)
						return rc;

					rc = fileScan.OpenRecordScan(rfhConvertion, convertionAttribute.attrType, convertionAttribute.attrLength, convertionAttribute.offset, compOp, dataCompare);
					if(rc != OK)
						return rc;

					char *dataConvertion;
					while(fileScan.GetNextRecord(rhConvertion) == OK){
						rc = rhConvertion.GetData(dataConvertion);
						if(rc != OK)
							return rc;

						pData.push_back(dataCompare);
						pData.push_back(dataConvertion);
					}
					fileScan.CloseRecordScan();
				}
			}
		}
	}
	return OK;
}
コード例 #22
0
t_rc SSQLM_DML_Manager::Where(const char *tName, char *conditions, vector<char *> *finalResultRecords, vector<REM_RecordID> *finalResultRIDs){
		
	char pathname[50];
	char pathname2[50];
	REM_RecordFileHandle *rfh = new REM_RecordFileHandle();
	REM_RecordFileScan *rfs = new REM_RecordFileScan();
	REM_RecordHandle rh;
	REM_RecordID rid;

	vector <char*> conditionsList;
	vector <char*> conditionsListWithoutIndex;

	int condLength = strlen(conditions);
	char *str = (char*)malloc(condLength);
	strcpy(str,conditions);

	char *pointer = str;
	int offset = 0;
	int size;
	char *type;
	char condition[50]; // one condition
	int i = 0;
	char *conditionAttribute = NULL;
	char *conditionValue = NULL;
	t_compOp comp = NO_OP;
	int index_no;
	t_rc rc;

	// Split with delimeter "AND"
	while(strstr(pointer,"AND")){					//***********************************************
													//**	Spaw thn eisodo tou where sta conditions.
		pointer = strstr(pointer,"AND");			//**	To conditionsList periexei ola ta 
		i = 0;										//**	conditions.
		while(&str[offset] != pointer){				//**
			condition[i] = str[offset];				//**
			i++;									//**
			offset++;								//**
		}											//**
		condition[i] = '\0';						//**
													//**
		conditionsList.push_back(condition);		//**
													//**
		offset+=4;									//**
		pointer+=4;									//**
	}												//**
	//add the last condition in the list			//**
	conditionsList.push_back(pointer);				//************************************************

	hash_map<int, REM_RecordID> rids;
	bool isFirstCondition = true;

	for(int iii=0; iii< (int)conditionsList.size(); iii++){		// Gia ka8e condition, 8a elegksw ean yparxei index.  
															// Gia na to kanw auto spaw to condition sta attribute, comperator kai value, kai anoigw to attrmet.
		int condLength = strlen(conditionsList[iii]);		
		char *condit;
		condit = (char *)malloc(condLength);
		strcpy(condit,conditionsList[iii]);					// keep a back up from the condition string because strtok_s destroys it.

		rc = GetConditionInfo(conditionsList[iii],conditionAttribute,comp,conditionValue);		// get the attribute, the comperator and the value of the condition
		if (rc != OK) {return rc; }	
		
		rc = FindAttributeInAttrmet(tName,conditionAttribute,offset,type,size,index_no);
		if (rc != OK) {return rc; }	

		if(index_no != -1){	//IN CASE OF INDEX									//***********************************
																				//**	ean exei index, 
			// Open index file													//**	anoigw to arxeio tou index
			INXM_IndexHandle ih;												//**	kai psaxnw mesa ta rids pou epalh8eyoun thn syn8hkh
			_snprintf_s(pathname2,sizeof(pathname),"%s/%s",dbName,tName);		//**
																				//**
			rc = im->OpenIndex(pathname2,index_no,ih);							//**
			if (rc != OK) { return rc; }										//**
																				//**
			INXM_IndexScan *is = new INXM_IndexScan();							//**
																				//**
			if(type){	// case of Integer										//**
				int cndV = atoi(conditionValue);								//**
				int *key1 = new int(cndV);										//**
				rc = is->OpenIndexScan(ih, comp, key1);							//**			
				if (rc != OK) { return rc; }									//**
			}																	//**
			else{		//case of string										//**
				rc = is->OpenIndexScan(ih, comp, conditionValue);				//**
				if (rc != OK) { return rc; }									//**	
			}																	//***********************************
			
			
			// Prepei twra na vroume thn tomh olwn twn rid pou epistrefoun oi indexers																	
			int i = 0;	
			int page;
			int slott;

			if(isFirstCondition){									//***********************************
																	//**	Edw dhmiourgeitai o hashmap gia to prwto condition.
				while( is->GetNextEntry(rid) != INXM_FSEOF ){		//**	Gia ka8e record pou epistrefei
																	//**
					rid.GetPageID(page);							//**
					rid.GetSlot(slott);								//**			
					rids[page*10000+slott] = rid;					//**	ypologizw ena monadiko kleidi					
					i++;											//**	kai pros8etw to recordid ston hash.		
				}													//**
				isFirstCondition = false;							//**	Gia thn epomenh syn8hkh, 8a vrei thn tomh tou hash me ta epomena rids.
			}														//***********************************
			else{
				hash_map<int, REM_RecordID> intersectionRIDs;

				while( is->GetNextEntry(rid) != INXM_FSEOF ){
				
					rid.GetPageID(page);
					rid.GetSlot(slott);
					if(rids.count(page*10000+slott)){				//	ean yparxei hdh ston prohgoumeno hash
						intersectionRIDs[page*10000+slott] = rid;	//	pros8ese to ston hash me thn tomh.
					}								
					i++;															
				}
				rids.swap(intersectionRIDs);						//	antallakse tous hashes wste na leitourghsei anadromika kai gia ta epomena conditions
			}

			rc = is->CloseIndexScan();
			if (rc != OK) { return rc; }
		}
		else{	// IN CASE THERE IS NO INDEX						//	Se periptwsh pou to attribute tou condition den exei index
			conditionsListWithoutIndex.push_back(condit);			//	pros8ese to sthn lista me ta conditions pou den exoun index
		}
	}

	STORM_StorageManager *stormgr3 = new STORM_StorageManager();				//	Epomeno vhma einai na paroume apo to REM ta records sta opoia
	REM_RecordFileManager *remrfm = new REM_RecordFileManager(stormgr3);		//	antistoixoun ta recordids pou mazepsame apo tous indexers.
	REM_RecordFileHandle *remrfh = new REM_RecordFileHandle();					//	Ean den mazepsame kanena rid apo indexer, tote anazhtoume sto
	REM_RecordHandle *remrh = new REM_RecordHandle();							//	table ta records pou epalh8euoun thn syn8hkh (ths opoias to
	vector <char*> recordsFromIndexes;											//	attribute den eixe index)
	vector <REM_RecordID> ridsFromIndexes;		
	hash_map <int, REM_RecordID>::iterator rids_Iter;
	char *pdata;

	_snprintf_s(pathname,sizeof(pathname),"%s/%s",dbName,tName);
	rc = remrfm->OpenRecordFile(pathname,*remrfh);
	if (rc != OK) { return rc; }

	for ( rids_Iter = rids.begin( ); rids_Iter != rids.end( ); rids_Iter++ ){	// Vres ta records sta opoia antistoixoun h tomh twn rids twn indexes.
		
		REM_RecordID recordid = rids_Iter->second;
		rc = remrfh->ReadRecord(recordid,*remrh);
		if (rc != OK) {return rc; }	

		remrh->GetData(pdata);

		int pDataLength = strlen(pdata);
		char * newInput;
		newInput = (char *)malloc(pDataLength);
		strcpy(newInput,pdata);

		ridsFromIndexes.push_back(recordid);
		recordsFromIndexes.push_back(newInput);									// Apo8hkeyse ta se mia lista.
	}

	rc = remrfm->CloseRecordFile(*remrfh);
	if (rc != OK) {return rc; }

	if(!conditionsListWithoutIndex.empty()){																//	Ean yparxoun conditions xwris indexes,
																											//	8a psaksoume to attribute tou ka8e condition sto arxeio attrmet
//																											//	wste na paroume plhrofories gia to attribute (offset,type,...)
		int offset2,size2,indexID2;																			//	me teliko stoxo na elegksoume poia apo ta records pou epestrepsan
		char *type2;																						//	oi indexers, epalh8euoun ta conditions xwris index.

		for(int i=0; i< (int) conditionsListWithoutIndex.size(); i++){										//	Gia ka8e tetoio condition loipon,

			rc = GetConditionInfo(conditionsListWithoutIndex[i],conditionAttribute,comp,conditionValue);	//	vres ta systatika tou merh (attribute, comperator, value)
			if (rc != OK) {return rc; }	

			rc = FindAttributeInAttrmet(tName,conditionAttribute,offset2,type2,size2,indexID2);				//	kai psakse mesa sto attrmet to record gia to sygkekrimeno attribute. Pare tis plhrofories gia to attribute.
			if (rc != OK) {return rc; }	

			int j = 0;
			if(!recordsFromIndexes.empty()){
				for(int j=0; j<(int)recordsFromIndexes.size(); j++){										//	Sygkrine an isxyei h syn8hkh me ola ta records pou epestrepsan oi indexes.	
					
					char *value;																			//	Ean h syn8hkh epalh8euetai, pros8ese to record sthn lista eksodou finalResultRecords.
					value = (char *)malloc(size);
					int z;
					for(z=0; z<size; z++){
						value[z] = recordsFromIndexes[j][offset+z];
					}
					value[z] = '\0';
					if(strstr(type,"TYPE_INT")){
						int val = atoi(value);
						int condValue = atoi(conditionValue);
						if(comp == EQ_OP){
							if(val == condValue){
								finalResultRecords->push_back(recordsFromIndexes[j]);
								finalResultRIDs->push_back(ridsFromIndexes[j]);
							}
						}
						else if(comp == GT_OP){
							if(val > condValue){
								finalResultRecords->push_back(recordsFromIndexes[j]);
								finalResultRIDs->push_back(ridsFromIndexes[j]);
							}
						}
						else if(comp == LT_OP){
							if(val < condValue){
								finalResultRecords->push_back(recordsFromIndexes[j]);
								finalResultRIDs->push_back(ridsFromIndexes[j]);
							}
						}
						else if(comp == NE_OP){
							if(val != condValue){
								finalResultRecords->push_back(recordsFromIndexes[j]);
								finalResultRIDs->push_back(ridsFromIndexes[j]);
							}
						}
						else if(comp == GE_OP){
							if(val >= condValue){
								finalResultRecords->push_back(recordsFromIndexes[j]);
								finalResultRIDs->push_back(ridsFromIndexes[j]);
							}
						}
						else if(comp == LE_OP){
							if(val <= condValue){
								finalResultRecords->push_back(recordsFromIndexes[j]);
								finalResultRIDs->push_back(ridsFromIndexes[j]);
							}
						}
					}
					else{ // the type is TYPE_STRING
						if(comp == EQ_OP){
							if(strstr(value,conditionValue)){
								finalResultRecords->push_back(recordsFromIndexes[j]);
								finalResultRIDs->push_back(ridsFromIndexes[j]);
							}
						}
						if(comp == GT_OP || comp == GE_OP){
							if(strcmp(value,conditionValue) == 1){
								finalResultRecords->push_back(recordsFromIndexes[j]);
								finalResultRIDs->push_back(ridsFromIndexes[j]);
							}
						}
						if(comp == LT_OP || comp == LE_OP){
							if(strcmp(value,conditionValue) == -1){
								finalResultRecords->push_back(recordsFromIndexes[j]);
								finalResultRIDs->push_back(ridsFromIndexes[j]);
							}
						}
					}
					j++;
				}
			}
			else{	// PERIPTWSH POU DEN EIXAME KANENA CONDITION ME INDEX									//	Sthn periptwsh pou den exoume kamia syn8hkh me index
				REM_RecordFileScan *remrfs = new REM_RecordFileScan();										//	psaxnoume mesa ston pinaka ta records pou epalh8euoun
				REM_RecordHandle *remrh2 = new REM_RecordHandle();											//	thn syn8hkh kai ta apouhkeyoume sthn lista eksodou.
				STORM_StorageManager *stormgr4 = new STORM_StorageManager();				
				REM_RecordFileManager *remrfm2 = new REM_RecordFileManager(stormgr4);		
				REM_RecordFileHandle *remrfh2 = new REM_RecordFileHandle();					
				char *data;

				_snprintf_s(pathname,sizeof(pathname),"%s/%s",dbName,tName);
				rc = remrfm2->OpenRecordFile(pathname,*remrfh2);
				if (rc != OK) { return rc; }
				
				if(strcmp(type,"TYPE_INT") == 0){

					int atoiCondition = atoi(conditionValue);
					int *key = new int(atoiCondition);

					rc = remrfs->OpenRecordScan(*remrfh2,TYPE_INT,size,offset,comp,key);	
					if (rc != OK) {return rc; }
				}
				else{
					rc = remrfs->OpenRecordScan(*remrfh2,TYPE_STRING,size,offset,comp,conditionValue);
					if (rc != OK) {return rc; }
				}
				while( remrfs->GetNextRecord(*remrh2) != REM_FSEOF ){

					REM_RecordID recordIDFromNoIndex;
					rc = remrh2->GetRecordID(recordIDFromNoIndex);
					if (rc != OK) {return rc; }

					rc = remrh2->GetData(data);
					if (rc != OK) {return rc; }

					int dataLength = strlen(data);
					char *input;
					input = (char *)malloc(dataLength);
					strcpy(input,data);
					finalResultRecords->push_back(input);	
					finalResultRIDs->push_back(recordIDFromNoIndex);
				}

				rc = remrfs->CloseRecordScan();
				if (rc != OK) {return rc; }

				rc = remrfm2->CloseRecordFile(*remrfh2);
				if (rc != OK) {return rc; }
				
				delete remrfs;
				delete remrh2;
				delete remrfh2;
				delete remrfm2;
				delete stormgr4;
			}
		}
	}
	else{	// PERIPTWH POU EIXAME MONO CONDITIONS ME INDEXES			//	Se auth thn periptwsh apla vgazoume sthn eksodo
		for( int i=0; i<(int)recordsFromIndexes.size(); i++){			//	ta records pou epestrepsan oi indexes.
			finalResultRecords->push_back(recordsFromIndexes[i]);
			finalResultRIDs->push_back(ridsFromIndexes[i]);
		}
	}

	delete remrh;
	delete remrfh;
	delete remrfm;
	delete stormgr3;

	return OK;
}