?
Solved

Packing Paradox TTables in D3 Standard

Posted on 1998-09-06
6
Medium Priority
?
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 14 hours left to enroll

762 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