lock_row

Locks the current window list row for update in the database.

Available in:

Apps (win) Apps (char) Reportwriter RPC Standalone PL
X X X X X

Syntax

int lock_row(table-name,row-id,update[,original])
ident        table-name
expr         row-id
int          update
list         original

Description

Locks the specified row. Returns status as:
table-namespecifies the database table.
row-idspecifies the row in the database table.
updateIf update is true, then the item's original value (previously saved) is compared to the current value in the database. If these values do not match, the following status is returned:
0Lock succeeded
1Could not acquire lock
2Database row has been modified since it was read into the window list
original(optional) must be a list in which the current database values for columns without the NOUPDATE attribute are placed. The lock_row() function uses these values internally to compare to the shadow values.

Notes

TRIMpl uses optimistic locking, only locking a row when explicitly required and not when the corresponding item is updated.

Example

Deletes all rows in the delete list:
.
for (i=list_rows(DL);i;i-,list_next(DL)) {
  lock = lock_row(EMP,list_curr(DL,0),false);
  if (lock != 0) g.msg = "Could not acquire lock.";
  else
    exec_sql("DELETE FROM emp WHERE rowid = " ^^ list_curr(DL,0));
  }
.
}