ApiTableConvertToSQL - cDbUpdateFunctionLibrary

 To convert an embedded table (DataFlex .dat file) for the current workspace (Filelist.cfg) to an SQL database back-end. The target is the database that has been set as the "enabled" connection with the SQLConnections tool or with the DataFlex "SQL Connection Manager" program if DataFlex 19.0 or later.


Type: Function


Parameters: Handle hTable

Parameter

Description

hTable

A file handle to the table name. Same as the Filelist.cfg slot number.


Syntax


Function ApiTableConvertToSQL Handle hTable

Call:

Get ApiTableConvertToSQL OrdHea.File_Number to bOK



Description

Use it to convert a table to SQL. The file handle is the same as the file number in Filelist.cfg. You cannot use this method for converting between two SQL databases. If you need to convert from SQL -> SQL you must first use the SQLTableConvertToEmbedded function to convert the table to embedded (DataFlex).

It will not convert an embedded table to SQL that already exists on the SQL back-end. You need then instead use the ApiTableAttachToSQL function. The reason for this is that the framework has re-entrance enabled - meaning that it should be able to run the same code twice by resetting the pnVersionNumber value without bringing mayhem to the SQL database.

Note: You must have setup a SQL connection for the workspace with the help of the Database Update Framework's SQLConnections tool. Or have setup a Maintained connection, if using DataFlex 19 or later. Important to note is that if you have setup an SQL connection with a maintained connection and you are using another SQL back-end then Microsoft SQL Server you must setup additional properties in the cDbUpdateVersion object, or by also creating an SQL connection record with the SQLConnection tool.


There is a variant of this function where you - instead of setting a series of properties - pass them on as parameters. See: ApiTableConvertToSQL_Ex


Example 1


// This sample is for a Microsoft SQL Server

Object oDbUpdateVersion1 is a cDbUpdateVersion

    Set pnVersionNumber to 1.0

    Set pbCopyData to True // True=Default

    Set pbRecnum   to True // True=Default

    Set pbToAnsi   to True // True=Default

    Set pbUseConnectionID to True // True=Default


    Procedure OnUpdate

        Boolean bOK

        Get ApiTableConvertToSQL Customer.File_Number to bOK

    End_Procedure


End_Object



Example 2


// This sample is for an IBM DB2 database

Object oDbUpdateVersion2 is a cDbUpdateVersion

    Set pbCopyData to True // True=Default

    Set pbRecnum   to True // True=Default

    Set pbToAnsi   to True // True=Default

    Set pbUseConnectionID to True // True=Default

    Set psBaseTableSpace to "USERINFO1"

    Set psIndexTableSpace to "USERINFO1"

    Set psLongTableSpace to "USERINFO1"

    Set psSchema to "DBO"

   

    Procedure OnUpdate

        Boolean bOK

        Get ApiTableConvertToSQL OrdHea.File_Number to bOK

    End_Procedure


End_Object