Copy_DB
See Also: Implementing Callback Functions, Copy_Records, Delete_db, Zerofile
Purpose
The Copy_db command is used to copy a database table to or from a client or a server, or from one folder to another.
Syntax
Copy_db {source-table} to {dest-table} [Callback {callback-object}] ;
[Compression {compression-type}]
Argument Explanation
- {source-table}: The name and path of the database table to be copied.
- {dest-table}: The name and path that the database table is copied to.
- {callback-object}: A handle to an object that will receive the Callback message during the copy operation. Refer to Implementing Callback Functions for more information.
- {compression-type}: Indicates the form of file compression that will be used to save the destination table. The compression used in the source file has no bearing on what compression is used in the copy. The valid types are:
DF_FILE_COMPRESS_NONE: No data compression.DF_FILE_COMPRESS_FAST: Uses run-length encoding.DF_FILE_COMPRESS_STANDARD: Uses compression based on the relative frequency of characters in a typical DataFlex file.
What It Does
Copy_db copies the database file (.DAT, .VLD [if any], .TAG, and .K files) identified by {source-table} from the source folder to the destination as specified in the command.
This command will not execute if {source-table} or {dest-table} is open to the user executing this command (they are allowed to be open to other users, however).
Copy_db works by calling the Copy_Records command. All records in the {source-table} are copied to the {dest-table} in record-number order.
Usage of the callback object is exactly as described for Copy_Records. Copy_db, however, can create a destination file where none previously exists. Copy_Records does not do this.
Examples
-
In the following example, the database table Vendor is copied to the database table Vendor2.
Copy_db "demo/vendor" to "vendor2" -
In this example,
sPhysNamewill be copied to the root folder of drive C:String sPhysName sFileDriver String sDestination Integer iCompressionType Close DF_All // to be sure all tables are closed Get_Attribute DF_FILE_PHYSICAL_NAME of Customer.File_Number to sPhysName Get_Attribute DF_FILE_COMPRESSION of Customer.File_Number to iCompressionType Get_Attribute DF_FILE_DRIVER of Customer.File_Number to sFileDriver Showln "File " sPhysName " (" sFileDriver ") with compression " iCompressionType " will be copied." Move (sFileDriver+":C:\CopyOfFile") to sDestination Copy_DB sPhysName To sDestination CallBack 0 Compression iCompressionType Showln "End of Copying Process."
Notes
-
This command neither uses nor changes any file list. All database tables must be identified by their folder root names.
-
If {dest-table} already exists and has one or more fields whose name matches one in the source table, records from the source table will be appended to the records already present. If any copied record contains a field value matching the value in any other record in the destination table and the field participates in an online unique index, Error 28 (Duplicate records not allowed in file) will be returned, and the record will not be copied.
-
The callback message is sent each time the number of records in the global attribute DF_RUNTIME_PROGRESS_FREQUENCY is copied, with parameters indicating the number of records copied and the total number of records to be copied.