COPY_DATA

Applies to: ORAFlex SQLFlex MYSQLFlex PGFlex DB2Flex

This command is used to copy data from a DAT file to an SQL table. Both the source and the destination files are opened, the data is copied and then the files are closed. This is usually used along with CREATE_TABLE_FROM_DAT_FILE, which creates the structure and then this command will insert the data. If needed, this command can also work backwards, copying data from an SQL table to a DAT file. This is an alternative to using the Flex2SQL Migration Tool and can improve performance when used in the right situations. Note that in order for this process to work properly the table being copied can not be opened. Because of this, a manual login must take place, using something like LOGIN_SQLFLEX or LOGIN. Since this only copies the data, CREATE_TABLE_FROM_DAT_FILE can be used to create the table structure.

Because COPY_DATA requires no user interaction, an optional callback function can be passed for tracing purposes. By passing the constant “CALLBACK” followed by the object name, a function can be used to set up messages for tracking and error handling. Below is more information regarding this callback object.

This function should follow this pattern:

Function Callback String sText Integer iStatusID Returns Integer

sText - Message corresponding to the current status ID

iStatusID - Integer value mapping to the current status constant: DF_MESSAGE_PROGRESS_TITLE Sent when SQLFlex starts the process

DF_MESSAGE_HEADING_1 Sent when SQLFlex is about to copy the source data

DF_MESSAGE_ERROR Sent when an error occurs

DF_MESSAGE_PROGRESS_STATUS Sent each time an additional 10% of the data is copied

NOTE: Returning false each time the function is called will continue copying process. Returning true will end it.

Another optional parameter that can be used is a constrain on the data being copied. This is done by passing the constant “CONSTRAIN” followed by an SQL constrain statement. When passing a constrain but not a callback object, pass 0 for the callback before passsing the constrain.

Syntax

COPY_DATA {from} to {destination} [CALLBACK {function}] [CONSTRAIN {variable}]

Parameter

Description

from

Table to copy from.

destination

Table to copy to.

function

Object with callback function (optional)

variable

SQL contraint to use when copying (optional)

Example

Object CallBackObj is a Array
    Function Callback String sText Integer iLogicalID Returns Integer
        If (iLogicalID = DF_MESSAGE_ERROR) Begin
            Showln "Error"
            Showln sText
            Function_Return True
        End

        Else Showln sText

        Function_Return False

    End_Function
End_Object

Login "localhost" "user" "pass123" "sql_drv"
CREATE_TABLE_FROM_DAT_FILE Customer.File_Number "Customer"
COPY_DATA "Customer" to "sql_drv:Customer" CALLBACK (Callback(Self)) CONSTRAIN "STATUS = 'Active'"