DbEnumerator.cs, DbDataRecord.cs: refactoring; DbDataRecord.cs: GetValue() should...
authorKonstantin Triger <kostat@mono-cvs.ximian.com>
Mon, 24 Sep 2007 14:44:35 +0000 (14:44 -0000)
committerKonstantin Triger <kostat@mono-cvs.ximian.com>
Mon, 24 Sep 2007 14:44:35 +0000 (14:44 -0000)
svn path=/trunk/mcs/; revision=86257

mcs/class/System.Data/System.Data.Common/ChangeLog
mcs/class/System.Data/System.Data.Common/DbDataRecord.cs
mcs/class/System.Data/System.Data.Common/DbEnumerator.cs

index 2b7709bfc00a842e4bb0f3628660bf5bf0ef54b1..4a7550d5aa264b2736856aabb157e7f006394e8f 100644 (file)
@@ -1,3 +1,8 @@
+2007-09-24  Konstantin Triger <kostat@mainsoft.com>
+
+       * DbEnumerator.cs, DbDataRecord.cs: refactoring.
+       * DbDataRecord.cs: GetValue() should return null instead of DBNull.
+
 2007-08-10  Nagappan A  <anagappan@novell.com>
 
        * DbDataAdapter.cs (Fill): Fixed method signature.
index 14bd86589f02952ef9313254524c5664a7893907..479a88bc6cb4923cf56d0d534773112a4775e480 100644 (file)
@@ -39,19 +39,17 @@ namespace System.Data.Common {
        {
                #region Fields
 
-               SchemaInfo[] schema;
-               object[] values;
-               int fieldCount;
-               FieldNameLookup lookup;
+               readonly SchemaInfo [] schema;
+               readonly object [] values;
+               readonly int fieldCount;
 
                #endregion
                
                #region Constructors
 
-               internal DbDataRecord (SchemaInfo[] schema, object[] values, FieldNameLookup lookup)
+               internal DbDataRecord (SchemaInfo[] schema, object[] values)
                {
                        this.schema = schema;
-                       this.lookup = lookup;
                        this.values = values;
                        this.fieldCount = values.Length;
                }
@@ -190,12 +188,15 @@ namespace System.Data.Common {
 
                public string GetName (int i)
                {
-                       return (string) lookup [i];
+                       return schema [i].ColumnName;
                }
 
                public int GetOrdinal (string name)
                {
-                       return lookup.IndexOf (name);
+                       for (int i = 0; i < FieldCount; i++)
+                               if (schema [i].ColumnName == name)
+                                       return i;
+                       return -1;
                }
 
                public string GetString (int i)
@@ -208,10 +209,7 @@ namespace System.Data.Common {
                        if ((i < 0) || (i > fieldCount))
                                 throw new IndexOutOfRangeException();
 
-                       object value = values [i];
-                       if (value == null)
-                               value = DBNull.Value;
-                       return value;
+                       return values [i];
                }
 
                public int GetValues (object[] values)
index 1c02bbb232269485a4e2ae49feb5bcb91b659d94..440ae31a149efbd0e7586c9a0265f335dccfc308 100644 (file)
@@ -40,11 +40,10 @@ namespace System.Data.Common {
        {
                #region Fields
 
-               IDataReader reader;
-               bool closeReader;
-               SchemaInfo[] schema;
-               FieldNameLookup lookup;
-               int fieldCount;
+               readonly IDataReader reader;
+               readonly bool closeReader;
+               readonly SchemaInfo [] schema;
+               readonly object [] values;
        
                #endregion // Fields
 
@@ -59,9 +58,8 @@ namespace System.Data.Common {
                {
                        this.reader = reader;
                        this.closeReader = closeReader;
-                       this.lookup = new FieldNameLookup ();
-                       this.fieldCount = reader.FieldCount;
-                       LoadSchema ();
+                       this.values = new object [reader.FieldCount];
+                       this.schema = LoadSchema (reader);
                }
 
                #endregion // Constructors
@@ -70,9 +68,8 @@ namespace System.Data.Common {
 
                public object Current {
                        get { 
-                               object[] values = new object[fieldCount];
                                reader.GetValues (values);
-                               return new DbDataRecord (schema, values, lookup); 
+                               return new DbDataRecord (schema, values); 
                        }
                }
 
@@ -80,14 +77,13 @@ namespace System.Data.Common {
 
                #region Methods
 
-               private void LoadSchema ()
+               private static SchemaInfo[] LoadSchema (IDataReader reader)
                {
-                       schema = new SchemaInfo [fieldCount];
+                       int fieldCount = reader.FieldCount;
+                       SchemaInfo[] schema = new SchemaInfo [fieldCount];
 
                        for(int i=0; i < fieldCount; i++) {
                                SchemaInfo columnSchema = new SchemaInfo ();
-                               
-                               lookup.Add (reader.GetName(i));
 
                                columnSchema.ColumnName = reader.GetName(i);
                                columnSchema.ColumnOrdinal = i; 
@@ -96,6 +92,8 @@ namespace System.Data.Common {
 
                                schema [i] = columnSchema;
                        }
+
+                       return schema;
                }
 
                public bool MoveNext ()