Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread LIB - proc, RemoveDetailProc.sql
Wed, Feb 8 2012 7:43 AMPermanent Link

Lucian

CREATE PROCEDURE "RemoveDetailProc" (
IN "TableName" VARCHAR(40) COLLATE "UNI_CI",
IN "KeyFieldName" VARCHAR(40) COLLATE "UNI_CI",
IN "OldKeyValue" INTEGER)
BEGIN
 DECLARE TriggerStatement STATEMENT;
 PREPARE TriggerStatement FROM 'DELETE FROM '+TableName+' WHERE '+KeyFieldName+'=?';
 EXECUTE TriggerStatement USING OldKeyValue;
END

sample of usage, from a BEFORE DELETE trigger:

BEGIN
 CALL RemoveChildrenProc('usergroups', 'UserID', OLDROW.UserID);
 CALL RemoveChildrenProc('userrights', 'UserID', OLDROW.UserID);
 ...
END

where
- 'usergroups', 'userrights' are detail tables
- 'UserID' is the key field in the detail table
Thu, Feb 9 2012 4:33 AMPermanent Link

Lucian

> CALL RemoveChildrenProc('usergroups', 'UserID', OLDROW.UserID);

Crap, that was supposed to be RemoveDetailProc. I changed the name in the last moment thinking it was more appropriate, but than I copied the usage sample straight from some script
Image