Class: cDbUpdateHandler

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: cDbUpdateHandler.pkg

Note: If using Mertech drivers, put the line "Define DUF_Use_Mertech_Drivers" above the "Use cDbUpdateVersion.pkg"


Description

The cDbUpdateHandler is a container object that holds one or more cDbUpdateVersion objects. The object should contain a Set Data_File_Field setting that specifies the data table name and field/column name to save the database update version to. This value gets updated automatically by the child cDbUpdateVersion objects after each successful update has been run. See the cDbUpdateVersion class for more info.


It also automatically instantiate all of the other classes of the framework. This means most of the properties of the other classes can be get/set directly in the cDbUpdateHandler object and it will "relay" that information to the correct object/class.


It is highly recommended to put all database update code in your main program. The reason is that the framework automatically locks others out of the program while the framework is doing its job. But that checking can only be performed if the same (main) program is started by another user during an update. However, you can of course put all update code in a separate package that is used (included) in your main program, right after the cApplication object.



Sample Code 1


Object oDbUpdateHandler is an cDbUpdateHandler
     Set Data_File_Field to File_Field DbVersion.DatabaseVersion
   

    Object oUpdateVersion1.1 is a cDbUpdateVersion
        Set pnVersionNumber to 1.1


        Declare_DataFile MyTable // To satisfy the compiler.

        Procedure OnUpdate

            Boolean bOK

            // Write your update code here:

        End_Procedure
        :
    End_Object
 
    Object oUpdateVersion1.2 is a cDbUpdateVersion
        Set pnVersionNumber to 1.2
        Use VersionUpdate2.pkg
        :
    End_Object
 
End_Object


Sample Code 2


Object oDbUpdateHandler is an cDbUpdateHandler
    Set Data_File_Field to File_Field DbVersion.DatabaseVersion


    // Optionally you can create an SQL database with this event:

    Procedure OnPreUpdate

        Boolean bOK

        Get SqlDatabaseCreate MSSQLDRV_ID "OrderEntry" True True to bOK

        If (bOK = False) Begin

            Send Info_Box "Nope, that didn't work. Program will now exit."

            Send Exit_Application

        End

    End_Procedure        
 
    Object oDbUpdateVersion1.1 is a cDbUpdateVersion

        Set pnVersionNumber to 1.1

        // Put your code in the OnUpdate event

        Declare_Datafile SalesP

        Declare_Datafile Customer

        Procedure OnUpdate

            Boolean bOK

            Get ApiTableConvertToSQL_Ex SalesP.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 2 True "1" to bOK

        End_Procedure
    End_Object
 
    Object oDbUpdateVersion1.2 is a cDbUpdateVersion
        Set pnVersionNumber to 1.2

        // ...or put your update code in a separate package:
        Use DbUpdateVersion2.pkg
        :
    End_Object
 
End_Object


Next Topic


cDbUpdateVersion