Kbase P104146: How to handle data conversions during SAVE-ROW-CHANGES() operations ?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  19/11/2009 |
|
Status: Verified
GOAL:
How to handle data conversions during SAVE-ROW-CHANGES() operations ?
GOAL:
How to set up validation logic for ProDataSets
GOAL:
Are there ProDataSet events that fire during SAVE-ROW-CHANGES() ?
FACT(s) (Environment):
OpenEdge 10.0x
All Supported Operating Systems
FIX:
Enhancement Request# 20050512-006
Currently there is no way to ensure validation and data conversion/encryption logic gets executed automatically when the SAVE-ROW-CHANGES() method is called.
It is not possible to use callback procedures for this as there are no appropriate events to attach the callback procedures to.
Thus, anything that isn't automatically handled by the SAVE-ROW-CHANGES() method will have to be coded manually.
The enhancement request was logged to request a BEFORE-ROW-SAVE and AFTER-ROW-SAVE event, having these events would allow callback procedures to be used.
To manually check and update the database table, it is possible to rely on the data-source:SAVE-WHERE-STRING attribute and to use this to fetch the record in the data-source.
Note that if the SAVE-ROW-CHANGES() fails, the data in the ProDataSet's BEFORE-TABLE should be used to look up the data-source's record. However, if it is successful, the ProDataSet's AFTER-TABLE data should be used to fetch the data as the data-source's record will now match that.
The following code snippet will illustrate how this can be achieved.
Note that this is by no means complete code and that it will have to be modified as the situation demands.
DEFINE VARIABLE i_bufbf AS HANDLE NO-UNDO. /* handle to data-set before-buffer */
DEFINE VARIABLE param i_src AS HANDLE NO-UNDO. /* handle to data-source to be used */
/* use these to track if save-row-changes() succeeded */
DEFINE VARIABLE lSaved AS LOGICAL NO-UNDO.
DEFINE VARIABLE cFindByBefore AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFindByAfter AS CHARACTER NO-UNDO.
/* Code to set the handles goes here */
ASSIGN cFindByBefore = i_src:SAVE-WHERE-STRING(1)
cFindByAfter = REPLACE(cFindByBefore,i_bufbf:NAME + ".",i_bufbf:AFTER-BUFFER:NAME + ".").
i_bufbf:FIND-FIRST().
i_src:GET-SOURCE-BUFFER(1):FIND-FIRST(cFindByBefore).
/* validations to be done before the save-row-changes() go here */
DO TRANSACTION:
lSaved = i_bufbf:SAVE-ROW-CHANGES().
/* if save-row-changes was successful, use the AFTER-BUFFER to look up the data as before-buffer
will not be in sync with data source */
IF lSaved THEN DO:
i_bufbf:AFTER-BUFFER:FIND-BY-ROWID(i_bufbf:AFTER-ROWID).
i_src:GET-SOURCE-BUFFER(1):FIND-FIRST(cFindByAfter).
/* Code to update data-source if changes were saved goes here */
END.
ELSE DO:
i_src:GET-SOURCE-BUFFER(1):FIND-FIRST(cFindByBefore).
/* Code to handle errors etc. if changes were NOT saved goes here */
END.
END.