Announcement

Collapse
No announcement yet.

Bug in "DbiDoRestructure"??

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bug in "DbiDoRestructure"??

    Hallo zusammen,

    ich habe folgendes Problem: Ich muss in einer Paradox-Tabelle per Programm(Delphi 7) die Länge eines Feldes vergrößern. Ich hab dazu das u. a. Originalbeispiel verwandt.
    Beim Aufruf von DbiDoRestructure wird nun automatisch eine temp. Tabelle angelegt, die riesig gross wird und nach einiger Zeit zum Absturz führt, weil keine Daten mehr eingefügt werden können. Das Ganze sieht so aus, als würde in DbiDoRestructure eine Endlosschleife sein. Kennt jemand das Problem? Am besten auch noch einen Workaround!! Für Hilfe wäre ich echt dankbar.
    Hier mein verwandter Code:

    Code sample to resize a Paradox table field at run-time

    Calling Syntax:
    ResizeField('c:\database\sometable.db', 'FieldName', 80);
    // (where 80 is the new field size)

    --------------------------------------------------------------------------------

    Uses DBITypes, DBIProcs, DBTables, DB;

    // Structure used to specify new field properties
    type TChangeRec = Packed Record
    szName: DBINAME;
    iType: word;
    iSubType: word;
    iLength: word;
    iPrecision: byte;
    end;

    // Procedure to modify Paradox table field properties
    // (based on example from the Borland BDE Reference help)
    procedure ChangeField(Table : TTable; FieldName : String; Rec : TChangeRec);
    var
    Props: CURProps;
    hDb: hDBIDb;
    Res : DBIResult;
    TableDesc: CRTblDesc;
    pFields: pFLDDesc;
    pOp: pCROpType;
    B: byte;
    Field : TField;
    begin
    // Make sure table is opened exclusively
    If (Table.Active and Not Table.Exclusive) Then Table.Close;
    If (Not Table.Exclusive) Then Table.Exclusive := True;
    If (Not Table.Active) Then Table.Open;

    Field := Table.FieldByName(FieldName);

    // Get table properties (needed to get table type)
    Check(DbiSetProp(hDBIObj(Table.Handle), curxltMODE, integer(xltNONE)));
    Check(DbiGetCursorProps(Table.Handle, Props));

    // Allocate memory for pointers
    pFields := AllocMem(Table.FieldCount * sizeof(FLDDesc));
    pOp := AllocMem(Table.FieldCount * sizeof(CROpType));

    try
    // Set the pointer to the index in the operation descriptor
    // to crMODIFY (to modify field properties)
    Inc(pOp, Field.Index);
    pOp^ := crMODIFY;
    Dec(pOp, Field.Index);

    // Get existing field properties
    Check(DbiGetFieldDescs(Table.Handle, pFields));
    Inc(pFields, Field.Index);

    // Check for field changes specified by caller
    if StrLen(Rec.szName) > 0 then pFields^.szName := Rec.szName;
    if Rec.iType > 0 then pFields^.iFldType := Rec.iType;
    if Rec.iSubType > 0 then pFields^.iSubType := Rec.iSubType;
    if Rec.iLength > 0 then pFields^.iUnits1 := Rec.iLength;
    if Rec.iPrecision > 0 then pFields^.iUnits2 := Rec.iPrecision;

    Dec(pFields, Field.Index);

    for B := 1 to Table.FieldCount do begin
    pFields^.iFldNum := B;
    Inc(pFields, 1);
    end;
    Dec(pFields, Table.FieldCount);

    // Clear the structure
    FillChar(TableDesc, sizeof(TableDesc), 0);

    // Get database handle from the table cursor's handle
    Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));

    // Set table name and type into the descriptor
    StrPCopy(TableDesc.szTblName, Table.TableName);
    StrPCopy(TableDesc.szTblType, Props.szTableType);

    // Set field count for this table
    TableDesc.iFldCount := Table.FieldCount;

    // Link the operation descriptor to the table descriptor
    TableDesc.pecrFldOp := pOp;

    // Link the field descriptor to the table descriptor
    TableDesc.pFldDesc := pFields;

    Table.Close;

    // Do the actual table restructuring
    Res := DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE);
    Check(Res);
    finally
    if pFields <> nil then FreeMem(pFields);
    if pOp <> nil then FreeMem(pOp);

    Table.Exclusive := False;
    Table.Open;
    end;
    end;

    // Procedure to resize a Paradox table field
    procedure ResizeField(TablePathName, Fiel

  • #2
    Hallo,

    wenn die Datenbank auf einer NTFS-Partition liegt, tritt das Problem auch dann auf, wenn es zum Test auf eine FAT16-Partition kopiert wird

    Comment


    • #3
      Hallo,

      tritt unabhängig vom Dateisystem auf. Ich denke, ich werde es auf die gute "altmodische" Tour machen (Spalte per SQL anhängen, Wert reinkopieren, alte löschen etc.) Vielen Dank trotzdem

      Comment

      Working...
      X