FIX: Trigger Failed Error When Updating a Compound Primary Key (155749)
The information in this article applies to:
- Microsoft Visual FoxPro for Windows 3.0
- Microsoft Visual FoxPro for Windows 3.0b
This article was previously published under Q155749 SYMPTOMS
When you make a change to a column in a table that makes up a portion of a
primary key or a compound primary key, and the Referential Integrity
Builder has referential integrity in place, the Cascade Update to the Child
table fails with a "Trigger Failed."
CAUSE
The following REPLACE command in the RIUPDATE procedure improperly
evaluates out to "FieldName1+FieldName2":
REPLACE (tcFieldName) WITH tcNewValue
This is why looking at the GaError array, which is filled by the
Referential Integrity Builder, reveals the trigger failed because of a
syntax error.
WORKAROUND
To work around this problem, go into the Stored Procedures and modify the
call to the RIUPDATE routine in the procedure called
"__RI_UPDATE_your_table_name" so that it sends an additional argument of
"lcParentWkArea." It should then read the following:
llRetVal=riupdate("<fieldname1>+<fieldname2>",lcParentID,lcParentWkArea)
instead of the following:
llRetVal=riupdate("ONE+TWO",lcParentID)
Make the following modifications to the RIUPDATE routine:
- Add the following additional parameter to the Parameters statement:
PARAMETERS tcFieldName,tcNewValue, tcParentWkArea
- Add the following variables to the LOCAL declaration line:
tcParentTable
ncount
- Add the following immediately after the LOCAL statement:
tcParentTable=ALIAS(tcParentWkArea)
- Remark out the current REPLACE command.
- Add the following code immediately after the commented REPLACE command:
ncount=OCCURS('+',tcFieldName)+1
FOR i = 1 TO ncount
DO CASE
CASE i = 1 && First occurrence of "+"
REPLACE (SUBSTR(tcFieldName,i,AT("+",tcFieldName,i)-1));
WITH EVAL(tcParentTable+'.'+;
SUBSTR(tcFieldName,i,AT("+",tcFieldName,i)-1))
CASE i = ncount && Last occurrence of "+"
REPLACE (SUBSTR(tcFieldName,AT('+',tcFieldName,ncount-1)+1)) ;
WITH EVAL(tcParentTable+'.'+ ;
SUBSTR(tcFieldName,AT('+',tcFieldName,ncount-1)+1))
OTHERWISE && Any number of occurrences of + in between.
REPLACE (SUBSTR(tcFieldName,AT('+',tcFieldName,(i-1))+1, ;
((AT('+',tcFieldName,i)-AT('+',tcFieldName,(i-1)))-1))) ;
WITH EVAL(tcParentTable+'.'+SUBSTR(tcFieldName, ;
AT('+',tcFieldName,(i-1))+1,((AT('+',tcFieldName,i)- ;
AT('+',tcFieldName,(i-1)))-1)))
ENDCASE
NEXT i
The above code works with any number of columns in a compound key.
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article. This problem has been fixed in
Visual FoxPro 5.0 for Windows.
Modification Type: | Major | Last Reviewed: | 9/30/2003 |
---|
Keywords: | kbBug kbfix kbvfp500fix KB155749 |
---|
|