Solved

Packing Paradox TTables in D3 Standard

Posted on 1998-09-06
6
311 Views
Last Modified: 2010-04-06
How do I pack and regenerate indexes on Paradox tables using Delphi 3 Standard edition. I know it can be done in Database Desktop but how do I achieve it at runtime.
I can't find any reference to it in the help files.

I'm probably missing something really simple but I'm tearing my hair out here.

Please help me people !!
0
Comment
Question by:elkiors
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 100 total points
ID: 1338775
From Borland Documenatation:
http://www.inprise.com/devsupport/bde/bdeapiex/dbidorestructure.html

Example 2: 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 Table.Active = False then
               raise EDatabaseError.Create('Table must be opened to pack');
             if Table.Exclusive = False 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;
0
 

Author Comment

by:elkiors
ID: 1338776
Please bear with me while I check out your answer, I'm a little pushed for time for checking it out. Give me a couple of days and I'll Accept or Reject.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1338777
OK, if you have problems then before the first Check(...
write:                                Check(dbiInit(Nil)); //initializing the BDE
and on the end write:       DbiExit;               //freening resources
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:elkiors
ID: 1338778
Ronit:

I'm sorry but I can't get this to compile, if you could make this a stand alone unit that I can just add to my projects it would be great.

At the moment it seems to be stopping on var types declared at the front of the PackTable procedure, I've tried to do a search for them in the help files so that I can trace the standard units requirements but no luck so far. Unfortunately, I'm still a novice, so the really low-level stuff like this is a bit beyond me.

I've upped the points as much as I can to help you consider the extra bit of effort needed on your part

thanx in advance for all your help

regards

elkiors



unit dbPack;

interface

procedure PackTable(Table: TTable);

implementation

// 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 Table.Active = False then raise EDatabaseError.Create('Table must be opened to pack');
  if Table.Exclusive = False 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;

end.

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1338779
Did you add to the uses --->BDE, DBTables,DB?
0
 

Author Comment

by:elkiors
ID: 1338780
thanx ronit, just what i need
the final compilable unit is listed below so anyone else can use it without any need to modify it further.


---------------------------------
unit dbPack;

interface

uses BDE, DBTables, DB, sysutils;

procedure PackTable(Table: TTable);

implementation

// 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 Table.Active = False then raise EDatabaseError.Create('Table must be opened to pack');
  if Table.Exclusive = False 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;

end.
----------------------------------------------------

thanks once again,

enjoy the points,

c u on another thread.

elkiors (Darren)

0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question