Beispiel #1
0
void DBObjTable::RedefineField(DBObjTableField *field, DBObjTableField *newField) {
    DBInt recID, fieldID;
    DBObjRecord *record, *oldRecord;
    DBObjTableField *tmpField;

    newField->StartByte(field->StartByte());
    if (field->Length() != newField->Length()) {
        RecordLengthVAR += (newField->Length() - field->Length());
        for (fieldID = field->RowID() + 1; fieldID < FieldNum(); ++fieldID) {
            tmpField = Field(fieldID);
            tmpField->StartByte(tmpField->StartByte() + newField->Length() - field->Length());
        }
    }
    for (recID = 0; recID < ItemNum(); recID++) {
        record = Item(recID);
        oldRecord = new DBObjRecord(*record);
        if (field->Length() != newField->Length()) {
            record->Realloc(RecordLengthVAR);
            if (newField->StartByte() + newField->Length() < RecordLengthVAR)
                memcpy(((char *) record->Data()) + newField->StartByte() + newField->Length(),
                       ((char *) oldRecord->Data()) + field->StartByte() + field->Length(),
                       RecordLengthVAR - (newField->StartByte() + newField->Length()));
        }
        switch (newField->Type()) {
            case DBTableFieldString:
                newField->String(record, field->String(oldRecord));
                break;
            case DBTableFieldInt:
                newField->Int(record, field->Int(oldRecord));
                break;
            case DBTableFieldFloat:
                newField->Float(record, field->Float(oldRecord));
                break;
            case DBTableFieldDate:
                newField->Date(record, field->Date(oldRecord));
                break;
            case DBTableFieldCoord:
                newField->Coordinate(record, field->Coordinate(oldRecord));
                break;
            case DBTableFieldRegion:
                newField->Region(record, field->Region(oldRecord));
                break;
            case DBTableFieldPosition:
                newField->Position(record, field->Position(oldRecord));
                break;
            case DBTableFieldTableRec:
            case DBTableFieldDataRec:
                newField->Record(record, field->Record(oldRecord));
                break;
        }
        delete oldRecord;
    }
    if (strcmp(field->Name(), newField->Name()) != 0) field->Name(newField->Name());
    if (field->Type() != newField->Type()) field->Type(newField->Type());
    if (field->FormatWidth() != newField->FormatWidth()) field->FormatWidth(newField->FormatWidth());
    if ((field->Type() == DBTableFieldFloat) && (field->FormatDecimals() != field->FormatDecimals()))
        field->FormatDecimals(newField->FormatDecimals());
    if (field->Length() != newField->Length()) field->Length(newField->Length());
}
Beispiel #2
0
void DBObjTable::DeleteField(DBObjTableField *delField) {
    DBInt i, recID, fieldID;
    DBObjRecord *record;
    DBObjTableField *field;
    unsigned char *data;

    for (fieldID = 0; fieldID < FieldPTR->ItemNum(); ++fieldID) {
        field = FieldPTR->Item(fieldID);
        if (field->StartByte() > delField->StartByte())
            field->StartByte(field->StartByte() - delField->Length());
    }
    for (recID = 0; recID < ItemNum(); ++recID) {
        record = Item(recID);
        data = (unsigned char *) record->Data() + delField->StartByte();
        for (i = 0; i < RecordLengthVAR - delField->StartByte() - delField->Length(); ++i)
            data[i] = data[i + delField->Length()];
        record->Realloc(RecordLengthVAR - delField->Length());
    }
    FieldPTR->Remove(delField);
    RecordLengthVAR -= delField->Length();
    delete delField;
}
Beispiel #3
0
int DBObjTable::Read(FILE *file, int swap) {
    DBInt id;
    DBDate date;
    DBCoordinate coord;
    DBRegion region;
    DBPosition pos;
    DBUShort row, col;
    DBObjRecord *record;
    DBObjTableField *field;

    if (DBObjectLIST<DBObjRecord>::Read(file, swap) != DBSuccess) return (DBFault);
    if (FieldPTR->Read(file, swap) != DBSuccess) return (DBFault);
    for (id = 0; id < FieldPTR->ItemNum(); ++id)
        if (FieldPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);

    RecordLengthVAR = 0;
    for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next())
        RecordLengthVAR = RecordLengthVAR > field->StartByte() + field->Length() ?
                          RecordLengthVAR : field->StartByte() + field->Length();

    for (id = 0; id < ItemNum(); ++id) {
        if (ReadItem(file, id, swap) == DBFault) return (DBFault);
        record = Item(id);
        if (swap == false) continue;
        for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next())
            switch (field->Type()) {
                case DBTableFieldInt:
                case DBTableFieldFloat:
                case DBTableFieldTableRec:
                case DBTableFieldDataRec:
                    switch (field->Length()) {
                        case 2:
                            DBByteOrderSwapHalfWord((char *) record->Data() + field->StartByte());
                            break;
                        case 4:
                            DBByteOrderSwapWord((char *) record->Data() + field->StartByte());
                            break;
                        case 8:
                            DBByteOrderSwapLongWord((char *) record->Data() + field->StartByte());
                            break;
                    }
                    break;
                case DBTableFieldDate:
                    date = field->Date(record);
                    date.Swap();
                    field->Date(record, date);
                    break;
                case DBTableFieldCoord:
                    coord = field->Coordinate(record);
                    coord.Swap();
                    field->Coordinate(record, coord);
                    break;
                case DBTableFieldRegion:
                    region = field->Region(record);
                    region.Swap();
                    field->Region(record, region);
                    break;
                case DBTableFieldPosition:
                    pos = field->Position(record);
                    switch (field->Length()) {
                        case sizeof(DBPosition):
                            pos.Swap();
                            break;
                        default:
                            row = pos.Row;
                            col = pos.Col;
                            DBByteOrderSwapHalfWord(&row);
                            DBByteOrderSwapHalfWord(&col);
                            pos.Row = row;
                            pos.Col = col;
                            break;
                    }
                    field->Position(record, pos);
                    break;
                default:
                    break;
            }
    }
    if (MethodPTR->Read(file, swap) != DBSuccess) return (DBFault);
    for (id = 0; id < MethodPTR->ItemNum(); ++id) if (MethodPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
    return (DBSuccess);
}