Author: suresh
Date: 2005-06-22 07:29:52 -0400 (Wed, 22 Jun 2005)
New Revision: 46361
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/MergeManager.cs
Log:
2005-06-22 Sureshkumar T <[EMAIL PROTECTED]>
* DataRow.cs: Added method MergeValuesToRow copy merge two rows
according to the merge rules.
* MergeManager.cs: (MergeRow): use MergeValuesToRow
API. CopyValuesToRow simply makes the target row same as source
row. Rather, MergeValuesToRow merges with the target row according
to the merge rules.
Modified: trunk/mcs/class/System.Data/System.Data/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data/ChangeLog 2005-06-22 11:15:06 UTC
(rev 46360)
+++ trunk/mcs/class/System.Data/System.Data/ChangeLog 2005-06-22 11:29:52 UTC
(rev 46361)
@@ -1,3 +1,13 @@
+2005-06-22 Sureshkumar T <[EMAIL PROTECTED]>
+
+ * DataRow.cs: Added method MergeValuesToRow copy merge two rows
+ according to the merge rules.
+
+ * MergeManager.cs: (MergeRow): use MergeValuesToRow
+ API. CopyValuesToRow simply makes the target row same as source
+ row. Rather, MergeValuesToRow merges with the target row according
+ to the merge rules.
+
2005-06-19 Konstantin Triger <[EMAIL PROTECTED]>
* DataSet.cs: Fixed ReadXml to work with IXmlSerializable
Modified: trunk/mcs/class/System.Data/System.Data/DataRow.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataRow.cs 2005-06-22 11:15:06 UTC
(rev 46360)
+++ trunk/mcs/class/System.Data/System.Data/DataRow.cs 2005-06-22 11:29:52 UTC
(rev 46361)
@@ -1509,6 +1509,65 @@
}
}
+ //Merge all values of this DataRow to the row parameter
according to merge rules.
+ internal void MergeValuesToRow(DataRow row, bool
preserveChanges)
+ {
+ if (row == null)
+ throw new ArgumentNullException("row");
+ if (row == this)
+ throw new ArgumentException("'row' is the same
as this object");
+
+ // Original values are anyway copied
+ if (HasVersion(DataRowVersion.Original)) {
+ if (row.Original < 0)
+ row.Original =
row.Table.RecordCache.NewRecord();
+ else if (row.Original == row.Current
+ && !(Original == Current && !
preserveChanges)) {
+ row.Original =
row.Table.RecordCache.NewRecord();
+ row.Table.RecordCache.CopyRecord
(row.Table, row.Current, row.Original);
+ }
+ } else {
+ if (row.Original == row.Current) { // if target
has same current, better create new original
+ row.Original =
row.Table.RecordCache.NewRecord();
+ row.Table.RecordCache.CopyRecord
(row.Table, row.Current, row.Original);
+ }
+ }
+
+ // if i have current, push all
+ if (HasVersion(DataRowVersion.Current)) {
+ if (! preserveChanges && row.Current < 0)
+ row.Current =
row.Table.RecordCache.NewRecord();
+ } else {
+ if (row.Current > 0 && ! preserveChanges) {
+
row.Table.RecordCache.DisposeRecord(row.Current);
+ row.Current = -1;
+ }
+ }
+
+ // copy source record values to target records
+ foreach(DataColumn column in Table.Columns) {
+ DataColumn targetColumn =
row.Table.Columns[column.ColumnName];
+ //if a column with the same name exists in both
rows copy the values
+ if(targetColumn != null) {
+ if
(HasVersion(DataRowVersion.Original)) {
+ object val = column[Original];
+ row.CheckValue(val,
targetColumn);
+ targetColumn[row.Original] =
val;
+ }
+
+ if (HasVersion(DataRowVersion.Current)
+ && !preserveChanges) {
+ object val = column[Current];
+ row.CheckValue(val,
targetColumn);
+ targetColumn[row.Current] = val;
+ }
+ }
+ }
+ if (HasErrors) {
+ CopyErrors(row);
+ }
+ }
+
internal void CopyErrors(DataRow row)
{
row.RowError = RowError;
Modified: trunk/mcs/class/System.Data/System.Data/MergeManager.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/MergeManager.cs 2005-06-22
11:15:06 UTC (rev 46360)
+++ trunk/mcs/class/System.Data/System.Data/MergeManager.cs 2005-06-22
11:29:52 UTC (rev 46361)
@@ -142,9 +142,9 @@
}
// row exists in target table, and presere changes is
false -
// change the values of the target row to the values of
the source row.
- else if (!preserveChanges)
+ else
{
- row.CopyValuesToRow(targetRow);
+ row.MergeValuesToRow(targetRow,
preserveChanges);
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches