Guardian Programmer's Guide

Table Of Contents
Communicating With Processes
Guardian Programmer’s Guide 421922-014
6 - 59
Programming the Server
!------------------------------------------------------------
! Procedure for updating a record. The procedure first
! reads the record from the data file and checks it against
! the original value received by the requester to make sure
! it has not been updated by another user.
! The procedure then writes the updated record to the file.
!------------------------------------------------------------
PROC UPDATE^RECORD;
BEGIN
INT COUNT^READ;
INT ERROR;
STRUCT .SAVE^REC(PART^RECORD);
STRUCT .CHECK^REC(PART^RECORD);
! Position exactly to the selected record.
CALL KEYPOSITION(PARTFILE^NUM,
REQUEST.PART.PART^NUMBER,
!key^specifier!,
!length^word!,
2);
IF <> THEN CALL FILE^ERRORS(PARTFILE^NUM);
! Read the selected record. If no such record exists,
! the procedure sets the reply error to the file system
! error number and returns to the main procedure:
CALL READUPDATELOCKX(PARTFILE^NUM,PART^RECORD,
$LEN(PART^RECORD));
IF <> THEN
BEGIN
CALL FILE_GETINFO_(PARTFILE^NUM,REPLY^ERROR);
RETURN;
END;
! Check that the record just read is identical to the record
! read earlier in the update record sequence. If not,
! return with REPLY^ERROR set to 300:
IF PART^RECORD <> REQUEST.OLD^PART FOR
$LEN(PART^RECORD) BYTES THEN
BEGIN
CALL UNLOCKREC(PARTFILE^NUM);
REPLY^ERROR := 300;
RETURN;
END;