Example #1
0
void carregaDados(struct page *buffer, char *data, char *meta, struct CAMPOS *campos){
//Traz todos os registros para o buffer
    int i=1, tamTpl = tamTupla(campos, meta);
    char *linha = getTupla(campos, meta, data, 0);

    while(linha != NULL){ //Pega as tuplas e insere no buffer até que acabe o arquivo
        colocaTuplaBuffer(buffer, linha, campos, meta);
        linha = getTupla(campos, meta, data, i*tamTpl);
        i++;
    }
}
Example #2
0
File: func.c Project: lucacp/BDII-2
void carregaDados(struct page *buffer, char *meta, struct CAMPOS *campos, struct OBJ *tabela){
//Traz todos os registros para o buffer
	//int id = 1;
    int i=1, tamTpl = tamTupla(campos, meta);  //tamTpl representa o tamanho total dos atributos
    char *linha = getTupla(campos, meta, tabela, 0);
	
    while(linha != NULL){ //Pega as tuplas e insere no buffer até que acabe o arquivo
        colocaTuplaBuffer(buffer, linha, campos, meta);
        linha = getTupla(campos, meta, tabela, i*tamTpl);
        i++;
    }
}
Example #3
0
int colocaTuplaBuffer(tp_buffer *buffer, int from, tp_table *campos, struct fs_objects objeto){//Define a página que será incluida uma nova tupla
	
	char *tupla = getTupla(campos,objeto,from);

 	if(tupla == ERRO_DE_LEITURA)
 		return ERRO_LEITURA_DADOS;

    int i=0, found=0;
	while (!found && i < PAGES)//Procura pagina com espaço para a tupla.
	{
    	if(SIZE - buffer[i].position > tamTupla(campos, objeto)){// Se na pagina i do buffer tiver espaço para a tupla, coloca tupla.
            setTupla(buffer, tupla, tamTupla(campos, objeto), i);
            found = 1;
            buffer[i].position += tamTupla(campos, objeto); // Atualiza proxima posição vaga dentro da pagina.
            buffer[i].nrec += 1;
            break;
    	}
    	i++;// Se não, passa pra proxima página do buffer.
    }
    
    if (!found)
		return ERRO_BUFFER_CHEIO;

	return SUCCESS;
}
Example #4
0
int carregaDados(struct page *buffer, char *meta, struct CAMPOS *campos, struct OBJ *tabela){
	//Traz todos os registros para o buffer
	
    int i=1,tamTpl = (tamTupla(campos, meta)); //tamTpl representa o tamanho total dos atributos
    char *linha;
     if(!(tamTpl)){
	  return GENERIC_ERROR;
     }

     if(!(linha =(char *)malloc(sizeof(char)*tamTpl))){
		 return OUT_OF_MEMORY;
     }
    int error;
	
    error = getTupla(linha,campos, meta, tabela, 0);
    if(error == OKAY){

		while(linha != NULL){ //Pega as tuplas e insere no buffer até que acabe o arquivo
			error = colocaTuplaBuffer(buffer, linha, campos, meta);
			free(linha);
			linha =(char *)malloc(sizeof(char)*tamTpl);
			if(error == OKAY){
				error = getTupla(linha,campos, meta, tabela, i*tamTpl);
				
				if( error != OKAY){
					return OKAY;
				}
				i++;
			}else return error;
		}
		
	}
	else
		return error;
	return OKAY;
}