[Mono-bugs] [Bug 650402] New: ForeignKeyConstraint enforced on deleted rows

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Oct 31 15:44:14 EDT 2010


https://bugzilla.novell.com/show_bug.cgi?id=650402

https://bugzilla.novell.com/show_bug.cgi?id=650402#c0


           Summary: ForeignKeyConstraint enforced on deleted rows
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: x86
        OS/Version: Windows 7
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.Data
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: cvolzke at live.com.au
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1036 Safari/532.5

If there is a foreign key on a row and a child row is deleted, the deleted row
is attempted to be read setting EnforceConstraints to false and then true.


Reproducible: Always

Steps to Reproduce:
1. Create a foreign key constraint.
2. Add a parent row and a child row.
3. childRow.AcceptChangs(); cihldRow.Delete();
4. EnforceConstraints = false; EnforceConstraints = true;

Actual Results:  
A DeletedRowInaccessibleException is raised

Expected Results:  
An exception should not be raised

Test case to reproduce
----------------------

            DataSet data = new DataSet();
            DataTable parent = new DataTable("parent");
            DataColumn pk = parent.Columns.Add("PK");
            DataTable child = new DataTable("child");
            DataColumn fk = child.Columns.Add("FK");

            data.Tables.Add(parent);
            data.Tables.Add(child);
            data.Relations.Add(pk, fk);

            parent.Rows.Add("value");
            child.Rows.Add("value");
            data.AcceptChanges();
            child.Rows[0].Delete();
            parent.Rows[0][0] = "value2";

            data.EnforceConstraints = false;
            data.EnforceConstraints = true;

Proposed fix
------------

Add line
  if (row.RowState == DataRowState.Deleted) continue;

to

internal override bool IsConstraintViolated()
{
    if (Table.DataSet == null || RelatedTable.DataSet == null) 
        return false;

    bool hasErrors = false;
    foreach (DataRow row in Table.Rows) {
        // first we check if all values in _childColumns place are nulls.
        // if yes we return.
                --> if (row.RowState == DataRowState.Deleted) continue; // LINE
ADDED

        if (row.IsNullColumns(_childColumns))
            continue;

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list