Try OpenEdge Now
skip to main content
Programming Interfaces
Audit Policy Maintenance APIs : Generic utility API : update-auditing-policies procedure
 

update-auditing-policies procedure

Saves the audit policy changes tracked in a specified ProDataSet object into a specified target database. The caller should check the ProDataSet and buffer's ERROR attribute for any error conditions and the buffer's ERROR-STRING for error messages.
Parameters:
INPUT pcDbInfo AS CHARACTER
Database information string specifying the target database to save the changes.
INPUT-OUTPUT DATASET-HANDLE phDataset
ProDataSet with the tracked changes.
Note: This procedure calls the _update-policies.p external procedure, which automatically refreshes the database cache by calling the AUDIT-POLICY:REFRESH-AUDIT-POLICY() method.
Example:
The following example is a combination of pseudo-code and ABL that shows how to run this procedure:

Calling the update-auditing-policies API procedure

{auditing/include/_aud-utils.i}

DEFINE VARIABLE cStatus    AS CHARACTER NO-UNDO.
DEFINE VARIABLE errorMsg   AS CHARACTER NO-UNDO.
DEFINE VARIABLE hBuffer    AS HANDLE    NO-UNDO.
DEFINE VARIABLE hDSChanges AS HANDLE    NO-UNDO.
DEFINE VARIABLE hQuery     AS HANDLE    NO-UNDO.
DEFINE VARIABLE ix         AS INTEGER   NO-UNDO.

/* Turn tracking-changes off for now */
RUN set-tracking-changes (FALSE).

/* Create a ProDataSet with the changes before sending it to the other
   procedure */
CREATE DATASET hDSChanges.
hDSChanges:CREATE-LIKE(hAuditDset).
hDSChanges:GET-CHANGES(hAuditDset). /* Get the changes */
ASSIGN errorMsg = "".

/* Call the generic procedure passing our local ProDataSet */
RUN update-auditing-policies IN hAuditUtils (INPUT cDbInfo,
  INPUT-OUTPUT DATASET-HANDLE hDSChanges BY-REFERENCE).
ASSIGN errorMsg = RETURN-VALUE.

/* Turn tracking changes back on */
RUN set-tracking-changes (TRUE).

/* Check the ERROR status that might have been returned. */
IF errorMsg = "":U AND hDSChanges:ERROR THEN DO:
  /* There was an error somewhere in the updates. Find it. */
  DO ix = 1 TO hDSChanges:NUM-BUFFERS.
    CREATE QUERY hQuery.
    hBuffer = hDSChanges:GET-BUFFER-HANDLE(ix):BEFORE-BUFFER.
    hQuery:ADD-BUFFER(hBuffer).
    hQuery:QUERY-PREPARE("FOR EACH " + hBuffer:NAME).
    hQuery:QUERY-OPEN().
    hQuery:GET-FIRST().

    DO WHILE NOT hQuery:QUERY-OFF-END:
      IF hBuffer:ERROR THEN
        cStatus = cStatus + hBuffer:ERROR-STRING + CHR(10) NO-ERROR.
      hQuery:GET-NEXT().
    END.
    hQuery:QUERY-CLOSE().
    DELETE OBJECT hQuery.
  END.
END.

/* delete the ProDataSet with changes */
DELETE OBJECT hDSChanges.
IF errorMsg <> "":U THEN
  RETURN errorMsg.

IF cstatus = "" THEN
  /* If no errors so far, accept all the changes */
  hAuditDset:ACCEPT-CHANGES().
ELSE
  RETURN cStatus.