Просмотр исходного кода

fixing net_2_0 compilation

svn path=/trunk/mcs/; revision=44554
Konstantin Triger 20 лет назад
Родитель
Сommit
c41b07156f

+ 0 - 14
mcs/class/System.Data/System.Data.Common/RecordCache.cs

@@ -161,20 +161,6 @@ namespace System.Data.Common
 			}
 		}
 
-                /// <summary>
-                ///     Compares two records in the given data table. The numbers are the offset
-                ///     into the container tables.
-                /// </summary>
-                internal static bool CompareRecords (DataTable table, int x, int y)
-                {
-                        foreach (DataColumn dc in table.Columns) {
-                                if (dc.DataContainer.CompareValues (x, y) != 0)
-                                        return false;
-                        }
-                        return true;
-                }
-
-
 		#endregion // Methods
 	}
 }

+ 6 - 0
mcs/class/System.Data/System.Data/ChangeLog

@@ -1,3 +1,9 @@
+2005-05-16 Konstantin Triger <[email protected]>
+
+        * DataRow.cs, DataTable.cs: code under net_2_0 changed to use the new interface
+        * DataTable.cs: Added CompareRecords, which compares records in column order
+
+
 2005-05-16  Sureshkumar T  <[email protected]>
 
 	* DataRow.cs:

+ 9 - 31
mcs/class/System.Data/System.Data/DataRow.cs

@@ -384,14 +384,6 @@ namespace System.Data {
 				return _original;
 			}
 			set {
-                                if (_original == value)
-                                        return;
-
-                                if (_original >= 0
-                                    && _current != _original
-                                    && _proposed != _original)
-                                        Table.RecordCache.DisposeRecord (_original);
-                                
 				if (Table != null) {
 					//Table.RecordCache[_original] = null;
 					Table.RecordCache[value] = this;
@@ -406,19 +398,10 @@ namespace System.Data {
 				return _current;
 			}
 			set {
-                                if (_current == value)
-                                        return;
-
-                                if (_current >= 0
-                                    && _proposed != _current
-                                    && _original != _current)
-                                        Table.RecordCache.DisposeRecord (_current);
-                                
 				if (Table != null) {
 					//Table.RecordCache[_current] = null;
 					Table.RecordCache[value] = this;
 				}
-
 				_current = value;
 			}
 		}
@@ -429,14 +412,6 @@ namespace System.Data {
 				return _proposed;
 			}
 			set {
-                                if (_proposed == value)
-                                        return;
-
-                                if (_proposed >= 0
-                                    && _current != _proposed
-                                    && _original != _proposed)
-                                        Table.RecordCache.DisposeRecord (_proposed);
-                                
 				if (Table != null) {
 					//Table.RecordCache[_proposed] = null;
 					Table.RecordCache[value] = this;
@@ -1600,14 +1575,18 @@ namespace System.Data {
                                 SetValue (i, values [i], temp);
 
                         if (is_new) { // new row
-                                Proposed = temp;
+                                if (HasVersion (DataRowVersion.Proposed) || RowState == DataRowState.Detached)
+                                        Proposed = temp;
+                                else
+                                        Current = temp;
+                                return;
                         }
 
                         if (loadOption == LoadOption.OverwriteChanges 
                             || (loadOption == LoadOption.PreserveChanges
                                 && RowState == DataRowState.Unchanged)) {
                                 Original = temp;
-                                if (Proposed >= 0)
+                                if (HasVersion (DataRowVersion.Proposed))
                                         Proposed = temp;
                                 else
                                         Current = temp;
@@ -1626,13 +1605,12 @@ namespace System.Data {
                         bool not_used = true;
                         // Upsert
                         if (RowState != DataRowState.Deleted) {
-                                int index = Proposed >=0 ? Proposed : Current;
-                                if (! RecordCache.CompareRecords (Table, index, temp)) {
-                                        if (Proposed >= 0)
+                                int index = HasVersion (DataRowVersion.Proposed) ? _proposed : _current;
+                                if (Table.CompareRecords (index, temp) != 0) {
+                                        if (HasVersion (DataRowVersion.Proposed))
                                                 Proposed = temp;
                                         else
                                                 Current = temp;
-
                                         not_used = false;
                                 }
                         }

+ 23 - 11
mcs/class/System.Data/System.Data/DataTable.cs

@@ -1203,20 +1203,20 @@ namespace System.Data {
                         
                         // Find Data DataRow
                         if (this.PrimaryKey.Length > 0) {
-                                object [] keyValues = new object [this.PrimaryKey.Length];
-                                for (int i = 0; i < keyValues.Length; i++)
-                                        keyValues [i] = values [this.PrimaryKey [i].Ordinal];
-                                
-                                Index index = GetIndex(PrimaryKey,null,DataViewRowState.OriginalRows,null,false);
-                                int found = index.Find (keyValues);
-                                row = found < 0 ? null : RecordCache [found];
-                                if (row == null) 
-                                        row = this.Rows.Find (keyValues);
+				int newRecord = CreateRecord(values);
+				try {
+					int existingRecord = _primaryKeyConstraint.Index.Find(newRecord);
+					if (existingRecord >= 0)
+						row = RecordCache[existingRecord];
+				}
+				finally {
+					RecordCache.DisposeRecord(newRecord);
+				}
                         }
                                 
                         // If not found, add new row
                         if (row == null) {
-                                row = NewRowFromBuilder (RowBuilder);
+                                row = this.NewRow ();
                                 new_row = true;
                         }
 
@@ -1233,7 +1233,7 @@ namespace System.Data {
                         }
 
                         if (new_row) {
-                                Rows.AddInternal(row);
+                                this.Rows.Add (row);
                                 if (loadOption == LoadOption.OverwriteChanges ||
                                     loadOption == LoadOption.PreserveChanges) {
                                         row.AcceptChanges ();
@@ -1321,6 +1321,18 @@ namespace System.Data {
 			}
 		}
 
+#if NET_2_0
+		internal int CompareRecords(int x, int y) {
+			for (int col = 0; col < Columns.Count; col++) {
+				int res = Columns[col].DataContainer.CompareValues (x, y);
+				if (res != 0)
+					return res;
+			}
+
+			return 0;
+		}
+#endif
+
 		/// <summary>
 		/// This member supports the .NET Framework infrastructure
 		///  and is not intended to be used directly from your code.