Delphi Examples: DbiBatchMove

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiBatchMove

Return to chapter overview

Create and copy table information from one table to another.

Because the DBIBatchMove function is a complex function that accepts over 20 parameters, Delphi users are often better served by using the VCL component TBatchMove. This component is found on the Data Access page of the Component Palette.

To use the TBatchMove component in your application, set the component's Mode, Mapping, Source, and Destination properties. You can then execute the batch move at design time by right clicking on the component and choosing Execute from the Speed Menu. Or you can execute the function at runtime by calling its Execute method. The following example illustrates using the component at runtime by appending TTables Table1 to Table2:

procedure TForm1.Button1Click(Sender : TObject);

begin

with BatchMove1 do begin

   Mode := batAppend;

   Source := Table1;

   Destination := Table2;

   Execute;

end;

end;

Append the source handle's table records to the destination handle's table:

BatchCount is the amount of records to append before committing the transaction. Most Delphi users should use the TBatchMove component or the TTable.BatchMove method. This example uses the following input:

 fDbiBatchMove(VendorTbl.Handle, VendorIBTbl.Handle, 500);

 

The procedure is defined as:

procedure fDbiBatchMove(hSrcCur, hDstCur: hDBICur; BatchCount: Longint);

var

 hDb: hDBIDb;

 Count: Longint;

 Length: Word;

 DBType: String;

begin

 Count := 0;

 // Get the database handle from the destination cursor

 Check(DbiGetObjFromObj(hDBIObj(hDstCur), objDATABASE, hDBIObj(hDb)));

 SetLength(DBType, DBIMAXNAMELEN);

 // Get the database type from the database handle

 Check(DbiGetProp(hDBIObj(hDb), dbDATABASETYPE, PChar(DBType), DBIMAXNAMELEN,

   Length));

 SetLength(DBType, StrLen(PChar(DbType)));

if DBType <> 'STANDARD' then

   // If the database is SQL based, set the batch count

   Check(DbiSetProp(hDBIObj(hDb), dbBATCHCOUNT, BatchCount));

 // Append the records

 Check(DbiBatchMove(nil, hSrcCur, nil, hDstCur, batchAPPEND, 0, nil, nil,

  nil, 0, nil, nil, nil, nil, nil, nil, True, True, Count, False));

end;