2 // System.Data.Common.DbDataReader.cs
5 // Tim Coleman (tim@timcoleman.com)
7 // Copyright (C) Tim Coleman, 2003
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
34 using System.ComponentModel;
39 using System.Threading;
40 using System.Threading.Tasks;
43 namespace System.Data.Common {
44 public abstract class DbDataReader : MarshalByRefObject, IDataReader, IDataRecord, IDisposable, IEnumerable
48 protected DbDataReader ()
52 #endregion // Constructors
56 public abstract int Depth { get; }
57 public abstract int FieldCount { get; }
58 public abstract bool HasRows { get; }
59 public abstract bool IsClosed { get; }
60 public abstract object this [int ordinal] { get; }
61 public abstract object this [string name] { get; }
62 public abstract int RecordsAffected { get; }
65 public virtual int VisibleFieldCount {
66 get { return FieldCount; }
69 #endregion // Properties
73 public abstract void Close ();
74 public abstract bool GetBoolean (int ordinal);
75 public abstract byte GetByte (int ordinal);
76 public abstract long GetBytes (int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length);
77 public abstract char GetChar (int ordinal);
78 public abstract long GetChars (int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length);
80 [EditorBrowsable (EditorBrowsableState.Never)]
81 public void Dispose ()
86 protected virtual void Dispose (bool disposing)
92 [EditorBrowsable (EditorBrowsableState.Never)]
93 public DbDataReader GetData (int ordinal)
95 return ((DbDataReader) this [ordinal]);
99 public abstract string GetDataTypeName (int ordinal);
100 public abstract DateTime GetDateTime (int ordinal);
101 public abstract decimal GetDecimal (int ordinal);
102 public abstract double GetDouble (int ordinal);
104 [EditorBrowsable (EditorBrowsableState.Never)]
105 public abstract IEnumerator GetEnumerator ();
107 public abstract Type GetFieldType (int ordinal);
108 public abstract float GetFloat (int ordinal);
109 public abstract Guid GetGuid (int ordinal);
110 public abstract short GetInt16 (int ordinal);
111 public abstract int GetInt32 (int ordinal);
112 public abstract long GetInt64 (int ordinal);
113 public abstract string GetName (int ordinal);
114 public abstract int GetOrdinal (string name);
117 [EditorBrowsable (EditorBrowsableState.Never)]
118 public virtual Type GetProviderSpecificFieldType (int ordinal)
120 return GetFieldType (ordinal);
123 [EditorBrowsable (EditorBrowsableState.Never)]
124 public virtual object GetProviderSpecificValue (int ordinal)
126 return GetValue (ordinal);
129 [EditorBrowsable (EditorBrowsableState.Never)]
130 public virtual int GetProviderSpecificValues (object[] values)
132 return GetValues (values);
135 protected virtual DbDataReader GetDbDataReader (int ordinal)
137 return ((DbDataReader) this [ordinal]);
141 public abstract DataTable GetSchemaTable ();
142 public abstract string GetString (int ordinal);
143 public abstract object GetValue (int ordinal);
144 public abstract int GetValues (object[] values);
146 IDataReader IDataRecord.GetData (int ordinal)
148 return ((IDataReader) this).GetData (ordinal);
151 public abstract bool IsDBNull (int ordinal);
152 public abstract bool NextResult ();
153 public abstract bool Read ();
155 internal static DataTable GetSchemaTableTemplate ()
157 Type booleanType = typeof (bool);
158 Type stringType = typeof (string);
159 Type intType = typeof (int);
160 Type typeType = typeof (Type);
161 Type shortType = typeof (short);
163 DataTable schemaTable = new DataTable ("SchemaTable");
164 schemaTable.Columns.Add ("ColumnName", stringType);
165 schemaTable.Columns.Add ("ColumnOrdinal", intType);
166 schemaTable.Columns.Add ("ColumnSize", intType);
167 schemaTable.Columns.Add ("NumericPrecision", shortType);
168 schemaTable.Columns.Add ("NumericScale", shortType);
169 schemaTable.Columns.Add ("IsUnique", booleanType);
170 schemaTable.Columns.Add ("IsKey", booleanType);
171 schemaTable.Columns.Add ("BaseServerName", stringType);
172 schemaTable.Columns.Add ("BaseCatalogName", stringType);
173 schemaTable.Columns.Add ("BaseColumnName", stringType);
174 schemaTable.Columns.Add ("BaseSchemaName", stringType);
175 schemaTable.Columns.Add ("BaseTableName", stringType);
176 schemaTable.Columns.Add ("DataType", typeType);
177 schemaTable.Columns.Add ("AllowDBNull", booleanType);
178 schemaTable.Columns.Add ("ProviderType", intType);
179 schemaTable.Columns.Add ("IsAliased", booleanType);
180 schemaTable.Columns.Add ("IsExpression", booleanType);
181 schemaTable.Columns.Add ("IsIdentity", booleanType);
182 schemaTable.Columns.Add ("IsAutoIncrement", booleanType);
183 schemaTable.Columns.Add ("IsRowVersion", booleanType);
184 schemaTable.Columns.Add ("IsHidden", booleanType);
185 schemaTable.Columns.Add ("IsLong", booleanType);
186 schemaTable.Columns.Add ("IsReadOnly", booleanType);
193 public virtual T GetFieldValue<T> (int i)
195 throw new NotImplementedException ();
198 public Task<T> GetFieldValueAsync<T> (int ordinal)
200 return GetFieldValueAsync<T> (ordinal, CancellationToken.None);
204 public virtual Task<T> GetFieldValueAsync<T> (int ordinal, CancellationToken cancellationToken)
206 throw new NotImplementedException ();
209 public Task<bool> NextResultAsync ()
211 return NextResultAsync (CancellationToken.None);
214 public Task<bool> IsDBNullAsync (int ordinal)
216 return IsDBNullAsync (ordinal, CancellationToken.None);
220 public virtual Stream GetStream (int i)
222 throw new NotImplementedException ();
226 public virtual TextReader GetTextReader (int i)
228 throw new NotImplementedException ();
232 public virtual Task<bool> IsDBNullAsync (int ordinal, CancellationToken cancellationToken)
234 throw new NotImplementedException ();
238 public virtual Task<bool> NextResultAsync (CancellationToken cancellationToken)
240 throw new NotImplementedException ();
243 public Task<bool> ReadAsync ()
245 return ReadAsync (CancellationToken.None);
249 public virtual Task<bool> ReadAsync (CancellationToken cancellationToken)
251 throw new NotImplementedException ();
255 #endregion // Methods