由于表经常地进行增加删除,所以表文件会一直增大所以想请教用什么方法可以对表进行压缩
谢谢

解决方案 »

  1.   

    看看这段Delphi带的帮助吧:C syntaxDBIResult DBIFN DbiPackTable (hDb, hCursor, pszTableName, [pszDriverType], bRegenIdxs);Delphi syntaxfunction DbiPackTable (hDb: hDBIDb; hCursor: hDBICur; pszTableName: PChar; pszDriverType: PChar; bRegenIdxs: Bool): DBIResult stdcall;DescriptionDbiPackTable optimizes table space by rebuilding the table associated with hCursor and releasing any free space.ParametershDb  Type: hDBIDb  (Input)
    Specifies the valid database handle.
    hCursor  Type: hDBICur  (Input)
    Specifies the cursor on the table to be packed. Optional. If hCursor is specified, the operation is performed on the table associated with the cursor. If hCursor is NULL, pszTableName and pszDriverType determine the table to be used. 
    pszTableName  Type: pCHAR  (Input)
    Pointer to the table name. Optional. If hCursor is NULL, pszTblName and pszTblType determine the table to be used. (If both pszTableName and hCursor are specified, pszTableName is ignored.) If pszTableName is a fully qualified name of a table, the pszDriverType parameter need not be specified. If the path is not included, the path name is taken from the current directory of the database associated with hDb. pszDriverType  Type: pCHAR  (Input)
    Pointer to the driver type. Optional. This parameter is required if pszTableName has no extension. The only valid pszDriverType is szDBASE.
    bRegenIdxs  Type: BOOL  (Input)
    Specifies whether or not to regenerate out-of-date table indexes. If TRUE, all out-of-date table indexes are regenerated (applies to maintained indexes only). Otherwise, out-of-date indexes are not regenerated.UsagedBASE or FoxPro: dBASE and FoxPro let users  a record for deletion (as opposed to actually removing it from the table). The only way to permanently remove ed records is with DbiPackTable. Paradox: This function is not valid for Paradox tables. Use DbiDoRestructure with the bPack option, instead.SQL, Access: This function is not valid for SQL or Access tables.PrerequisitesExclusive access to the table is required. DbiResult return valuesDBIERR_NONE The table was successfully rebuilt.
    DBIERR_INVALIDPARAM The specified table name or the pointer to the table name is NULL.
    DBIERR_INVALIDHNDL The specified database handle or cursor handle is invalid or NULL.
    DBIERR_NOSUCHTABLE Table name does not exist.
    DBIERR_UNKNOWNTBLTYPE Table type is unknown.
    DBIERR_NEEDEXCLACCESS The table is not open in exclusive mode.
      

  2.   

    Delphi带的例子:Example 1: Pack a Paradox or dBASE table.This example will pack a Paradox or dBASE table therfore removing already deleted rows in a table. This function will also regenerate all out-of-date indexes (maintained indexes). This example uses the following input:  PackTable(Table1)The function is defined as follows: // Pack a Paradox or dBASE table
    // The table must be opened execlusively before calling this function...
    procedure PackTable(Table: TTable);
    var
      Props: CURProps;
      hDb: hDBIDb;
      TableDesc: CRTblDesc;
    begin
      // Make sure the table is open exclusively so we can get the db handle...
      if not Table.Active then
        raise EDatabaseError.Create('Table must be opened to pack');
      if not Table.Exclusive then    raise EDatabaseError.Create('Table must be opened exclusively to pack');  // Get the table properties to determine table type...
      Check(DbiGetCursorProps(Table.Handle, Props));  // If the table is a Paradox table, you must call DbiDoRestructure...
      if Props.szTableType = szPARADOX then begin
        // Blank out the structure...
        FillChar(TableDesc, sizeof(TableDesc), 0);
        // Get the database handle from the table's cursor handle...    Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
        // Put the table name in the table descriptor...
        StrPCopy(TableDesc.szTblName, Table.TableName);
        // Put the table type in the table descriptor...
        StrPCopy(TableDesc.szTblType, Props.szTableType);
        // Set the Pack option in the table descriptor to TRUE...
        TableDesc.bPack := True;
        // Close the table so the restructure can complete...
        Table.Close;
        // Call DbiDoRestructure...    Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, False));
      end
      else
        // If the table is a dBASE table, simply call DbiPackTable...
        if (Props.szTableType = szDBASE) then
          Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, True))
        else
          // Pack only works on PAradox or dBASE; nothing else...
          raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' +        'type to pack');  Table.Open;end;