Events for cDbUpdateHandler

Name

Description

OnPreUpdate

Event called before any update of the database is started. This is a programmer's hook event. Can be used to create an SQL database (not table).

OnPostUpdate

Event that is called after all database updates have finished. This is a programmer's hook event.

OnFindVersionRecord

Hook message for custom DbVersion record find. The programmer can use this event for putting code that needs to be executed to find a *custom* DbVersion table record - aka when another table should be used in place of the standard DbVersion table. By default the DbVersion table is used but this can be customized by adding this line to the code;

"Define DUF_Use_Custom_DbVersion"

above the line;

"Use cDbUpdateHandler.pkg"

OnErrorWriteHeader_DataTable

Hook event for writing header error text (pre-update) to a data table, instead of the default text-log file. Only called if the pbUseDataTable property = True. Don't forget to Open the table first (!) as all tables have been closed at this stage. The start date & time is passed.

OnErrorWriteRow_DataTable

Hook event to log errors to a database table. Only called if the pbUseDataTable = True. Don't forget to Open the table first (!) as all tables have been closed at this stage. If pbQuickWrite = True the passed DbUpdateErrorArray will contain just one row, as it is called for each error that occurred. Else it is called once at the end after all updates have run and contains all errors.


Sample Code


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


    // You can create a database prior making any updates in case it doesn't exist:

    // Note: This option is only available for MS-SQL.

    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        


    // To find a database version record if the standard DbVersion table

    // should *not* be used. You can here use your own table logic.

    Procedure OnFindVersionRecord

        Open MyTable

        Move xx to MyTable.Column1

        Move yy to MyTable.Column2

        Find LE MyTable by Index.1

    End_Procedure        

    // Called once when the update begins.

    Procedure OnErrorWriteHeader_DataTable DateTime dtUpdateStart

        Open MyLogTable

        Move dtUpdateStart to MyLogTable.UpdateStart

        Saverecord MyLogTable

    End_Procedure


    // Called once after all updates have finished if pbQuickWrite=False. If pbQuickWrite=True it is called once for each error.

    Procedure OnErrorWriteRow_DataTable tDbUpdateError[] DbUpdateErrorArray

        Integer iSize iCount

        Open MyLogTable

        Move (SizeOfArray(DbUpdateErrorArray)) to iSize

        Decrement iSize

        For iCount from 0 to iSize

            Clear MyLogTable

            Move DbUpdateErrorArray[iCount].iError to MyLogTable.ErrorNo

            Move DbUpdateErrorArray[iCount].sErrorText to MyLogTable.ErrorText

            SaveRecord MyLogTable

        Loop

    End_Procedure


...


NOTE:

Struct tDbUpdateError

    Number  nUpdateVersion

    Integer iError

    String  sErrorText

    Integer iErrorLine

    Boolean bError

End_Struct