project BLF > class Persistence (other) > method WriteDirect

Description

Write directly to the database, without using any temp-tables, without optimistic lock.
Cannot be used to create data in the database.

PostCondition

Unless run inside a larger transaction (when run from methods PreSave or PostSave) every database record that matches the search criteria will be updated in it's own transaction. This means there is no transaction undo in case an error occurs during update, but this was necessary to prevent a lock table overflow on updates that can potentially update very large record sets.


Parameters


icTableNameinputcharacterDatabase table name
icPrepareinputcharacterProgress for each statement defining what record(s) must be updated.
icFieldListinputcharacterComma seperated list of field names to update.
If this list is empty, the record(s) to update will be deleted.
icFieldListDataTypesinputcharacterComma seperated list of data type of each field in icFieldList.

data type =
c (character)
d (decimal)
i (integer)
l (logical)
t (date)
icAbsoluteinputcharacterchr(2) seperated list of absolute values to write to the fields of icFieldList. The same value(s) will be written to each record to update.
Cannot be combined with icIncremental.
icIncrementalinputcharacterchr(2) seperated list of values to add to the fields of icFieldList. The same value(s) will be added in each record to update.
Fields to update are restricted to data types integer and decimal.
Cannot be combined with icAbsolute.
ihClassinputhandleHandle to the class that is using the persistence layer. In most of the cases, this handle will be available in the preprocessor {&TARGETPROCEDURE}.
icUserLogininputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program1/other.p)

if icIncremental <> ""
then do:
    <M-4 run ReadDirect (input  icTableName (icTableName), 
                     input  icPrepare (icPrepare), 
                     input  icFieldList (icFieldList), 
                     output vcCurrentValues (ocValueList), 
                     input  ihClass (ihClass), 
                     output oiReturnStatus (oiReturnStatus)) in other>
    if oiReturnStatus <> 0
    then return.
end.

&if defined(DEBUGSQL) > 0 &then
run SqlDebugWrite in {&TARGETPROCEDURE} ("* ":U + program-name(1), 1).
&endif

run SqlBufCreate in {&TARGETPROCEDURE}
   (input icTableName,
    output viBufferId,
    output oiReturnStatus).
if oiReturnStatus <> 0
then do:
    <M-1 run SqlErrorMessage (input  ihClass (ihClass), 
                          output viFcReturnSuper (oiReturnStatus)) in other>
    return.
end.

do viCnt = 1 to num-entries(icFieldList):

    case entry(viCnt,icFieldListDataTypes):

    when "c":U
    then do:
        run SqlBufAddField in {&TARGETPROCEDURE}
           (input viBufferId,
            input entry(viCnt,icFieldList),
            input "character":U,
            input 0,
            output viFieldId,
            output oiReturnStatus).
        if oiReturnStatus = 0
        then run SqlFldSetString in {&TARGETPROCEDURE}
                (input viBufferId,
                 input viFieldId,
                 input 1,
                 input entry(viCnt,icAbsolute,chr(2)),
                 output oiReturnStatus).
    end.

    when "d":U
    then do:
        run SqlBufAddField in {&TARGETPROCEDURE}
           (input viBufferId,
            input entry(viCnt,icFieldList),
            input "decimal":U,
            input 0,
            output viFieldId,
            output oiReturnStatus).
        if oiReturnStatus = 0
        then do:
            if icIncremental = ""
            then vdValue = decimal(entry(viCnt,icAbsolute,chr(2))).
            else vdValue = decimal(entry(viCnt,vcCurrentValues ,chr(2)))
                         + decimal(entry(viCnt,icIncremental,chr(2))).
            run SqlFldSetDecimal in {&TARGETPROCEDURE}
               (input viBufferId,
                input viFieldId,
                input 1,
                input vdValue,
                output oiReturnStatus).
        end.
    end.

    when "i":U
    then do:
        run SqlBufAddField in {&TARGETPROCEDURE}
           (input viBufferId,
            input entry(viCnt,icFieldList),
            input "integer":U,
            input 0,
            output viFieldId,
            output oiReturnStatus).
        if oiReturnStatus = 0
        then do:
            if icIncremental = ""
            then viValue = integer(entry(viCnt,icAbsolute,chr(2))).
            else viValue = integer(entry(viCnt,vcCurrentValues ,chr(2)))
                         + integer(entry(viCnt,icIncremental,chr(2))).
            run SqlFldSetInteger in {&TARGETPROCEDURE}
               (input viBufferId,
                input viFieldId,
                input 1,
                input viValue,
                output oiReturnStatus).
        end.
    end.

    when "l":U
    then do:
        run SqlBufAddField in {&TARGETPROCEDURE}
           (input viBufferId,
            input entry(viCnt,icFieldList),
            input "logical":U,
            input 0,
            output viFieldId,
            output oiReturnStatus).
        if oiReturnStatus = 0
        then run SqlFldSetLogical in {&TARGETPROCEDURE}
                (input viBufferId,
                 input viFieldId,
                 input 1,
                 input (entry(viCnt,icAbsolute,chr(2)) = "TRUE":U),
                 output oiReturnStatus).
    end.

    when "t":U
    then do:
        run SqlBufAddField in {&TARGETPROCEDURE}
           (input viBufferId,
            input entry(viCnt,icFieldList),
            input "date":U,
            input 0,
            output viFieldId,
            output oiReturnStatus).
        if oiReturnStatus = 0
        then do:
            vtemp = date(integer(substring(entry(viCnt,icAbsolute,chr(2)),5,2,"CHARACTER":U)),
                         integer(substring(entry(viCnt,icAbsolute,chr(2)),7,2,"CHARACTER":U)),
                         integer(substring(entry(viCnt,icAbsolute,chr(2)),1,4,"CHARACTER":U))).
            run SqlFldSetInteger in {&TARGETPROCEDURE}
               (input viBufferId,
                input viFieldId,
                input 1,
                input integer(vtemp),
                output oiReturnStatus).
        end.
    end.

    otherwise return.

    end case.

    if oiReturnStatus <> 0
    then do:
        <M-2 run SqlErrorMessage (input  ihClass (ihClass), 
                              output viFcReturnSuper (oiReturnStatus)) in other>
        return.
    end.
end.

run SqlBufWriteDirect in {&TARGETPROCEDURE}
   (input viBufferId,
    input icPrepare,
    output oiReturnStatus).
if oiReturnStatus <> 0
then do:
    <M-3 run SqlErrorMessage (input  ihClass (ihClass), 
                          output viFcReturnSuper (oiReturnStatus)) in other>
end.