DbDataReader.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // System.Data.Common.DbDataReader.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2003
  8. //
  9. //
  10. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. #if NET_2_0 || TARGET_JVM
  32. using System.Collections;
  33. using System.ComponentModel;
  34. using System.Data;
  35. namespace System.Data.Common {
  36. public abstract class DbDataReader : MarshalByRefObject, IDataReader, IDataRecord, IDisposable, IEnumerable
  37. {
  38. #region Constructors
  39. protected DbDataReader ()
  40. {
  41. }
  42. #endregion // Constructors
  43. #region Properties
  44. public abstract int Depth { get; }
  45. public abstract int FieldCount { get; }
  46. public abstract bool HasRows { get; }
  47. public abstract bool IsClosed { get; }
  48. public abstract object this [int index] { get; }
  49. public abstract object this [string name] { get; }
  50. public abstract int RecordsAffected { get; }
  51. #if NET_2_0
  52. [MonoTODO]
  53. public virtual int VisibleFieldCount {
  54. get { return FieldCount; }
  55. }
  56. #endif
  57. #endregion // Properties
  58. #region Methods
  59. public abstract void Close ();
  60. public abstract bool GetBoolean (int i);
  61. public abstract byte GetByte (int i);
  62. public abstract long GetBytes (int i, long fieldOffset, byte[] buffer, int bufferOffset, int length);
  63. public abstract char GetChar (int i);
  64. public abstract long GetChars (int i, long dataIndex, char[] buffer, int bufferIndex, int length);
  65. [EditorBrowsable (EditorBrowsableState.Never)]
  66. public void Dispose ()
  67. {
  68. Dispose (true);
  69. }
  70. protected virtual void Dispose (bool disposing)
  71. {
  72. if (disposing)
  73. Close ();
  74. }
  75. #if NET_2_0
  76. [MonoTODO]
  77. [EditorBrowsable (EditorBrowsableState.Never)]
  78. public DbDataReader GetData (int i)
  79. {
  80. throw new NotImplementedException ();
  81. }
  82. #endif
  83. public abstract string GetDataTypeName (int i);
  84. public abstract DateTime GetDateTime (int i);
  85. public abstract decimal GetDecimal (int i);
  86. public abstract double GetDouble (int i);
  87. [EditorBrowsable (EditorBrowsableState.Never)]
  88. public abstract IEnumerator GetEnumerator ();
  89. public abstract Type GetFieldType (int i);
  90. public abstract float GetFloat (int i);
  91. public abstract Guid GetGuid (int i);
  92. public abstract short GetInt16 (int i);
  93. public abstract int GetInt32 (int i);
  94. public abstract long GetInt64 (int i);
  95. public abstract string GetName (int i);
  96. public abstract int GetOrdinal (string name);
  97. #if NET_2_0
  98. [MonoTODO]
  99. [EditorBrowsable (EditorBrowsableState.Never)]
  100. public virtual Type GetProviderSpecificFieldType (int i)
  101. {
  102. return GetFieldType (i);
  103. }
  104. [MonoTODO]
  105. [EditorBrowsable (EditorBrowsableState.Never)]
  106. public virtual object GetProviderSpecificValue (int i)
  107. {
  108. return GetValue (i);
  109. }
  110. [MonoTODO]
  111. [EditorBrowsable (EditorBrowsableState.Never)]
  112. public virtual int GetProviderSpecificValues (object[] values)
  113. {
  114. return GetValues (values);
  115. }
  116. [MonoTODO]
  117. protected virtual DbDataReader GetDbDataReader (int ordinal)
  118. {
  119. throw new NotSupportedException ();
  120. }
  121. #endif
  122. public abstract DataTable GetSchemaTable ();
  123. public abstract string GetString (int i);
  124. public abstract object GetValue (int i);
  125. public abstract int GetValues (object[] values);
  126. IDataReader IDataRecord.GetData (int i)
  127. {
  128. return ((IDataReader) this).GetData (i);
  129. }
  130. public abstract bool IsDBNull (int i);
  131. public abstract bool NextResult ();
  132. public abstract bool Read ();
  133. internal static DataTable GetSchemaTableTemplate ()
  134. {
  135. Type booleanType = Type.GetType ("System.Boolean");
  136. Type stringType = Type.GetType ("System.String");
  137. Type intType = Type.GetType ("System.Int32");
  138. Type typeType = Type.GetType ("System.Type");
  139. Type shortType = Type.GetType ("System.Int16");
  140. DataTable schemaTable = new DataTable ("SchemaTable");
  141. schemaTable.Columns.Add ("ColumnName", stringType);
  142. schemaTable.Columns.Add ("ColumnOrdinal", intType);
  143. schemaTable.Columns.Add ("ColumnSize", intType);
  144. schemaTable.Columns.Add ("NumericPrecision", shortType);
  145. schemaTable.Columns.Add ("NumericScale", shortType);
  146. schemaTable.Columns.Add ("IsUnique", booleanType);
  147. schemaTable.Columns.Add ("IsKey", booleanType);
  148. schemaTable.Columns.Add ("BaseServerName", stringType);
  149. schemaTable.Columns.Add ("BaseCatalogName", stringType);
  150. schemaTable.Columns.Add ("BaseColumnName", stringType);
  151. schemaTable.Columns.Add ("BaseSchemaName", stringType);
  152. schemaTable.Columns.Add ("BaseTableName", stringType);
  153. schemaTable.Columns.Add ("DataType", typeType);
  154. schemaTable.Columns.Add ("AllowDBNull", booleanType);
  155. schemaTable.Columns.Add ("ProviderType", intType);
  156. schemaTable.Columns.Add ("IsAliased", booleanType);
  157. schemaTable.Columns.Add ("IsExpression", booleanType);
  158. schemaTable.Columns.Add ("IsIdentity", booleanType);
  159. schemaTable.Columns.Add ("IsAutoIncrement", booleanType);
  160. schemaTable.Columns.Add ("IsRowVersion", booleanType);
  161. schemaTable.Columns.Add ("IsHidden", booleanType);
  162. schemaTable.Columns.Add ("IsLong", booleanType);
  163. schemaTable.Columns.Add ("IsReadOnly", booleanType);
  164. return schemaTable;
  165. }
  166. #endregion // Methods
  167. }
  168. }
  169. #endif