Programming Guide |
Compares widgets in the current table view with their before-image values
#include <tmusubs.h>int sm_bi_compare(void);
DM_TM_ERR_GENERAL
if no transaction or table view is available.
- Success—one of the following constants:
- ·
BI_UNCHANGED
: Occurrence was not changed.
- ·
BI_DELETED
: Occurrence was deleted.
- ·
BI_INSERTED
: Occurrence was inserted.
- ·
BI_KEY_NULLED
: A primary key field in the occurrence was cleared or set toNULL
.
- ·
BI_KEY_CHANGED
: A primary key field in the occurrence was changed to a non-NULL
/non-empty value.
- ·
BI_UPDATED
: A non-primary key field in the occurrence was changed.
sm_bi_compare
compares an occurrence value with its before-image and returns a code indicating the status of the comparison. Comparison codes are listed above.The occurrence is the current occurrence number as determined by sm_tm_inquire
("TM_OCC")
. A positive occurrence number indicates an onscreen occurrence. A negative occurrence number indicates a deleted occurrence; an occurrence is deleted by the logical key DELL or by a call to sm_i_doccur.In the standard transaction models, the requests
TM_INSERT
,TM_UPDATE
, andTM_DELETE
each callsm_bi_compare
. This allows the model to choose the appropriate processing for a changed occurrence.A special case exists when a row's primary key value is set to empty or
NULL
. The program can do this in one of the following ways:
In the standard models both the
TM_DELETE
andTM_INSERT
requests test forBI_KEY_CHANGED
and both perform processing for this change. Therefore, if a primary key value changes, the standard models delete the occurrence using the before-image value of the primary key and insert a new occurrence using the onscreen value of the primary key. The model may be changed so thatTM_UPDATE
handles all updates, including primary key changes.This function operates on the current table view. It is intended to be called from a transaction model or event function.
/* The following example taken from the standard
transaction model for JDB shows the processing for the
TM_UPDATE request. */case TM_UPDATE:
/* Do nothing, except for updates */
occ_type = sm_bi_compare();
if (occ_type != BI_UPDATED)
{
break;
}if (!reuse_cursor)
{
save_cursor_type = 0;
}
reuse_cursor = 0;sm_tm_push_model_event(TM_UPDATE_EXEC);
sm_tm_push_model_event(TM_UPDATE_DECLARE);
sm_tm_push_model_event(TM_GET_SAVE_CURSOR);
break;