Explorar el Código

2002-05-18 Tim Coleman <[email protected]>
* System.Data/DataRow.cs: Try to reduce memory
usage by only creating the original and proposed
arrays as required in BeginEdit, and then destroying
proposed during EndEdit, and original during AcceptChanges.
* System.Data.Common/DbDataAdapter.cs: Make the
startRecord and maxRecords parameters work correctly.

svn path=/trunk/mcs/; revision=4736

Tim Coleman hace 23 años
padre
commit
58847a4f3d

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

@@ -1,3 +1,11 @@
+2002-05-18  Tim Coleman <[email protected]>
+	* System.Data/DataRow.cs: Try to reduce memory
+	usage by only creating the original and proposed
+	arrays as required in BeginEdit, and then destroying
+	proposed during EndEdit, and original during AcceptChanges.
+	* System.Data.Common/DbDataAdapter.cs: Make the
+	startRecord and maxRecords parameters work correctly.
+
 2002-05-18  Tim Coleman <[email protected]>
 	* System.Data/DataRow.cs: Move the null check in
 	ItemArray set to above the Invalid Cast check, so

+ 6 - 1
mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs

@@ -135,7 +135,12 @@ namespace System.Data.Common
                                 DataRow row;
                                 object[] itemArray = new object[dataReader.FieldCount];
 
-                                while (dataReader.Read () && !(maxRecords > 0 && changeCount > maxRecords && srcTable == tableName))
+				// limit results for first results only.
+				if (srcTable == tableName)
+					for (int k = 0; k < startRecord; k += 1)
+						dataReader.Read ();
+
+                                while (dataReader.Read () && !(maxRecords > 0 && changeCount >= maxRecords && srcTable == tableName))
                                 {
                                         // need to check for existing rows to reconcile if we have key
                                         // information.  skip this step for now

+ 25 - 5
mcs/class/System.Data/System.Data/DataRow.cs

@@ -46,12 +46,10 @@ namespace System.Data
 		{
 			table = builder.Table;
 
-			original = new object[table.Columns.Count];
+			original = null; 
 			proposed = null;
 			current = new object[table.Columns.Count];
 
-			Array.Copy (current, original, table.Columns.Count);
-	
 			versions = new Hashtable ();
 
 			versions[DataRowVersion.Original] = original;
@@ -183,12 +181,14 @@ namespace System.Data
 				{
 					if (table.Columns[i].ReadOnly && value[i] != this[i])
 						throw new ReadOnlyException ();
+
 					if (value[i] == null)
 					{
 						if (!table.Columns[i].AllowDBNull)
 							throw new NoNullAllowedException ();
 						continue;
 					}
+						
 					if (table.Columns[i].DataType != value[i].GetType())
 						throw new InvalidCastException ();
 				}
@@ -234,8 +234,7 @@ namespace System.Data
 		{
 			this.EndEdit ();
 
-			Array.Copy (proposed, current, table.Columns.Count);
-			proposed = null;
+			original = null;
 
 			switch (rowState)
 			{
@@ -257,7 +256,9 @@ namespace System.Data
 		public void BeginEdit() 
 		{
 			proposed = new object[table.Columns.Count];
+			original = new object[table.Columns.Count];
 			Array.Copy (current, proposed, table.Columns.Count);
+			Array.Copy (current, original, table.Columns.Count);
 		}
 
 		/// <summary>
@@ -265,6 +266,7 @@ namespace System.Data
 		/// </summary>
 		public void CancelEdit() 
 		{
+			original = null;
 			proposed = null;
 			rowState = DataRowState.Unchanged;
 		}
@@ -293,6 +295,11 @@ namespace System.Data
 		public void EndEdit() 
 		{
 			rowState = DataRowState.Modified;
+			if (proposed != null)
+			{
+				Array.Copy (proposed, current, table.Columns.Count);
+				proposed = null;
+			}
 		}
 
 		/// <summary>
@@ -503,7 +510,20 @@ namespace System.Data
 		[MonoTODO]
 		public void RejectChanges () 
 		{
+			Array.Copy (original, current, table.Columns.Count);
 			CancelEdit ();
+			switch (rowState)
+			{
+				case DataRowState.Added:
+					table.Rows.Remove (this);
+					break;
+				case DataRowState.Modified:
+					rowState = DataRowState.Unchanged;
+					break;
+				case DataRowState.Deleted:
+					rowState = DataRowState.Unchanged;
+					break;
+			}
 		}
 
 		/// <summary>