Esempio n. 1
0
int Scan_relcat(char *ar)
{
	int recid;
	relDesc record;
	int fd, sd;

	if( (sd = HF_OpenFileScan(relCatFd, sizeof(relDesc), 'c',  MAXNAME,  0, 1, ar)) < 0)
		return (UT_errno = HF_errno);
	if((recid = HF_FindNextRec(sd, (char*)&record)) >=0 )
	{
		if(HF_CloseFileScan(sd) < 0)
			return (UT_errno = HF_errno);
		return 1;
	}
	else 
	{
		if(HF_CloseFileScan(sd) < 0)
			return (UT_errno = HF_errno);
		return (UT_errno = HF_errno);
	}
}
Esempio n. 2
0
int Scan_attrcat(char *ar)
{
	int recid;
	attrDesc record;
	int sd;
	if( (sd = HF_OpenFileScan(attrCatFd, sizeof(attrDesc), 'c', MAXNAME, MAXNAME, 1, ar)) < 0 )
		return (UT_errno = HF_errno);
	if((recid = HF_FindNextRec(sd, (char*)&record)) >= 0)
	{
		if(HF_CloseFileScan(sd) < 0)
			return (UT_errno = HF_errno);
		printf("prin to return\n");
		return 1;
	}
	else  
	{
		if(HF_CloseFileScan(sd) < 0)
			return (UT_errno = HF_errno);
		printf("---  %d\n", recid);	
		return (UT_errno = HF_errno);
	}
}
Esempio n. 3
0
int VW_CreateSelect(int argc, char* argv[]){

	int scanDesc,check,found=0;
	relDesc recrel;
	attrDesc recattr;
	int scanDescattr;
	char* rec;
	int utc,j;
	char** utcargs;    //pinakas mesa ston opoion tha ftiaksoume ta orismata ths UT_Create

	//elegxos gia to an dinetai akribos mia sxesi i parapano







	if((scanDesc=HF_OpenFileScan(viewfd,sizeof(viewDesc),'c',MAXNAME,0,EQUAL,argv[1]))<0)
		HF_PrintError("Problem while opening file scan");

	check=HF_FindNextRec(scanDesc,rec);
	while(check!=HFE_EOF){

		if(check>0){
			found=1;			
			break;
		}
		check=HF_FindNextRec(scanDesc,rec);
	}

	if(HF_CloseFileScan(scanDesc)<0)
		HF_PrintError("Error while closing scan");
	
	if(found==0){//an den iparxei i opsi sto viewCat

		//desmeush xorou gia ton pinaka utcargs gia na enimerosoume ta relcat,attrcat me UT_create
		utcargs=malloc((2*atoi(argv[2])+2)*sizeof(char**));
	
		for(i=0;i<(2*atoi(argv[2])+2);i++)
			utcargs[i]=malloc(256*sizeof(char));
	
		sprintf(utcargs[0],"%s","create");
		sprintf(utcargs[1],"%s",argv[1]);
	
		for(i=2;i<(2*atoi(argv[2])+2);i++)//pername ston utcargs ta onomata ton pedion
			if(i%2==0)
				sprintf(utcargs[i],"%s",argv[i+2]);
			
					
		//skanaroume to attrCat gia na broume tous tipous ton pedion kai na tous perasoume ston utcargs	
		j=3;
		for(i=4;i<=(2*atoi(argv[2])+2);i=i+2){
		
		found=0;
	
		if((scanDescattr=HF_OpenFileScan(attrfd,sizeof(attrDesc),'c',MAXNAME,0,EQUAL,argv[3]))<0)
			HF_PrintError("Problem while opening file scan");
		
		check=HF_FindNextRec(scanDescattr,(char*)recattr);
			
		while(check!=HFE_EOF){
			//brikame to probalomeno pedio san pedio tou relname
			if(strcmp(recattr.attrname,argv[i])==0){
				recsize+=recattr.attrlength;
				found=1;
				
				if(recattr.attrtype=='c')
					sprintf(utcargs[j],"%c%d",recattr.attrtype,recattr.attrlength);
				else
					sprintf(utcargs[j],"%c",recattr.attrtype);
				j+=2;	
				//telos kataskeuhs
				
				break;
			}
			
			check=HF_FindNextRec(scanDescattr,(char*)&recattr);
		}
		
		if(HF_CloseFileScan(scanDescattr)<0)
			HF_PrintError("CreateSelect : Error while closing scan");

		
		if(found==0){
			printf("REQUESTED FIELD FOR PROJECTION NOT FOUND IN RELCAT... RETYPE SELECTION USING DIFFERENT ARGUMENTS\n");
			return 1;
		}
		

		if((utc=UT_create(2*atoi(argv[2])+2,utcargs))!=0){//dimiourgia tis sxesis gia na enimerosoume ta Relcat kai Attrcat
			printf("View could not be created\n");
			return -1;
		}
	}
	else{
Esempio n. 4
0
void main()
{
	int athletesFd;
	int eventsFd;
	int partsFd;

	char *athleteRec;
	char *eventRec;
	char *partsRec;

	int athletesScan;
	int eventsScan;
	int partsScan;

	int eventId;
	int eventRecId;
	int partRecId;

	int partsCounter = 0;


	//Αρχικοποίηση Επιπέδου HF
	HF_Init();


	//’νοιγμα Αρχείου EVENTS
	eventsFd = HF_OpenFile("EVENTS");

	if (eventsFd < 0)
	{
		HF_PrintError("Error in HF_OpenFile called on EVENTS.");
		return;
	}


	//’νοιγμα Αρχείου PARTICIPATIONS
	partsFd = HF_OpenFile("PARTICIPATIONS");

	if (partsFd < 0)
	{
		HF_PrintError("Error in HF_OpenFile called on PARTICIPATIONS.");
		return;
	}


	//’νοιγμα Αρχείου ATHLETES
	athletesFd = HF_OpenFile("ATHLETES");

	if (athletesFd < 0)
	{
		HF_PrintError("Error in HF_OpenFile called on ATHLETES.");
		return;
	}
	
	eventId= 30;

	//Scan στο Αρχείο EVENTS με συνθήκη eventId >= "30"
	eventsScan = HF_OpenFileScan(eventsFd, 
								 HF_MAIN_EVENT_REC_SIZE,
								 'i',
								 sizeof(int),
								 0,
								 5,
								 (char *) &eventId);
	
	if (eventsScan < 0) 
	{
		HF_PrintError("HF_OpenFileScan on EVENTS failed");
		return;
	}


	eventRec = (char *) malloc(HF_MAIN_EVENT_REC_SIZE);
	if (eventRec == NULL)
	{
		printf("Event Record malloc failed\n");
		return;
	}

	printf("Scan of file EVENTS with condition: eventId >= %d\n\n", eventId);

	while ( (eventRecId = HF_FindNextRec(eventsScan, eventRec)) >= 0)
	{		
		int recEventId;
		char *eventName = (char *) malloc(HF_MAIN_EVENT_NAME_SIZE);
		if (eventName == NULL)
		{
			printf("Event Name malloc failed\n");
			return;
		}

		memcpy((void *) &recEventId, (void *) eventRec, sizeof(int));
		eventRec += sizeof(int);

		memcpy((void *) eventName, (void *) eventRec, HF_MAIN_EVENT_NAME_SIZE);
		eventRec += HF_MAIN_EVENT_NAME_SIZE;

		printf("Found Event Record: recId=%d, data=(%d, %s)\n", eventRecId, recEventId, eventName);

		eventRec -= HF_MAIN_EVENT_REC_SIZE;

		//Επαλήθευση της τιμής που ανακτήθηκε
		if (recEventId < eventId)
		{
			printf("Invalid Event record\n");
			return;
		}


		//Scan στο Αρχείο PARTICIPATIONS με συνθήκη eventId = recEventId
		partsScan = HF_OpenFileScan(partsFd,
									HF_MAIN_PARTICIPATION_REC_SIZE,
									'i',
									sizeof(int),
									sizeof(int),
									1,
									(char *) &recEventId);

		if (partsScan < 0) 
		{
			HF_PrintError("HF_OpenFileScan on PARTICIPATIONS failed");
			return;
		}

		partsRec = (char *) malloc(HF_MAIN_PARTICIPATION_REC_SIZE);
		if (partsRec == NULL)
		{
			printf("Participation Record malloc failed\n");
			return;
		}

		printf("Scan of file PARTICIPATIONS with condition: eventId = %d\n", recEventId);

		while ( (partRecId = HF_FindNextRec(partsScan, partsRec)) >= 0)
		{
			int partAthId, partEvId;
			char *partDate;

			partDate = (char *) malloc(HF_MAIN_DATE_SIZE);
			if (partDate == NULL)
			{
				printf("Participation Date malloc failed\n");
				return;
			}

			memcpy((void *) &partAthId, (void *)partsRec, sizeof(int));
			partsRec += sizeof(int);

			memcpy((void *) &partEvId, (void *)partsRec, sizeof(int));
			partsRec += sizeof(int);

			memcpy((void *) partDate, (void *)partsRec, HF_MAIN_DATE_SIZE);
			partsRec += HF_MAIN_DATE_SIZE;

			printf("Found Participation Record: recId=%d, data=(%d, %d, %s)\n", partRecId, partAthId, partEvId, partDate);

			partsRec -= HF_MAIN_PARTICIPATION_REC_SIZE;

			//Επαλήθευση της τιμής που ανακτήθηκε
			if (partEvId != recEventId)
			{
				HF_PrintError("Invalid Participation Record\n");
				return;
			}


			//Scan στο Αρχείο ATHLETES με συνθήκη athleteId = partAthId
			athletesScan = HF_OpenFileScan(athletesFd, 
										   HF_MAIN_ATHLETE_REC_SIZE,
										   'i',
										   sizeof(int),
										   0,
										   1,
										   (char *) &partAthId);
			
			if (athletesScan < 0) 
			{
				HF_PrintError("HF_OpenFileScan on ATHLETES failed");
				return;
			}

			athleteRec = (char *) malloc(HF_MAIN_ATHLETE_REC_SIZE);
			if (athleteRec == NULL)
			{
				printf("Athlete Record malloc failed\n");
				return;
			}

			printf("Scan of file ATHLETES with condition: athleteId = %d\n", partAthId);

			if (HF_FindNextRec(athletesScan, athleteRec) >= 0)
			{
				int athleteId;
				char *athleteName;
				char *athleteSurname;
				
				athleteName = (char *) malloc(HF_MAIN_NAME_SIZE);
				if (athleteName == NULL)
				{
					printf("Athlete Name malloc failed\n");
					return;
				}
				athleteSurname = (char *) malloc(HF_MAIN_NAME_SIZE);
				if (athleteSurname == NULL)
				{
					printf("Athlete Surname malloc failed\n");
					return;
				}

				memcpy((void *) &athleteId, (void *) athleteRec, sizeof(int));
				athleteRec += sizeof(int);

				memcpy((void *) athleteSurname, (void *) athleteRec, HF_MAIN_NAME_SIZE);
				athleteRec += HF_MAIN_NAME_SIZE;

				memcpy((void *) athleteName, (void *) athleteRec, HF_MAIN_NAME_SIZE);
				athleteRec += HF_MAIN_NAME_SIZE;

				athleteRec -= HF_MAIN_ATHLETE_REC_SIZE;

				printf("Found Athlete Record: (%d, %s, %s)\n", athleteId, athleteSurname, athleteName);

				//Επαλήθευση της τιμής που ανακτήθηκε
				if (athleteId != partAthId)
				{
					HF_PrintError("Invalid Athlete Record\n");
					return;
				}

				printf("Athlete %s, %s participated in %s on %s.\n", athleteSurname, athleteName, eventName, partDate);

				free(athleteSurname);
				free(athleteName);
			}

			if (HF_FindNextRec(athletesScan, athleteRec) >= 0)
			{
				HF_PrintError("File Scan on Athletes returned a second Athlete record");
				return;
			}

			free(athleteRec);

			//Κλείσιμο του Scan στο Αρχείο ATHLETES
			if (HF_CloseFileScan(athletesScan) != HFE_OK)
			{
				HF_PrintError("Close of Scan on ATHLETES Failed.");
				return;
			}

			printf("Deleting Participation Record %d\n", partRecId);
			if (HF_DeleteRec(partsFd, partRecId, HF_MAIN_PARTICIPATION_REC_SIZE) != HFE_OK)
			{
				HF_PrintError("Deletion of Participation Record failed.");
				return;
			}
			partsCounter++;
			
			free(partDate);
		}

		free(partsRec);

		//Κλείσιμο του Scan στο Αρχείο PARTICIPATIONS
		if (HF_CloseFileScan(partsScan) != HFE_OK)
		{
			HF_PrintError("Close of Scan on PARTICIPATIONS Failed.");
			return;
		}

		printf("Deleting Event Record: recId=%d, data=(%d, %s)\n\n", eventRecId, recEventId, eventName);
		if (HF_DeleteRec(eventsFd, eventRecId, HF_MAIN_EVENT_REC_SIZE) != HFE_OK)
		{
			HF_PrintError("Deletion of Event Record failed.");
			return;
		}

		free(eventName);
	}

	free(eventRec);

	printf("Deleted %d participations\n", partsCounter);
	
	
	//Κλείσιμο Αρχείου PARTICIPATIONS
	if (HF_CloseFile(partsFd) != HFE_OK)
		HF_PrintError("Error in HF_CloseFile called on PARTICIPATIONS.");
	
	//Κλείσιμο Αρχείου EVENTS
	if (HF_CloseFile(eventsFd) != HFE_OK)
		HF_PrintError("Error in HF_CloseFile called on EVENTS.");

	//Κλείσιμο Αρχείου ATHLETES
	if (HF_CloseFile(athletesFd) != HFE_OK)
		HF_PrintError("Error in HF_CloseFile called on ATHLETES.");

}