+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.
{
#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;
}
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)
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)
{
#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
{
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
public object Current {
get {
- object[] values = new object[fieldCount];
reader.GetValues (values);
- return new DbDataRecord (schema, values, lookup);
+ return new DbDataRecord (schema, values);
}
}
#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;
schema [i] = columnSchema;
}
+
+ return schema;
}
public bool MoveNext ()