Class: cDbUpdateVersion

See Also: Overview of the DataFlex Database Update Framework


Properties  Events  Methods


Hierarchy

cObject
---cDbUpdateHandler
------cDbUpdateVersion
------cDbUpdateFunctionLibrary
------cDbUpdateLogFile
------cDbUpdateUserCount
------cSQLConnectionHandler
---------cSQLConnectionIniFile
---------cDbUpdateDatabaseDriver



Library: Windows Application Class Library


Package: cDbUpdateVersion.pkg


Description


This is a child class of the cDbUpdateHandler class. 

Put an object of this class inside the cDbUpdateHandler object. Set the pnVersionNumber to a consecutive database version number. Place your update code in the OnUpdate event to alter the database.

Add one cDbUpdateVersion object for each update of the database and specify its database version by setting the pnVersionNumber property.


To aid when adding database update code for the OnUpdate event the function library cDbUpdateFunctionLibrary has been imported to the cDbUpdateHandler class, thus making all those functions easily accessible from within the OnUpdate event. The library contains a whole range of functions for easy manipulation of the database and it can be expanded by the developer if needed.

See cDbUpdateHandler for more info about the container object.

See cDatabaseFunctionsLibrary for more info about all functions available to this class, including specialized SQL functions.


Important


The order of each cDbUpdateVersion objects is important and the pnVersionNumber for each and one of them *must* be consecutive! So a cDbUpdateVersion object with a pnVersionNumber = 1.5 must come after (below) a cDbUpdateVersion object with a pnVersionNumber = 1.4 setting, or the "pnVersionNumber = 1.4" object's Update code won't get executed.


Note


When converting embedded tables to SQL there are two different interfaces; one geared at being more Object Oriented and the other is a function that takes on a series of parameters to do the same thing. Compare below the 1.0 example that uses the ApiTableConvertToSQL function and also sets a series of object properties - versus - the 1.1 sample that uses the ApiTableConvertToSQL_Ex (Extended) function to do it all in one line of code. The reason here being that if e.g. the DB2 database is used there are a lot of more info that is needed for the conversion process to succeed.



Sample


// These are needed to keep the compiler happy;

Declare_Datafile Customer

Declare_Datafile Invt

Declare_Datafile OrderDtl

Declare_Datafile OrderHea

Declare_Datafile OrdSys

Declare_Datafile SalesP

Declare_Datafile Users

Declare_Datafile Vendor


Object oDbUpdateHandler is an cDbUpdateHandler
    Set


    Object oUpdateVersion1 is a cDbUpdateVersion
        Set pnVersionNumber to 1
        Set pbUseConnectionID to True

        Set pbCopyData to True

        Set pbRecnum to True

        Set pbToANSI to True

        // If the psDriverID is not set it is read from the SQLConnections.ini file.

       

        // Add update code to the OnUpdate event

        Procedure OnUpdate

            Boolean bOK

            Get ApiTableConvertToSQL Invt.File_Number       to bOK

            Get ApiTableConvertToSQL OrderHea.File_Number   to bOK

            Get ApiTableConvertToSQL OrderDtl.File_Number   to bOK

            Get ApiTableConvertToSQL OrdSys.File_Number     to bOK

            Get ApiTableConvertToSQL SalesP.File_Number     to bOK

            Get ApiTableConvertToSQL Vendor.File_Number     to bOK

        End_Procedure

    End_Object
 
    Object oDbUpdateVersion2 is a cDbUpdateVersion

        Set pnVersionNumber to 2


        Procedure OnUpdate

            Boolean bOK

            // Alternate table conversion function that instead of setting properties like in

            // above passes a series of parameters.

            Get ApiTableConvertToSQL_Ex Users.File_Number MSSQLDRV_ID True True True True to bOK

           

            Get SQLColumnRename Customer.File_Number "Purchases" "YearlyPurchases" MSSQLDRV_ID to bOK

            Get SQLColumnAdd Customer.File_Number "IsPrinted" DF_BCD_DUF 4 0 True "1" to bOK

        End_Procedure
    End_Object


    Object oUpdateVersion3 is a cDbUpdateVersion
        Set pnVersionNumber to 3
        Use VersionUpdate3.pkg
        :
    End_Object
 
End_Object



Next Topic


cDbUpdateFunctionLibrary