2 // System.Data.OleDb.OleDbDataReader
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Tim Coleman (tim@timcoleman.com)
8 // Copyright (C) Rodrigo Moya, 2002
9 // Copyright (C) Tim Coleman, 2002
12 using System.Collections;
13 using System.ComponentModel;
15 using System.Data.Common;
17 namespace System.Data.OleDb
19 public sealed class OleDbDataReader : MarshalByRefObject, IDataReader, IDisposable, IDataRecord, IEnumerable
23 private OleDbCommand command;
25 private ArrayList gdaResults;
26 private int currentResult;
27 private int currentRow;
33 internal OleDbDataReader (OleDbCommand command, ArrayList results)
35 this.command = command;
40 gdaResults = new ArrayList ();
52 throw new NotImplementedException ();
56 public int FieldCount {
58 if (currentResult < 0 ||
59 currentResult >= gdaResults.Count)
62 return libgda.gda_data_model_get_n_columns (
63 (IntPtr) gdaResults[currentResult]);
67 public bool IsClosed {
73 public object this[string name] {
76 throw new NotImplementedException ();
80 public object this[int index] {
82 if (currentResult < 0 ||
83 currentResult >= gdaResults.Count)
86 return libgda.gda_data_model_get_value_at (
87 (IntPtr) gdaResults[currentResult],
93 public int RecordsAffected {
97 if (currentResult < 0 ||
98 currentResult >= gdaResults.Count)
101 total_rows = libgda.gda_data_model_get_n_rows (
102 (IntPtr) gdaResults[currentResult]);
103 if (total_rows > 0) {
104 if (FieldCount > 0) {
105 // It's a SELECT statement
110 return FieldCount > 0 ? -1 : total_rows;
121 throw new NotImplementedException ();
127 throw new NotImplementedException ();
130 public bool GetBoolean (int ordinal)
134 if (currentResult == -1)
135 throw new InvalidCastException ();
137 value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
138 ordinal, currentRow);
139 if (value == IntPtr.Zero)
140 throw new InvalidCastException ();
142 if (libgda.gda_value_get_vtype (value) != GdaValueType.Boolean)
143 throw new InvalidCastException ();
144 return libgda.gda_value_get_boolean (value);
147 public byte GetByte (int ordinal)
151 if (currentResult == -1)
152 throw new InvalidCastException ();
154 value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
155 ordinal, currentRow);
156 if (value == IntPtr.Zero)
157 throw new InvalidCastException ();
159 if (libgda.gda_value_get_vtype (value) != GdaValueType.Tinyint)
160 throw new InvalidCastException ();
161 return libgda.gda_value_get_tinyint (value);
165 public long GetBytes (int ordinal, long dataIndex, byte[] buffer, int bufferIndex, int length)
167 throw new NotImplementedException ();
170 public char GetChar (int ordinal)
174 if (currentResult == -1)
175 throw new InvalidCastException ();
177 value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
178 ordinal, currentRow);
179 if (value == IntPtr.Zero)
180 throw new InvalidCastException ();
182 if (libgda.gda_value_get_vtype (value) != GdaValueType.Tinyint)
183 throw new InvalidCastException ();
184 return (char) libgda.gda_value_get_tinyint (value);
188 public long GetChars (int ordinal, long dataIndex, char[] buffer, int bufferIndex, int length)
190 throw new NotImplementedException ();
194 public OleDbDataReader GetData (int ordinal)
196 throw new NotImplementedException ();
199 public string GetDataTypeName (int index)
203 if (currentResult == -1)
206 value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
208 if (value == IntPtr.Zero)
211 return libgda.gda_type_to_string (libgda.gda_value_get_vtype (value));
215 public DateTime GetDateTime (int ordinal)
217 throw new NotImplementedException ();
221 public decimal GetDecimal (int ordinal)
223 throw new NotImplementedException ();
227 public double GetDouble (int ordinal)
229 throw new NotImplementedException ();
233 public Type GetFieldType (int index)
235 throw new NotImplementedException ();
239 public float GetFloat (int ordinal)
241 throw new NotImplementedException ();
245 public Guid GetGuid (int ordinal)
247 throw new NotImplementedException ();
251 public short GetInt16 (int ordinal)
253 throw new NotImplementedException ();
257 public int GetInt32 (int ordinal)
259 throw new NotImplementedException ();
263 public long GetInt64 (int ordinal)
265 throw new NotImplementedException ();
269 public string GetName (int index)
271 throw new NotImplementedException ();
275 public int GetOrdinal (string name)
277 throw new NotImplementedException ();
281 public DataTable GetSchemaTable ()
283 throw new NotImplementedException ();
287 public string GetString (int ordinal)
289 throw new NotImplementedException ();
293 public TimeSpan GetTimeSpan (int ordinal)
295 throw new NotImplementedException ();
298 public object GetValue (int ordinal)
303 if (currentResult == -1)
304 throw new IndexOutOfRangeException ();
306 value = libgda.gda_data_model_get_value_at ((IntPtr) gdaResults[currentResult],
307 ordinal, currentRow);
308 if (value == IntPtr.Zero)
309 throw new IndexOutOfRangeException ();
311 type = libgda.gda_value_get_vtype (value);
312 // FIXME: return correct type
314 return (object) libgda.gda_value_stringify (value);
318 public int GetValues (object[] values)
320 throw new NotImplementedException ();
324 IDataReader IDataRecord.GetData (int ordinal)
326 throw new NotImplementedException ();
330 void IDisposable.Dispose ()
332 throw new NotImplementedException ();
336 IEnumerator IEnumerable.GetEnumerator ()
338 throw new NotImplementedException ();
342 public bool IsDBNull (int ordinal)
344 throw new NotImplementedException ();
347 public bool NextResult ()
349 int i = currentResult + 1;
350 if (i >= 0 && i < gdaResults.Count) {
360 if (currentResult < 0 ||
361 currentResult >= gdaResults.Count)
366 libgda.gda_data_model_get_n_rows ((IntPtr) gdaResults[currentResult]))