Author: suresh
Date: 2005-06-10 02:43:14 -0400 (Fri, 10 Jun 2005)
New Revision: 45735

Modified:
   trunk/mcs/class/System.Data/System.Data/ChangeLog
   trunk/mcs/class/System.Data/System.Data/DataRow.cs
   trunk/mcs/class/System.Data/System.Data/DataSet.cs
Log:
2005-06-10  Sureshkumar T  <[EMAIL PROTECTED]>
        * DataRow.cs: CopyValuesToRow: if orginal == current, don't create
        a new current record.
        * DataSet.cs: GetChanges :Temporarily disable EnforceConstraints.



Modified: trunk/mcs/class/System.Data/System.Data/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data/ChangeLog   2005-06-10 05:58:45 UTC 
(rev 45734)
+++ trunk/mcs/class/System.Data/System.Data/ChangeLog   2005-06-10 06:43:14 UTC 
(rev 45735)
@@ -1,9 +1,14 @@
 2005-06-10  Sureshkumar T  <[EMAIL PROTECTED]>
 
-       * MergeManager.cs: Temporarily disable EnforceConstraints while
-       doing a dataset Merge. Patch from [EMAIL PROTECTED]
-       (George Barbarosie).
+       * DataRow.cs: CopyValuesToRow: if orginal == current, don't create
+       a new current record.
 
+       * DataSet.cs: GetChanges :Temporarily disable EnforceConstraints.
+
+       * MergeManager.cs: Merge: Temporarily disable
+       EnforceConstraints. Patch from [EMAIL PROTECTED] (George
+       Barbarosie).
+
 2005-06-09  Jordi Mas i Hernandez <[EMAIL PROTECTED]>
 
        * DataView.cs: fixes GetListName

Modified: trunk/mcs/class/System.Data/System.Data/DataRow.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataRow.cs  2005-06-10 05:58:45 UTC 
(rev 45734)
+++ trunk/mcs/class/System.Data/System.Data/DataRow.cs  2005-06-10 06:43:14 UTC 
(rev 45735)
@@ -1459,12 +1459,15 @@
                                        }
 
                                        if (HasVersion(DataRowVersion.Current)) 
{
-                                               if (row.Current < 0) {
-                                                       row.Current = 
row.Table.RecordCache.NewRecord();
+                                               if (Current == Original) {
+                                                       row.Current = 
row.Original;
+                                               }else {
+                                                       if (row.Current < 0)
+                                                               row.Current = 
row.Table.RecordCache.NewRecord();
+                                                       object val = 
column[Current];
+                                                       row.CheckValue(val, 
targetColumn);
+                                                       
targetColumn[row.Current] = val;
                                                }
-                                               object val = column[Current];
-                                               row.CheckValue(val, 
targetColumn);
-                                               targetColumn[row.Current] = val;
                                        }
                                        else {
                                                if (row.Current > 0) {

Modified: trunk/mcs/class/System.Data/System.Data/DataSet.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataSet.cs  2005-06-10 05:58:45 UTC 
(rev 45734)
+++ trunk/mcs/class/System.Data/System.Data/DataSet.cs  2005-06-10 06:43:14 UTC 
(rev 45735)
@@ -477,46 +477,45 @@
                                return null;
                        
                        DataSet copySet = Clone ();
+                       bool prev = copySet.EnforceConstraints;
+                       copySet.EnforceConstraints = false;
+
                        Hashtable addedRows = new Hashtable ();
 
-                       IEnumerator tableEnumerator = Tables.GetEnumerator ();
-                       DataTable origTable;
-                       DataTable copyTable;
-                       while (tableEnumerator.MoveNext ()) {
-                               origTable = (DataTable)tableEnumerator.Current;
-                               copyTable = copySet.Tables[origTable.TableName];
-                               
-                               // Look for relations that have this table as 
child
-                               IEnumerator relations = 
origTable.ParentRelations.GetEnumerator ();
-
-                               IEnumerator rowEnumerator = 
origTable.Rows.GetEnumerator ();
-                               while (rowEnumerator.MoveNext ()) {
-                                       DataRow row = 
(DataRow)rowEnumerator.Current;
-                                       
-                                       if (row.IsRowChanged (rowStates))
-                                               AddChangedRow (addedRows, 
copySet, copyTable, relations, row);
+                       for (int i = 0; i < Tables.Count; i++) {
+                               DataTable origTable = Tables [i];
+                               DataTable copyTable = 
copySet.Tables[origTable.TableName];
+                               for (int j = 0; j < origTable.Rows.Count; j++) {
+                                       DataRow row = origTable.Rows [j];
+                                       if (!row.IsRowChanged (rowStates)
+                                           || addedRows.Contains (row))
+                                               continue;
+                                       AddChangedRow (addedRows, copyTable, 
row);
                                }
                        }
+                       copySet.EnforceConstraints = prev;
                        return copySet;
                }
                
-               void AddChangedRow (Hashtable addedRows, DataSet copySet, 
DataTable copyTable, IEnumerator relations, DataRow row)
+               private void AddChangedRow (Hashtable addedRows, DataTable 
copyTable, DataRow row)
                {
                        if (addedRows.ContainsKey (row)) return;
-                       
-                       relations.Reset ();
-                       while (relations.MoveNext ()) {
-                               DataRow parentRow = row.GetParentRow 
((DataRelation) relations.Current);
-                               if (parentRow == null || addedRows.ContainsKey 
(parentRow)) continue;
-                               DataTable parentCopyTable = copySet.Tables 
[parentRow.Table.TableName];
-                               AddChangedRow (addedRows, copySet, 
parentCopyTable, parentRow.Table.ParentRelations.GetEnumerator (), parentRow);
+
+                       foreach (DataRelation relation in 
row.Table.ParentRelations) {
+                               DataRow parent = row.GetParentRow (relation);
+                               if (parent == null)
+                                       continue;
+                               // add the parent row
+                               DataTable parentCopyTable = 
copyTable.DataSet.Tables [parent.Table.TableName];
+                               AddChangedRow (addedRows, parentCopyTable, 
parent);
                        }
-               
-                       DataRow newRow = copyTable.NewRow ();
-                       copyTable.Rows.Add (newRow);
-                       row.CopyValuesToRow (newRow);                   
+
+                       // add the current row
+                       DataRow newRow = copyTable.NewNotInitializedRow();
+                       copyTable.Rows.AddInternal(newRow);
+                       row.CopyValuesToRow (newRow);
                        newRow.XmlRowID = row.XmlRowID;
-                       addedRows.Add (row,row);
+                       addedRows.Add (row, row);
                }
 
 #if NET_2_0

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to