2004-04-29 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 29 Apr 2004 08:01:47 +0000 (08:01 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 29 Apr 2004 08:01:47 +0000 (08:01 -0000)
* DataRow.cs : When Column was added and it was AutoIncrement column,
  it extended the item object array incorrectly.
  (Plus tiny comment and incorrect indentation fix.)

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

mcs/class/System.Data/System.Data/ChangeLog
mcs/class/System.Data/System.Data/DataRow.cs

index da331bca6d0e0ae386ed47bf20ebc356818b69c6..6bfacc2501f3829199940a582caae9e2dc295a09 100644 (file)
@@ -1,3 +1,9 @@
+2004-04-29  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * DataRow.cs : When Column was added and it was AutoIncrement column,
+         it extended the item object array incorrectly.
+         (Plus tiny comment and incorrect indentation fix.)
+
 2004-04-29  Boris Kirzner <borisk@mainsoft.com>
 
        * MergeManager.cs : added ( incomplete yet ) support for merging DataSet schema.
index 6b0ed9e5726f98e604bd3a765b9169c297b42f07..c0c3be300efb6fb283ae1b0842a98dc9635f35fa 100644 (file)
@@ -294,8 +294,9 @@ namespace System.Data {
                                }
                                else if(col.AutoIncrement == true && CanAccess(index,DataRowVersion.Default)) 
                                {
+                                       // New value is computed at .ctor(), so
+                                       // we don't have to do anything here.
                                        newval = this [index];
-//                                     newval = col.AutoIncrementValue ();
                                }
                                else 
                                {
@@ -1283,27 +1284,26 @@ namespace System.Data {
                        for(int i = 0; i < columns.Count; i++){
 
                                string columnName = columns[i].ColumnName;
-                               DataColumn column = row.Table.Columns[columnName];
+                               int index = row.Table.Columns.IndexOf(columnName);
                                //if a column with the same name exists in both rows copy the values
-                               if(column != null) {
-                                       int index = column.Ordinal;
+                               if(index != -1) {
                                        if (HasVersion(DataRowVersion.Original))
                                        {
                                                if (row.original == null)
                                                        row.original = new object[row.Table.Columns.Count];
-                                               row.original[index] = row.SetColumnValue(original[i], column, index);
+                                               row.original[index] = row.SetColumnValue(original[i], Table.Columns[index], index);
                                        }
                                        if (HasVersion(DataRowVersion.Current))
                                        {
                                                if (row.current == null)
                                                        row.current = new object[row.Table.Columns.Count];
-                                               row.current[index] = row.SetColumnValue(current[i], column, index);
+                                               row.current[index] = row.SetColumnValue(current[i], Table.Columns[index], index);
                                        }
                                        if (HasVersion(DataRowVersion.Proposed))
                                        {
                                                if (row.proposed == null)
                                                        row.proposed = new object[row.Table.Columns.Count];
-                                               row.proposed[index] = row.SetColumnValue(proposed[i], column, index);
+                                               row.proposed[index] = row.SetColumnValue(proposed[i], Table.Columns[index], index);
                                        }
                                        
                                        //Saving the current value as the column value
@@ -1330,21 +1330,22 @@ namespace System.Data {
                                int index = this.Table.Columns.Count - 1;
                                if (current != null)
                                {
-                                       tmp = new object[current.Length + 1];
+                                       // When AutoIncrement column was added, current item array length automatically increases
+                                       tmp = new object [Table.Columns.Count];
                                        Array.Copy (current, tmp, current.Length);
                                        tmp[tmp.Length - 1] = SetColumnValue(null, this.Table.Columns[index], index);
                                        current = tmp;
                                }
                                if (proposed != null)
                                {
-                                       tmp = new object[proposed.Length + 1];
+                                       tmp = new object [Table.Columns.Count];
                                        Array.Copy (proposed, tmp, proposed.Length);
                                        tmp[tmp.Length - 1] = SetColumnValue(null, this.Table.Columns[index], index);
                                        proposed = tmp;
                                }
                                if(original != null)
                                {
-                                       tmp = new object[original.Length + 1];
+                                       tmp = new object [Table.Columns.Count];
                                        Array.Copy (original, tmp, original.Length);
                                        tmp[tmp.Length - 1] = SetColumnValue(null, this.Table.Columns[index], index);
                                        original = tmp;
@@ -1479,9 +1480,9 @@ namespace System.Data {
                        if (_nullConstraintViolation) {
                                if (proposed != null) {
                                        for (int i = 0; i < proposed.Length; i++) {
-                                       if (this[i] == DBNull.Value && !_table.Columns[i].AllowDBNull)
-                                               throw new NoNullAllowedException(_nullConstraintMessage);
-                               }
+                                               if (this[i] == DBNull.Value && !_table.Columns[i].AllowDBNull)
+                                                       throw new NoNullAllowedException(_nullConstraintMessage);
+                                       }
                                }
                                _nullConstraintViolation = false;
                        }