Kbase P23614: How to read the ROWID of newly inserted record inside SQL-92 trigger ?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  9/7/2009 |
|
Status: Unverified
GOAL:
How to read the ROWID of newly inserted record inside SQL-92 trigger ?
FACT(s) (Environment):
Progress 9.x
OpenEdge 10.x
All Supported Operating Systems
FIX:
It is not possible to get the ROWID of a new record by using the NEWROW object in a trigger. The best workaround is to re-fetch the newly created record and to store the ROWID value in an Integer field. This can be accomplished by using the UPDATE statement with a WHERE clause. The following example illustrates this within a trigger.
This trigger reads the Custnum value of the newly inserted record and uses it to update the rowidFLD field afterwards.
CREATE TRIGGER getRowID AFTER INSERT ON pub.customer
REFERENCING NEWROW
FOR EACH ROW
IMPORT
import java.sql.* ;
BEGIN
Integer custnum = (Integer) NEWROW.getValue(1, INTEGER);
SQLIStatement update_stmt = new SQLIStatement ("UPDATE pub.customer SET rowidFLD = ROWID WHERE custnum = ?"); /* <--- 1 row */
update_stmt.setParam(1, custnum);
update_stmt.execute();
END;