Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / System.Data / System.Data.Common / DbDataReader.cs
1 //
2 // System.Data.Common.DbDataReader.cs
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //
7 // Copyright (C) Tim Coleman, 2003
8 //
9
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
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:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
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.
31 //
32
33 using System.Collections;
34 using System.ComponentModel;
35 using System.Data;
36 using System.IO;
37
38 #if NET_4_5
39 using System.Threading;
40 using System.Threading.Tasks;
41 #endif
42
43 namespace System.Data.Common {
44         public abstract class DbDataReader : MarshalByRefObject, IDataReader, IDataRecord, IDisposable, IEnumerable
45         {
46                 #region Constructors
47
48                 protected DbDataReader ()
49                 {
50                 }
51
52                 #endregion // Constructors
53
54                 #region Properties
55
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; }
63
64 #if NET_2_0
65                 public virtual int VisibleFieldCount {
66                         get { return FieldCount; }
67                 }
68 #endif
69                 #endregion // Properties
70
71                 #region Methods
72
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);
79
80                 [EditorBrowsable (EditorBrowsableState.Never)]
81                 public void Dispose ()
82                 {
83                         Dispose (true); 
84                 }
85                 
86                 protected virtual void Dispose (bool disposing)
87                 {
88                         if (disposing)
89                                 Close ();
90                 }
91 #if NET_2_0
92                 [EditorBrowsable (EditorBrowsableState.Never)]
93                 public DbDataReader GetData (int ordinal)
94                 {
95                         return ((DbDataReader) this [ordinal]);
96                 }
97 #endif
98
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);
103
104                 [EditorBrowsable (EditorBrowsableState.Never)]
105                 public abstract IEnumerator GetEnumerator ();
106
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);
115
116 #if NET_2_0
117                 [EditorBrowsable (EditorBrowsableState.Never)]
118                 public virtual Type GetProviderSpecificFieldType (int ordinal)
119                 {
120                         return GetFieldType (ordinal);
121                 }
122
123                 [EditorBrowsable (EditorBrowsableState.Never)]
124                 public virtual object GetProviderSpecificValue (int ordinal)
125                 {
126                         return GetValue (ordinal);
127                 }
128
129                 [EditorBrowsable (EditorBrowsableState.Never)]
130                 public virtual int GetProviderSpecificValues (object[] values)
131                 {
132                         return GetValues (values);
133                 }
134         
135                 protected virtual DbDataReader GetDbDataReader (int ordinal)
136                 {
137                         return ((DbDataReader) this [ordinal]);
138                 }
139 #endif 
140
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);
145
146                 IDataReader IDataRecord.GetData (int ordinal)
147                 {
148                         return ((IDataReader) this).GetData (ordinal);
149                 }
150
151                 public abstract bool IsDBNull (int ordinal);
152                 public abstract bool NextResult ();
153                 public abstract bool Read ();
154
155                 internal static DataTable GetSchemaTableTemplate ()
156                 {
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);
162
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);
187
188                         return schemaTable;
189                 }
190                 
191 #if NET_4_5
192                 [MonoTODO]
193                 public virtual T GetFieldValue<T> (int i)
194                 {
195                         throw new NotImplementedException ();
196                 }
197
198                 public Task<T> GetFieldValueAsync<T> (int ordinal)
199                 {
200                         return GetFieldValueAsync<T> (ordinal, CancellationToken.None);
201                 }
202                 
203                 [MonoTODO]
204                 public virtual Task<T> GetFieldValueAsync<T> (int ordinal, CancellationToken cancellationToken)
205                 {
206                         throw new NotImplementedException ();
207                 }
208                 
209                 public Task<bool> NextResultAsync ()
210                 {
211                         return NextResultAsync (CancellationToken.None);
212                 }
213                 
214                 public Task<bool> IsDBNullAsync (int ordinal)
215                 {
216                         return IsDBNullAsync (ordinal, CancellationToken.None);
217                 }
218
219                 [MonoTODO]
220                 public virtual Stream GetStream (int i)
221                 {
222                         throw new NotImplementedException ();
223                 }
224                 
225                 [MonoTODO]
226                 public virtual TextReader GetTextReader (int i)
227                 {
228                         throw new NotImplementedException ();   
229                 }
230
231                 [MonoTODO]
232                 public virtual Task<bool> IsDBNullAsync (int ordinal, CancellationToken cancellationToken)
233                 {
234                         throw new NotImplementedException ();
235                 }
236                 
237                 [MonoTODO]
238                 public virtual Task<bool> NextResultAsync (CancellationToken cancellationToken)
239                 {
240                         throw new NotImplementedException ();
241                 }
242                 
243                 public Task<bool> ReadAsync ()
244                 {
245                         return ReadAsync (CancellationToken.None);
246                 }
247                 
248                 [MonoTODO]
249                 public virtual Task<bool> ReadAsync (CancellationToken cancellationToken)
250                 {
251                         throw new NotImplementedException ();
252                 }
253 #endif
254
255                 #endregion // Methods
256         }
257 }
258