project BLF > class BCustomField > method PostSave

Description

Actions to take after writing current instance to the database, and before final commit of the transaction.
Use the field tc_status to test the status of the updated records:
'' = unchanged
'N' = new
'C' = changed
'D' = deleted


Parameters


oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bcustomfield.p)

<ANCESTOR-CODE>

if vlAlsoDeleteCustomFieldData
then for each tCustomField where tCustomField.tc_Status = "D" on error undo, throw:

    /* not a database table */
    if tCustomField.CustomFieldFieldName begins "tCustomTable" then next.
    
    assign vcTable = substring(entry(1,tCustomField.CustomFieldFieldName,".":U),2,-1,"CHARACTER":U)
           vcField =           entry(2,tCustomField.CustomFieldFieldName,".":U).

    vcQuery = "for each ":U + vcTable + " where ":U + vcTable + ".":U + vcField + " <> ?":U.
    
    if vcField begins "CustomInteger":U
    or vcField begins "CustomDecimal":U
    then assign vcQuery = vcQuery + " and ":U + vcTable + ".":U + vcField + " <> 0":U
                vcEmpty = "0"
                vcDType = "i".
    else
    if vcField begins "CustomDate":U
    then assign vcEmpty = "?"
                vcDType = "t".
    else assign vcQuery = vcQuery + " and ":U + vcTable + ".":U + vcField + " <> ''":U
                vcEmpty = ""
                vcDType = "c".
    
    <M-25 run StartPersistence
       (output vhFcComponent (ohPersistence), 
        output viFcReturnSuper (oiReturnStatus)) in BCustomField>
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.

    <M-54 run WriteDirect
       (input  vcTable (icTableName), 
        input  vcQuery (icPrepare), 
        input  vcField (icFieldList), 
        input  vcDType (icFieldListDataTypes), 
        input  vcEmpty (icAbsolute), 
        input  '' (icIncremental), 
        input  {&TARGETPROCEDURE} (ihClass), 
        input  vcUserLogin (icUserLogin), 
        output viFcReturnSuper (oiReturnStatus)) in persistence>
    if viFcReturnSuper = -4 then viFcReturnSuper = 0.
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.
end.

for each tCustomField where tCustomField.tc_Status = "D" on error undo, throw:

    /* ================================================================= */
    /* Remove this custom field from any UI.                             */
    /* ================================================================= */
    <I-48 {bFcStartAndOpenInstance
         &CLASS                = "BControlProperty"}>
    <M-45 run RemoveCustomFieldFromUI
       (input  tCustomField.CustomFieldFieldName (icCustomFieldName), 
        output viFcReturnSuper (oiReturnStatus)) in BControlProperty>
    <I-93 {bFcCloseAndStopInstance
         &CLASS           = "BControlProperty"}>
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.
end.