void IDataReader.Close() { rows = null; nextResult = null; fields = null; ordinals = null; recordIndex = -1; }
void IDisposable.Dispose() { rows = null; nextResult = null; fields = null; ordinals = null; recordIndex = -1; }
/// <summary> /// Caches a data reader to enable disconnected data access via the IDataReader interface. /// </summary> /// <param name="reader">The IDataReader to cache.</param> public DisconnectedReader(IDataReader reader) { // Cache field information this.fields = new FieldInfo[reader.FieldCount]; this.ordinals = new Hashtable(StringComparer.OrdinalIgnoreCase); for (int index = 0; index < fields.Length; index++) { FieldInfo field = new FieldInfo(); field.Name = reader.GetName(index); field.Type = reader.GetFieldType(index); field.DataTypeName = reader.GetDataTypeName(index); fields[index] = field; if (!ordinals.Contains(field.Name)) { ordinals.Add(field.Name, index); } } // Cache schema info schema = reader.GetSchemaTable(); // Cache row data rows = new ArrayList(); while (reader.Read()) { object[] values = new object[fields.Length]; reader.GetValues(values); rows.Add(values); } // Cache additional results if (reader.NextResult()) { nextResult = new DisconnectedReader(reader); } // Close the reader once all data has been cached else { reader.Dispose(); } // Set the record index before the first record; this.recordIndex = -1; this.lastIndex = rows.Count - 1; }
bool IDataReader.NextResult() { if (nextResult == null) { return(false); } this.fields = nextResult.fields; this.ordinals = nextResult.ordinals; this.rows = nextResult.rows; this.schema = nextResult.schema; this.recordIndex = -1; this.nextResult = nextResult.nextResult; this.lastIndex = rows.Count - 1; return(true); }
/// <summary> /// Caches a data reader to enable disconnected data access via the IDataReader interface. /// </summary> /// <param name="reader">The IDataReader to cache.</param> public DisconnectedReader(IDataReader reader) { // Cache field information this.fields = new FieldInfo[reader.FieldCount]; this.ordinals = new Hashtable(StringComparer.OrdinalIgnoreCase); for (int index = 0; index < fields.Length; index++) { FieldInfo field = new FieldInfo(); field.Name = reader.GetName(index); field.Type = reader.GetFieldType(index); field.DataTypeName = reader.GetDataTypeName(index); fields[index] = field; if (!ordinals.Contains(field.Name)) ordinals.Add(field.Name, index); } // Cache schema info schema = reader.GetSchemaTable(); // Cache row data rows = new ArrayList(); while (reader.Read()) { object[] values = new object[fields.Length]; reader.GetValues(values); rows.Add(values); } // Cache additional results if (reader.NextResult()) nextResult = new DisconnectedReader(reader); // Close the reader once all data has been cached else reader.Dispose(); // Set the record index before the first record; this.recordIndex = -1; this.lastIndex = rows.Count - 1; }
bool IDataReader.NextResult() { if (nextResult == null) return false; this.fields = nextResult.fields; this.ordinals = nextResult.ordinals; this.rows = nextResult.rows; this.schema = nextResult.schema; this.recordIndex = -1; this.nextResult = nextResult.nextResult; this.lastIndex = rows.Count - 1; return true; }