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
;
47 if (this.source
== null)
48 this.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 int fieldCount
= FieldCount
;
164 //target object is byval so we can not just assign new object[] to values , calling side will not change
165 //hence copy each item into values
166 for (i
= 0; i
< values
.Length
&& i
< fieldCount
; ++i
)
167 values
[i
] = Current
[i
];
171 public bool IsDBNull (int i
)
173 return Current
.IsNull (i
);
176 public bool GetBoolean (int i
)
178 return (bool) Current
[i
];
181 public byte GetByte (int i
)
183 return (byte) Current
[i
];
186 public char GetChar (int i
)
188 return (char) Current
[i
];
191 public DateTime
GetDateTime (int i
)
193 return (DateTime
) Current
[i
];
196 public decimal GetDecimal (int i
)
198 return (decimal) Current
[i
];
201 public double GetDouble (int i
)
203 return (double) Current
[i
];
206 public float GetFloat (int i
)
208 return (float) Current
[i
];
211 public Guid
GetGuid (int i
)
213 return (Guid
) Current
[i
];
216 public short GetInt16 (int i
)
218 return (short) Current
[i
];
221 public int GetInt32 (int i
)
223 return (int) Current
[i
];
226 public long GetInt64 (int i
)
228 return (long) Current
[i
];
231 public string GetString (int i
)
233 return (string) Current
[i
];
236 public object GetValue (int i
)