2 // RowEnumerableDataReader.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2008 Novell, Inc. http://www.novell.com
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Collections.Generic;
38 internal class RowEnumerableDataReader : IDataReader
40 EnumerableRowCollection source;
44 public RowEnumerableDataReader (IEnumerable source, int depth)
46 this.source = source as EnumerableRowCollection;
48 source = new EnumerableRowCollection<DataRow> ((IEnumerable<DataRow>) source);
52 public DataRow Current {
53 get { return e != null ? (DataRow) e.Current : null; }
60 public bool IsClosed {
61 get { return e == null; }
64 public int RecordsAffected {
73 public DataTable GetSchemaTable ()
75 return new DataTableReader (source.Table).GetSchemaTable ();
78 public bool NextResult ()
86 e = ((IEnumerable) source).GetEnumerator ();
91 public void Dispose ()
102 foreach (DataRow rr in source) {
109 public int FieldCount {
110 get { return GetTable ().Columns.Count; }
113 public object this [int i] {
114 get { return Current [i]; }
117 public object this [string name] {
118 get { return Current [name]; }
121 public string GetDataTypeName (int i)
123 return GetFieldType (i).Name;
126 public Type GetFieldType (int i)
128 return GetTable ().Columns [i].DataType;
131 public string GetName (int i)
133 return GetTable ().Columns [i].ColumnName;
136 public int GetOrdinal (string name)
138 return GetTable ().Columns [name].Ordinal;
141 public long GetBytes (int i, long fieldOffset, byte [] buffer, int bufferoffset, int length)
143 // FIXME: do we need it?
144 throw new NotSupportedException ();
147 public long GetChars (int i, long fieldOffset, char [] buffer, int bufferoffset, int length)
149 // FIXME: do we need it?
150 throw new NotSupportedException ();
153 public IDataReader GetData (int i)
155 // FIXME: do we need it?
156 throw new NotSupportedException ();
159 public int GetValues (object [] values)
161 // FIXME: do we need it?
162 throw new NotSupportedException ();
165 public bool IsDBNull (int i)
167 return Current.IsNull (i);
170 public bool GetBoolean (int i)
172 return (bool) Current [i];
175 public byte GetByte (int i)
177 return (byte) Current [i];
180 public char GetChar (int i)
182 return (char) Current [i];
185 public DateTime GetDateTime (int i)
187 return (DateTime) Current [i];
190 public decimal GetDecimal (int i)
192 return (decimal) Current [i];
195 public double GetDouble (int i)
197 return (double) Current [i];
200 public float GetFloat (int i)
202 return (float) Current [i];
205 public Guid GetGuid (int i)
207 return (Guid) Current [i];
210 public short GetInt16 (int i)
212 return (short) Current [i];
215 public int GetInt32 (int i)
217 return (int) Current [i];
220 public long GetInt64 (int i)
222 return (long) Current [i];
225 public string GetString (int i)
227 return (string) Current [i];
230 public object GetValue (int i)