Parcourir la source

fixes for ImportRowTest test case

svn path=/branches/Mainsoft.System.Data/mcs/; revision=44544
Konstantin Triger il y a 20 ans
Parent
commit
03f0186151

+ 1 - 1
mcs/class/System.Data/System.Data.Common/Index.cs

@@ -395,7 +395,7 @@ namespace System.Data.Common
 
 			int oldIdx = FindIndex(oldRecord);
 
-			if( oldIdx == -1) {
+			if( oldIdx == -1 || Key.Table.RecordCache[Array[oldIdx]] != row ) {
 				Add(row,newRecord);
 				return;
 			}

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

@@ -1,3 +1,9 @@
+2005-05-16 Konstantin Triger <[email protected]>
+
+	* UniqueConstraint.cs : IsNull check is relevant for rows having default row version.
+	* DataTable.cs : The row should be validated when imported
+	* DataRowCollection.cs : if the row does not contain Proposed neither Current version, it's irrelevant for validation
+
 2005-04-26 Boris Kirzner <[email protected]>
 
 	* UniqueConstraint.cs :

+ 3 - 0
mcs/class/System.Data/System.Data/DataRowCollection.cs

@@ -329,6 +329,9 @@ namespace System.Data
 			row.CheckNullConstraints();
 
 			int newRecord = (row.Proposed >= 0) ? row.Proposed : row.Current;
+			if (newRecord < 0)
+				return;
+
 			foreach(Index index in table.Indexes) {
 				index.Update(row,newRecord);
 			}

+ 4 - 0
mcs/class/System.Data/System.Data/DataTable.cs

@@ -1008,6 +1008,10 @@ namespace System.Data {
 				RecordCache.CopyRecord(row.Table,current,newRow.Current);
 			}
 
+			if (EnforceConstraints)
+				// we have to check that the new row doesn't colide with existing row
+				Rows.ValidateDataRowInternal(newRow);
+
 			Rows.AddInternal(newRow);		
 	
 			if (row.HasErrors) {

+ 2 - 2
mcs/class/System.Data/System.Data/UniqueConstraint.cs

@@ -436,9 +436,9 @@ namespace System.Data {
 
 		internal override void AssertConstraint(DataRow row)
 		{	
-			if (IsPrimaryKey) {
+			if (IsPrimaryKey && row.HasVersion(DataRowVersion.Default)) {
 				for (int i = 0; i < Columns.Length; i++) {
-					if (row.IsNull(i)) {
+					if (row.IsNull(Columns[i])) {
 						throw new NoNullAllowedException("Column '" + Columns[i].ColumnName + "' does not allow nulls.");
 					}
 				}