Переглянути джерело

2006-02-22 Senganal T <[email protected]>

	* Test/System.Data/DataRowCollectionTest2.cs : Check if index is maintained for row on calling RejectChanges. 
	* Test/System.Data/DataTableTest2.cs : Check if data is loaded and merged (if key exists) correctly.
	* Test/System.Data/ForeignKeyConstraintTest.cs : Check if a ParentColumn value can be modified
		when the row is in 'Added' State. Also, check if child col values are
		updated correctly.
	* Test/ProviderTests/System.Data.SqlClient/SqlAdapterTest.cs : Added testcases for verifying FillError Behavior
	* System.Data.Common/DbDataAdapter.cs :
		- FillTable : Move BeginLoadData, EndLoadData outside the loop. Also,
		move EndLoadData outsidet try,catch block. FillError is only for errors
		occuring during loading the data into datatable.
	* System.Data.Common/Key.cs :
		- Set Default value of RowStateFilter to (CurrentRos | OriginalRows).
		- ContainsVersion : If RowStateFilter is set to default value, return true
		for Modified Rows as they can contain Default/Original versions.
	* System.Data/DataRow.cs 
		- RejectChanges : Do not remove Row from Indexes when state is Deleted.
		- CheckChildRows : When checking for the ChildRows, use the current value
		and not the original value.


svn path=/trunk/mcs/; revision=57149
Senganal T 20 роки тому
батько
коміт
08c7b22113

+ 11 - 0
mcs/class/System.Data/System.Data.Common/ChangeLog

@@ -1,3 +1,14 @@
+2006-02-22  Senganal T <[email protected]>
+
+	* DbDataAdapter.cs :
+		- FillTable : Move BeginLoadData, EndLoadData outside the loop. Also,
+		move EndLoadData outsidet try,catch block. FillError is only for errors
+		occuring during loading the data into datatable.
+	* Key.cs :
+		- Set Default value of RowStateFilter to (CurrentRos | OriginalRows).
+		- ContainsVersion : If RowStateFilter is set to default value, return true
+		for Modified Rows as they can contain Default/Original versions.
+
 2006-02-18  Raja R Harinath  <[email protected]>
 
 	* DbConnectionStringBuilder.cs (ICollection.CopyTo): Use

+ 12 - 11
mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs

@@ -408,13 +408,12 @@ namespace System.Data.Common {
 				dataReader.Read ();
 			}
 
+			dataTable.BeginLoadData ();
 			while (dataReader.Read () && (maxRecords == 0 || (counter - counterStart) < maxRecords)) {
 				try {
-					dataTable.BeginLoadData ();
 					dataTable.LoadDataRow (dataReader, sortedMapping, length, AcceptChangesDuringFill);
-					dataTable.EndLoadData ();
 					counter++;
-				} 
+				}
 				catch (Exception e) {
 					object[] readerArray = new object[dataReader.FieldCount];
 					object[] tableArray = new object[mapping.Length];
@@ -428,20 +427,22 @@ namespace System.Data.Common {
 					}
 					FillErrorEventArgs args = CreateFillErrorEvent (dataTable, tableArray, e);
 					OnFillError (args);
-					if(!args.Continue) {
-						return false;
-					}
+
+					// if args.Continue is not set to true or if a handler is not set, rethrow the error..
+					if(!args.Continue)
+						throw e;
 				}
 			}
+			dataTable.EndLoadData ();
 			return true;
 		}
 
 #if NET_2_0
-                /// <summary>
-                ///     Fills the given datatable using values from reader. if a value 
-                ///     for a column is  null, that will be filled with default value. 
-                /// </summary>
-                /// <returns>No. of rows affected </returns>
+		/// <summary>
+		///     Fills the given datatable using values from reader. if a value 
+		///     for a column is  null, that will be filled with default value. 
+		/// </summary>
+		/// <returns>No. of rows affected </returns>
 		internal static int FillFromReader (DataTable table,
                                                     IDataReader reader,
                                                     int start, 

+ 22 - 41
mcs/class/System.Data/System.Data.Common/Key.cs

@@ -47,6 +47,7 @@ namespace System.Data.Common
 		//	and always uses the _current version
 		//so need a temp row for Eval calls
 		DataRow _tmpRow;
+		static DataViewRowState DefaultRowStateFilter = (DataViewRowState.CurrentRows | DataViewRowState.OriginalRows);
 
 		#endregion //Fields
 
@@ -69,13 +70,11 @@ namespace System.Data.Common
 				}
 			}
 
-			if (rowState != DataViewRowState.None) {
+			if (rowState != DataViewRowState.None)
 				_rowStateFilter = rowState;
-			}
-			else {
+			else
 				// FIXME : what is the correct value ?
-				_rowStateFilter = DataViewRowState.CurrentRows;
-			}
+				_rowStateFilter = DefaultRowStateFilter;
 		}
 
 		#endregion // Constructors
@@ -166,77 +165,59 @@ namespace System.Data.Common
 		internal bool ContainsVersion (DataRowState state, DataRowVersion version)
 		{
 			switch (state) {
-				case DataRowState.Unchanged: {
-					if ((_rowStateFilter & DataViewRowState.Unchanged) != DataViewRowState.None) {
+				case DataRowState.Unchanged:
+					if ((_rowStateFilter & DataViewRowState.Unchanged) != DataViewRowState.None)
 						return ((version & DataRowVersion.Default) != 0);
-					}
-
 					break;
-				}
-				case DataRowState.Added: {
-					if ((_rowStateFilter & DataViewRowState.Added) != DataViewRowState.None) {
+				case DataRowState.Added:
+					if ((_rowStateFilter & DataViewRowState.Added) != DataViewRowState.None)
 						return ((version & DataRowVersion.Default) != 0);
-					}
-
 					break;
-				}
-				case DataRowState.Deleted: {
-					if ((_rowStateFilter & DataViewRowState.Deleted) != DataViewRowState.None) {
+				case DataRowState.Deleted:
+					if ((_rowStateFilter & DataViewRowState.Deleted) != DataViewRowState.None)
 						return (version == DataRowVersion.Original);
-					}
-
 					break;
-				}
 				default:
-					if ((_rowStateFilter & DataViewRowState.ModifiedCurrent) != DataViewRowState.None) {
+					// If _rowStateFilter has the default value, return true
+					if (_rowStateFilter ==  DefaultRowStateFilter)
+						return true;
+					if ((_rowStateFilter & DataViewRowState.ModifiedCurrent) != DataViewRowState.None)
 						return ((version & DataRowVersion.Default) != 0);
-					}
-					else if ((_rowStateFilter & DataViewRowState.ModifiedOriginal) != DataViewRowState.None) {
+					if ((_rowStateFilter & DataViewRowState.ModifiedOriginal) != DataViewRowState.None)
 						return (version == DataRowVersion.Original);
-					}
-
 					break;
 			}
 
-            return false;
+			return false;
 		}
 
 		internal static int GetRecord(DataRow row, DataViewRowState rowStateFilter)
 		{
 			switch (row.RowState) {
 				case DataRowState.Unchanged: {
-					if ((rowStateFilter & DataViewRowState.Unchanged) != DataViewRowState.None) {
+					if ((rowStateFilter & DataViewRowState.Unchanged) != DataViewRowState.None)
 						return row.Proposed >= 0 ? row.Proposed : row.Current;
-					}
-
 					break;
 				}
 				case DataRowState.Added: {
-					if ((rowStateFilter & DataViewRowState.Added) != DataViewRowState.None) {
+					if ((rowStateFilter & DataViewRowState.Added) != DataViewRowState.None)
 						return row.Proposed >= 0 ? row.Proposed : row.Current;
-					}
-
 					break;
 				}
 				case DataRowState.Deleted: {
-					if ((rowStateFilter & DataViewRowState.Deleted) != DataViewRowState.None) {
+					if ((rowStateFilter & DataViewRowState.Deleted) != DataViewRowState.None)
 						return row.Original;
-					}
-
 					break;
 				}
 				default:
-					if ((rowStateFilter & DataViewRowState.ModifiedCurrent) != DataViewRowState.None) {
+					if ((rowStateFilter & DataViewRowState.ModifiedCurrent) != DataViewRowState.None)
 						return row.Proposed >= 0 ? row.Proposed : row.Current;
-					}
-					else if ((rowStateFilter & DataViewRowState.ModifiedOriginal) != DataViewRowState.None) {
+					if ((rowStateFilter & DataViewRowState.ModifiedOriginal) != DataViewRowState.None)
 						return row.Original;
-					}
-
 					break;
 			}
 
-            return -1;
+			return -1;
 		}
 
 		/// <summary>

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

@@ -1,3 +1,10 @@
+2006-02-22  Senganal T  <[email protected]>
+
+	* DataRow.cs 
+		- RejectChanges : Do not remove Row from Indexes when state is Deleted.
+		- CheckChildRows : When checking for the ChildRows, use the current value
+		and not the original value.
+
 2006-02-18  Atsushi Enomoto  <[email protected]>
 
 	* CustomDataClassGenerator.cs : Patch by Marek Habersack. xsd now

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

@@ -591,14 +591,14 @@ namespace System.Data {
 					return;
 			case DataRowState.Added:
 			case DataRowState.Modified:
-					int original = Original;
-					DataRowState oldState = RowState;
+				int original = Original;
+				DataRowState oldState = RowState;
                                 if (Original >= 0) {
                                         Table.RecordCache.DisposeRecord(Original);
                                 }
                                 Original = Current;
-					foreach (Index index in Table.Indexes)
-						index.Update(this, original, DataRowVersion.Original, oldState);
+				foreach (Index index in Table.Indexes)
+					index.Update(this, original, DataRowVersion.Original, oldState);
 				break;
 			case DataRowState.Deleted:
 				Table.DeleteRowFromIndexes(this);
@@ -654,7 +654,7 @@ namespace System.Data {
 				Proposed = -1;
 
 				foreach(Index index in Table.Indexes)
-					index.Update(this,oldRecord, DataRowVersion.Proposed, oldState);					
+					index.Update(this,oldRecord, DataRowVersion.Proposed, oldState);
 			}
 		}
 
@@ -695,9 +695,8 @@ namespace System.Data {
 			if (Current >= 0) {
 				int current = Current;
 				DataRowState oldState = RowState;
-				if (Current != Original) {
+				if (Current != Original)
 					_table.RecordCache.DisposeRecord(Current);
-				}
 				Current = -1;
 				foreach(Index index in Table.Indexes)
 					index.Update(this, current, DataRowVersion.Current, oldState);
@@ -769,7 +768,7 @@ namespace System.Data {
 								// change only the values in the key columns
 								// set the childcolumn value to the new parent row value
 									for (int k = 0; k < fkc.Columns.Length; k++)
-										if (!fkc.RelatedColumns [k].DataContainer [Original].Equals (fkc.RelatedColumns [k].DataContainer [Proposed]))
+										if (!fkc.RelatedColumns [k].DataContainer [Current].Equals (fkc.RelatedColumns [k].DataContainer [Proposed]))
 											childRows[j][fkc.Columns[k]] = this[fkc.RelatedColumns[k], DataRowVersion.Proposed];
 
 									break;
@@ -1340,7 +1339,6 @@ namespace System.Data {
 				break;
 			case DataRowState.Deleted:
 				CheckChildRows (DataRowAction.Rollback);
-				Table.DeleteRowFromIndexes(this);
 				Current = Original;
 				break;
 			}

+ 4 - 0
mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog

@@ -1,3 +1,7 @@
+2006-02-13  Senganal T  <[email protected]>
+
+	* SqlAdapterTest.cs : Added testcases for verifying FillError Behavior
+
 2006-02-13  Senganal T  <[email protected]>
 
 	* SqlAdapterTest.cs : Added testcases for #77480

+ 45 - 0
mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlDataAdapterTest.cs

@@ -388,6 +388,51 @@ namespace MonoTests.System.Data.SqlClient
 			}
 		}
 
+		bool FillErrorContinue = false;
+		[Test]
+		public void Fill_Test_FillErrorTest ()
+		{
+			string query = "select type_bigint from numeric_family where id=1 or id=4 ";
+
+			DataSet ds = new DataSet ();
+			DataTable table = ds.Tables.Add ("test");
+			table.Columns.Add ("col", typeof (int));
+
+			adapter = new SqlDataAdapter (query, connectionString);
+			DataTableMapping mapping = adapter.TableMappings.Add ("numeric_family", "test");
+			mapping.ColumnMappings.Add ("type_bigint", "col");
+
+			int count = 0;
+			try {
+				count = adapter.Fill (ds, "numeric_family");
+				Assert.Fail ("#1 Overflow exception must be thrown");
+			}catch (OverflowException e) {
+			}
+			Assert.AreEqual (0, ds.Tables [0].Rows.Count, "#2");
+			Assert.AreEqual (0, count, "#3");
+
+			adapter.FillError += new FillErrorEventHandler (ErrorHandler);
+			FillErrorContinue = false;
+			try {
+				count = adapter.Fill (ds, "numeric_family");
+				Assert.Fail ("#4 Overflow exception must be thrown");
+			}catch (OverflowException e) {
+			}
+			Assert.AreEqual (0, ds.Tables [0].Rows.Count, "#5");
+			Assert.AreEqual (0, count, "#6");
+
+			FillErrorContinue = true;
+			count = adapter.Fill (ds, "numeric_family");
+			// 1 row shud be filled
+			Assert.AreEqual (1, ds.Tables [0].Rows.Count, "#7");
+			Assert.AreEqual (1, count, "#8");
+		}
+
+		void ErrorHandler (object sender, FillErrorEventArgs args)
+		{
+			args.Continue = FillErrorContinue;
+		}
+
 		[Test]
 		public void GetFillParametersTest ()
 		{

+ 8 - 0
mcs/class/System.Data/Test/System.Data/ChangeLog

@@ -1,3 +1,11 @@
+2006-02-22  Senganal T  <[email protected]>
+
+	* DataRowCollectionTest2.cs : Check if index is maintained for row on calling RejectChanges. 
+	* DataTableTest2.cs : Check if data is loaded and merged (if key exists) correctly.
+	* ForeignKeyConstraintTest.cs : Check if a ParentColumn value can be modified
+		when the row is in 'Added' State. Also, check if child col values are
+		updated correctly.
+
 2006-02-16  Senganal T  <[email protected]>
 
 	* DataSetTest2.cs :

+ 16 - 0
mcs/class/System.Data/Test/System.Data/DataRowCollectionTest2.cs

@@ -183,6 +183,22 @@ namespace MonoTests.System.Data
 			dt.Rows.Add((Object[])null);
 		}
 
+		[Test]
+		public void FindByKey ()
+		{
+			DataTable table = new DataTable ();
+			table.Columns.Add ("col1", typeof (int));
+			table.PrimaryKey = new DataColumn[] {table.Columns [0]};
+
+			table.Rows.Add (new object[] {1});
+			table.AcceptChanges ();
+			Assert.IsNotNull (table.Rows.Find (new object[] {1}), "#1");
+
+			table.Rows[0].Delete ();
+			table.RejectChanges ();
+			Assert.IsNotNull (table.Rows.Find (new object[] {1}), "#2");
+		}
+
 		[Test]
 		public void DataRowCollection_Clear1()
 		{

+ 38 - 0
mcs/class/System.Data/Test/System.Data/DataTableTest2.cs

@@ -1949,6 +1949,44 @@ namespace MonoTests_System.Data
 			Assert.AreEqual (1, table.Constraints.Count, "#1");
 		}
 
+		[Test]
+		public void LoadDataRow_ExistingData ()
+		{
+			DataSet ds = new DataSet ();
+			DataTable table = ds.Tables.Add ();
+			
+			table.Columns.Add ("col1", typeof (int));
+			table.Columns.Add ("col2", typeof (int));
+			table.PrimaryKey = new DataColumn[] {table.Columns [0]};
+
+			table.BeginLoadData ();
+			table.LoadDataRow (new object[] {1,10}, true);
+			table.LoadDataRow (new object[] {2,10}, true);
+			table.LoadDataRow (new object[] {3,10}, true);
+			table.LoadDataRow (new object[] {4,10}, true);
+			table.EndLoadData ();
+
+			Assert.AreEqual (4, table.Rows.Count, "#1");
+			Assert.AreEqual (10, table.Rows [0][1], "#2");
+			Assert.AreEqual (10, table.Rows [1][1], "#3");
+			Assert.AreEqual (10, table.Rows [2][1], "#4");
+			Assert.AreEqual (10, table.Rows [3][1], "#5");
+	
+
+			table.BeginLoadData ();
+			table.LoadDataRow (new object[] {1,100}, true);
+			table.LoadDataRow (new object[] {2,100}, true);
+			table.LoadDataRow (new object[] {3,100}, true);
+			table.LoadDataRow (new object[] {4,100}, true);
+			table.EndLoadData ();
+
+			Assert.AreEqual (4, table.Rows.Count, "#6");
+			Assert.AreEqual (100, table.Rows [0][1], "#7");
+			Assert.AreEqual (100, table.Rows [1][1], "#8");
+			Assert.AreEqual (100, table.Rows [2][1], "#7");
+			Assert.AreEqual (100, table.Rows [3][1], "#10");
+		}
+
 		private void OnRowDeleting_Handler(Object sender,DataRowChangeEventArgs e)
 		{
 			

+ 17 - 0
mcs/class/System.Data/Test/System.Data/ForeignKeyConstraintTest.cs

@@ -509,5 +509,22 @@ namespace MonoTests.System.Data
 				_ds.EnforceConstraints = true;
 			}
 		}
+
+		[Test]
+		public void ModifyParentKeyBeforeAcceptChanges ()
+		{
+			DataSet ds1 = new DataSet();
+			DataTable t1= ds1.Tables.Add ("t1");
+			DataTable t2= ds1.Tables.Add ("t2");
+			t1.Columns.Add ("col1", typeof (int));
+			t2.Columns.Add ("col2", typeof (int));
+			ds1.Relations.Add ("fk", t1.Columns [0], t2.Columns [0]);
+
+			t1.Rows.Add (new object[] {10});
+			t2.Rows.Add (new object [] {10});
+
+			t1.Rows [0][0]=20;
+			Assert("#1", (int)t2.Rows [0][0] == 20);
+		}
 	}
 }