Icon Copying Tables

Introduction
Copying tables is accomplished through the CopyTable method of the TDBISAMTable component. The properties used by the CopyTable method include the DatabaseName, TableName, and Exists properties. By default, copying a table copies the entire structure and specified contents of a table to a new table. The records that are copied can be controlled by setting a range or filter on the source table being copied prior to calling the CopyTable method. You can also specify False for the last CopyData parameter in order to only copy the table structure and not the table contents.

Information The CopyTable method acquires a read lock on the source table at the beginning of the copy operation and does not release it until the copy operation is complete. This is done to make sure that no other sessions modify the data as well as make sure that the data that is copied is logically consistent with the original table and does not contain partial updates. Please see the Locking and Concurrency topic for more information.

Copying a Table
To copy a table, you must specify the DatabaseName and TableName properties of the TDBISAMTable component and then call the CopyTable method. The table can be open or closed when this method is called, and the table does not need to be opened exclusively (Exclusive property=True). If the table is closed when this method is called, then the DBISAM engine will attempt to open the table before copying it. It is usually good practice to also examine the Exists property of the TDBISAMTable component first to make sure that you don't attempt to copy a non-existent table. If you do attempt to copy a non-existent table an EDBISAMEngineError exception will be raised. The error code given when copying a table fails due to the table not existing is 11010 and is defined as DBISAM_OSENOENT in the dbisamcn unit (Delphi) or dbisamcn header file (C++).

The following example shows how to copy the "customer" table to the "newcust" table in the same database directory using the CopyTable method:

{
   MyTable->DatabaseName="d:\\temp";
   MyTable->TableName="customer";
   if (MyTable->Exists)
      {
      MyTable->CopyTable("d:\\temp","newcust");
      }
}

Information When copying tables in a local session, you must specify the first database name parameter to the CopyTable method as a local database directory. When copying tables in a remote session, you must specify the first database name parameter to the CopyTable method as a database defined on the database server. You cannot copy tables on a database server to local tables or vice-versa. Please see the DBISAM Architecture topic for more information.

The CopyTable operation can also be performed on a table that is already open and has a range or filter set. This is useful for limiting the copied records to a certain criteria. Please see the Setting Ranges on Tables and Setting Filters on Tables and Query Result Sets topics for more information.

Tracking the Copy Progress
To take care of tracking the progress of the copy we have provided the TDBISAMTable OnCopyProgress event.
Image