New test.
[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 #if NET_2_0 || TARGET_JVM
34
35 using System.Collections;
36 using System.ComponentModel;
37 using System.Data;
38
39 namespace System.Data.Common {
40         public abstract class DbDataReader : MarshalByRefObject, IDataReader, IDataRecord, IDisposable, IEnumerable
41         {
42                 #region Constructors
43
44                 protected DbDataReader ()
45                 {
46                 }
47
48                 #endregion // Constructors
49
50                 #region Properties
51
52                 public abstract int Depth { get; }
53                 public abstract int FieldCount { get; }
54                 public abstract bool HasRows { get; }
55                 public abstract bool IsClosed { get; }
56                 public abstract object this [int index] { get; }
57                 public abstract object this [string name] { get; }
58                 public abstract int RecordsAffected { get; }
59
60 #if NET_2_0
61                 [MonoTODO]
62                 public virtual int VisibleFieldCount {
63                         get { return FieldCount; }
64                 }
65 #endif
66                 #endregion // Properties
67
68                 #region Methods
69
70                 public abstract void Close ();
71                 public abstract bool GetBoolean (int i);
72                 public abstract byte GetByte (int i);
73                 public abstract long GetBytes (int i, long fieldOffset, byte[] buffer, int bufferOffset, int length);
74                 public abstract char GetChar (int i);
75                 public abstract long GetChars (int i, long dataIndex, char[] buffer, int bufferIndex, int length);
76
77                 [EditorBrowsable (EditorBrowsableState.Never)]
78                 public void Dispose ()
79                 {
80                         Dispose (true); 
81                 }
82                 
83                 protected virtual void Dispose (bool disposing)
84                 {
85                         if (disposing)
86                                 Close ();
87                 }
88 #if NET_2_0
89                 [MonoTODO]
90                 [EditorBrowsable (EditorBrowsableState.Never)]
91                 public DbDataReader GetData (int i)
92                 {
93                         throw new NotImplementedException ();
94                 }
95 #endif
96
97                 public abstract string GetDataTypeName (int i);
98                 public abstract DateTime GetDateTime (int i);
99                 public abstract decimal GetDecimal (int i);
100                 public abstract double GetDouble (int i);
101
102                 [EditorBrowsable (EditorBrowsableState.Never)]
103                 public abstract IEnumerator GetEnumerator ();
104
105                 public abstract Type GetFieldType (int i);
106                 public abstract float GetFloat (int i);
107                 public abstract Guid GetGuid (int i);
108                 public abstract short GetInt16 (int i);
109                 public abstract int GetInt32 (int i);
110                 public abstract long GetInt64 (int i);
111                 public abstract string GetName (int i);
112                 public abstract int GetOrdinal (string name);
113
114 #if NET_2_0
115                 [MonoTODO]
116                 [EditorBrowsable (EditorBrowsableState.Never)]
117                 public virtual Type GetProviderSpecificFieldType (int i)
118                 {
119                         return GetFieldType (i);
120                 }
121
122                 [MonoTODO]
123                 [EditorBrowsable (EditorBrowsableState.Never)]
124                 public virtual object GetProviderSpecificValue (int i)
125                 {
126                         return GetValue (i);
127                 }
128
129                 [MonoTODO]
130                 [EditorBrowsable (EditorBrowsableState.Never)]
131                 public virtual int GetProviderSpecificValues (object[] values)
132                 {
133                         return GetValues (values);
134                 }
135         
136                 [MonoTODO]
137                 protected virtual DbDataReader GetDbDataReader (int ordinal)
138                 {
139                         throw new NotSupportedException ();
140                 }
141 #endif 
142
143                 public abstract DataTable GetSchemaTable ();
144                 public abstract string GetString (int i);
145                 public abstract object GetValue (int i);
146                 public abstract int GetValues (object[] values);
147
148                 IDataReader IDataRecord.GetData (int i)
149                 {
150                         return ((IDataReader) this).GetData (i);
151                 }
152
153                 public abstract bool IsDBNull (int i);
154                 public abstract bool NextResult ();
155                 public abstract bool Read ();
156
157                 internal static DataTable GetSchemaTableTemplate ()
158                 {
159                         Type booleanType        = Type.GetType ("System.Boolean");
160                         Type stringType         = Type.GetType ("System.String");
161                         Type intType            = Type.GetType ("System.Int32");
162                         Type typeType           = Type.GetType ("System.Type");
163                         Type shortType          = Type.GetType ("System.Int16");
164
165                         DataTable schemaTable = new DataTable ("SchemaTable");
166                         schemaTable.Columns.Add ("ColumnName",          stringType);
167                         schemaTable.Columns.Add ("ColumnOrdinal",       intType);
168                         schemaTable.Columns.Add ("ColumnSize",          intType);
169                         schemaTable.Columns.Add ("NumericPrecision",    shortType);
170                         schemaTable.Columns.Add ("NumericScale",        shortType);
171                         schemaTable.Columns.Add ("IsUnique",            booleanType);
172                         schemaTable.Columns.Add ("IsKey",               booleanType);
173                         schemaTable.Columns.Add ("BaseServerName",      stringType);
174                         schemaTable.Columns.Add ("BaseCatalogName",     stringType);
175                         schemaTable.Columns.Add ("BaseColumnName",      stringType);
176                         schemaTable.Columns.Add ("BaseSchemaName",      stringType);
177                         schemaTable.Columns.Add ("BaseTableName",       stringType);
178                         schemaTable.Columns.Add ("DataType",            typeType);
179                         schemaTable.Columns.Add ("AllowDBNull",         booleanType);
180                         schemaTable.Columns.Add ("ProviderType",        intType);
181                         schemaTable.Columns.Add ("IsAliased",           booleanType);
182                         schemaTable.Columns.Add ("IsExpression",        booleanType);
183                         schemaTable.Columns.Add ("IsIdentity",          booleanType);
184                         schemaTable.Columns.Add ("IsAutoIncrement",     booleanType);
185                         schemaTable.Columns.Add ("IsRowVersion",        booleanType);
186                         schemaTable.Columns.Add ("IsHidden",            booleanType);
187                         schemaTable.Columns.Add ("IsLong",              booleanType);
188                         schemaTable.Columns.Add ("IsReadOnly",          booleanType);
189
190                         return schemaTable;
191                 }
192
193                 #endregion // Methods
194         }
195 }
196
197 #endif