[Mono-bugs] [Bug 650410] New: Deleting a row in the RowDeleting event causes Detach() exception while cascade delete is on
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Sun Oct 31 17:13:56 EDT 2010
https://bugzilla.novell.com/show_bug.cgi?id=650410
https://bugzilla.novell.com/show_bug.cgi?id=650410#c0
Summary: Deleting a row in the RowDeleting event causes
Detach() exception while cascade delete is on
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
In a particular sequence of events:
a) cascade deleting a row in another table while in RowDeleting event
b) having cascade delete on for another relationship
DataRow.Detach() is called twice for the same row.
The test case below works fine on ms.net.
Reproducible: Always
Steps to Reproduce:
Below is the test case:
DataSet data = new DataSet();
var t1 = data.Tables.Add("t1");
var t2 = data.Tables.Add("t2");
var t3 = data.Tables.Add("t3");
data.Tables.Remove(t1);
data.Tables.Remove(t3);
data.Tables.Add(t1);
data.Tables.Add(t3);
t1.Columns.Add("pk");
t1.Columns.Add("fk");
t2.Columns.Add("pk");
t2.Columns.Add("fk");
t3.Columns.Add("pk");
t3.Columns.Add("fk");
t1.Rows.Add(new object[] { "x", "x" });
t2.Rows.Add(new object[] { "x", "x" });
t3.Rows.Add(new object[] { "x", "x" });
var r12 = data.Relations.Add("r12", t1.Columns[0], t2.Columns[1]);
var r23 = data.Relations.Add("r23", t2.Columns[0], t3.Columns[1]);
var r31 = data.Relations.Add("r31", t3.Columns[0], t1.Columns[1]);
r12.ChildKeyConstraint.DeleteRule = Rule.None;
r23.ChildKeyConstraint.DeleteRule = Rule.Cascade;
r31.ChildKeyConstraint.DeleteRule = Rule.Cascade;
r12.ChildKeyConstraint.Table.Constraints.Remove(r12.ChildKeyConstraint);
List<DataRow> RowsInCascadeDelete = new List<DataRow>();
r12.ParentTable.RowDeleting += (sender, e) =>
{
if (!RowsInCascadeDelete.Contains(e.Row))
{
RowsInCascadeDelete.Add(e.Row);
try
{
DataRow[] childRows = e.Row.GetChildRows(r12);
foreach (DataRow childRow in childRows)
{
childRow.Delete();
}
}
finally
{
RowsInCascadeDelete.Remove(e.Row);
}
}
};
t2.Rows[0].Delete();
Actual Results:
An exception is thrown
Expected Results:
An exception should not be thrown
Tbe fix is straightfoward, if Detach() is called on a DataRow that is already
detached, do nothing:
void Detach ()
{
--- LINES ADDED ---
if (RowState == DataRowState.Detached)
return;
--- LINES ADDED ---
Table.DeleteRowFromIndexes (this);
_table.Rows.RemoveInternal (this);
--
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