FIX: RI Code Not Selecting Right Work Area After Cascaded Delete (221648)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a
  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q221648

SYMPTOMS

You have a database container (DBC) that contains several tables. The DBC contains referential integrity code generated by the Referential Integrity (RI) Builder. The RI is configured to cascade deletes from a parent to a child table, and from the child table to another child table. When a record is deleted from the parent table, the stored procedure that performs the cascaded delete does not immediately reselect the correct work area after the delete occurs.

CAUSE

In the code created by the Referential Integrity Builder, the local variable lcStartArea is declared in both the insert and update code, but not in the delete code.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug was corrected in Visual Studio 6.0 Service Pack 3.

For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed

MORE INFORMATION

Steps to Reproduce Behavior

  1. Run the following code from a program (.PRG) file:
    #DEFINE CRLF CHR(13)+CHR(10)
    
    CLOSE DATA ALL
    * Make the DBC
    CREATE DATABASE 'RITEST.DBC'
    
    * Add the stored procedures. Because STRTOFILE() was not available in
    * VFP 5, you will have to create this stored procedure manually
    STRTOFILE("PROC RITestProc"+CRLF+ ;
       "   messagebox([Current work area is ]+str(select()))"+CRLF +;
       "ENDPROC", 'procs.txt')
    
    APPEND PROC FROM 'procs.txt' OVERWRITE
    DELETE FILE procs.txt
    
    * Make the tables, indexes, relations, and trigger
    CREATE TABLE 'RITBL1.DBF' NAME 'RITBL1' (FLD1 C(10) NOT NULL ;
       PRIMARY KEY, FLD2 C(25) NOT NULL)
    CREATE TRIGGER ON 'RITBL1' FOR DELETE AS RITestProc()
    
    CREATE TABLE 'RITBL2.DBF' NAME 'RITBL2' (FLD1 C(10) NOT NULL, ;
       FLD2 D NOT NULL PRIMARY KEY)
    ALTER TABLE 'RITBL2' ADD FOREIGN KEY FLD1 TAG FLD11 ;
       REFERENCES RITBL1 TAG FLD1
    
    CREATE TABLE 'RITBL3.DBF' NAME 'RITBL3' (FLD2 D NOT NULL, ;
       FLD3 C(25) NOT NULL)
    ALTER TABLE 'RITBL3' ADD FOREIGN KEY FLD2 TAG FLD2_3 ;
       REFERENCES RITBL2 TAG FLD2
    
    * Add the data
    INSERT INTO RITBL1 VALUES('1', 'One')
    INSERT INTO RITBL2 VALUES('1', DATE())
    INSERT INTO ritbl3 VALUES(DATE(), "Today")
    
    * Open the Database Designer to run RI builder
    MODIFY DATABASE
    
    * Delete the record in RITBL1 to demonstrate behavior
    USE RITBL1 IN 1
    DELETE FROM RITBL1 WHERE FLD1=='1'
    					
  2. When the Database Designer is displayed, right-click on the Database Designer, and select Edit Referential Integrity from the Context menu.
  3. When the Referential Integrity Builder is displayed, click the Rules for Deleting tab. Select the first record in the grid, and click the Cascade option.
  4. Select the second record in the grid, and click the Cascade option, then click OK. If performed properly, the Delete column for both of the grid's records contain the word "Cascade."
  5. Click Yes in each of the two warning dialogs that appear.
  6. Close the Database Designer. The messagebox appears, showing that the current work area is 2.
(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Jim Saunders, Microsoft Corporation.


Modification Type:MajorLast Reviewed:10/15/2002
Keywords:kbBug kbCodeSnippet kbDatabase kbDSupport kbVS600sp3fix KB221648