Ejemplo n.º 1
0
/**
 * @brief updateField changes the value of a  given field on the whole database.
 * @param newData new information to be inserted.
 * @param pFile the database to be used
 * @param pRow
 * @param pColumn
 */
bool writefile::updateField(string newData, string pFile , int pRow , int pColumn){
    int currSeek = file.tellg();
    int sizeToColumn;
    int cSize;
    bool bowl = true;
    //Relative route + the name of the file
    if ( !(file.is_open()) ){
        string fileH = pFile;
        string standardDir = createNewFile(fileH.c_str());
        file.open(standardDir.c_str());
    }

    if ( !(file.is_open()) ){
        cout << "NED " + pFile << endl;
        bowl = false;
    }

    placeSeekOn(&pRow , &pColumn, &sizeToColumn, &cSize);
    fillString(&newData,cSize);


    if (file.is_open()){
        file << newData;
    }

    file.seekg(currSeek);

    if (file.is_open()){
        file.close();
    }
    return bowl;
}
Ejemplo n.º 2
0
/**
 * @brief readField returns the data readed on field of the database.
 * @param pFile is the name of the file to be readed from.
 * @param pRow is the row of the desired data.
 * @param Column is the column of the desired data.
 * @return
 */
string readfile::readField(string pFile , int pRow , int pColumn){
    int currSeek =file.tellg();
    int sizeToColumn;
    int cSize;
    //Relative route + the name of the file
    if ( !(file.is_open()) ){
        string standardDir = createNewFile(&pFile);
        file.open(standardDir.c_str());
    }

    if ( !(file.is_open()) ){
        return "NED " + pFile;
    }

   placeSeekOn(&pRow , &pColumn, &sizeToColumn, &cSize);

    //build the stringto return
    string stringToReturn = "";

    for (int i  = 0 ; i < cSize ; i++){
        char currChar = file.get();
        if (currChar != '*'){
            stringToReturn.push_back(currChar);
        }else{
            break;
        }
    }
    file.seekg(currSeek);
    if (stringToReturn == "") stringToReturn = "404";
    return stringToReturn;
}
Ejemplo n.º 3
0
/**
 * @brief updateColumn From pCname of pFile, replace pToCompare with newData
 * @param newData
 * @param pToCompare
 * @param pFile
 * @param pCName
 */
bool writefile::updateColumn(string newData,string pToCompare, string pFile, string pCName){

    int currSeek = file.tellg();
    int sizeToColumn;
    int cSize;
    string standardDir;
    bool bowl = true;

    //Relative route + the name of the file
    if ( !(file.is_open()) ){
        string fileH = pFile;
        standardDir = createNewFile(fileH.c_str());
        file.open(standardDir.c_str());
    }

    if ( !(file.is_open()) ){
        cout << "NED " + pFile << endl;
        bowl = false;
    }

    int Column = getColumnNumber(&standardDir , &pCName );
    int regQty = getRegisterQuantity();
    string currentData = K->EMPTY_STRING;

    for (int rowCounter = K->ONE_BYTE ; rowCounter <= regQty ; rowCounter++){

        //Move the seek to the column and register.
        placeSeekOn( &rowCounter , &Column, &sizeToColumn, &cSize);

        //Build the string of the old data
        for (int i = 0 ; i < cSize ; i++){
            char temp = file.get();
            if (temp == '*'){
                break;
            }else{
                currentData.push_back(temp);
            }
        }
        //Compare data.
        if (currentData == pToCompare){
            updateField(newData, pFile , rowCounter , Column);
        }else{
            currentData = K->EMPTY_STRING;
        }
    }

    file.seekg(currSeek);
    if (file.is_open()){
        file.close();
    }
    return bowl;
}
Ejemplo n.º 4
0
bool writefile::deleteRegister(string pFile, string pCName, string newData){
    int currSeek = file.tellg();
    int Column;
    int cSize;
    string standardDir;
    bool bowl = true;

    //Relative route + the name of the file
    if ( !(file.is_open()) ){
        standardDir = createNewFile(pFile.c_str());
        file.open(standardDir.c_str());
    }

    if ( !(file.is_open()) ){
        cout << "NED " + pFile << endl;
        return false;
    }

    Column = getColumnNumber(&standardDir , &pCName );
    cSize = getRegisterSize();
    int regQty = getRegisterQuantity();
    string voidField = K->EMPTY_STRING;
    int sizeToColumn = sizeUntilColumn(Column);

    fillString(&voidField,cSize);
    cout << voidField.length() <<endl;
    for (int rowCounter = K->ONE_BYTE ; rowCounter <= regQty ; rowCounter++){

        //Compare data.
        if (readField(pFile , rowCounter , Column) == newData){
            placeSeekOn(&rowCounter , &Column, &sizeToColumn, &cSize);
            if (file.is_open()){
                file << voidField;
            } else {
                bowl = false;
            }
        }
    }

    file.seekg(currSeek);
    if (file.is_open()){
        file.close();
    }
    return bowl;
}