DbDataReader.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. public virtual int VisibleFieldCount {
  53. get { return FieldCount; }
  54. }
  55. #endif
  56. #endregion // Properties
  57. #region Methods
  58. public abstract void Close ();
  59. public abstract bool GetBoolean (int i);
  60. public abstract byte GetByte (int i);
  61. public abstract long GetBytes (int i, long fieldOffset, byte[] buffer, int bufferOffset, int length);
  62. public abstract char GetChar (int i);
  63. public abstract long GetChars (int i, long dataIndex, char[] buffer, int bufferIndex, int length);
  64. [EditorBrowsable (EditorBrowsableState.Never)]
  65. public void Dispose ()
  66. {
  67. Dispose (true);
  68. }
  69. protected virtual void Dispose (bool disposing)
  70. {
  71. if (disposing)
  72. Close ();
  73. }
  74. #if NET_2_0
  75. [EditorBrowsable (EditorBrowsableState.Never)]
  76. public DbDataReader GetData (int i)
  77. {
  78. return ((DbDataReader) this [i]);
  79. }
  80. #endif
  81. public abstract string GetDataTypeName (int i);
  82. public abstract DateTime GetDateTime (int i);
  83. public abstract decimal GetDecimal (int i);
  84. public abstract double GetDouble (int i);
  85. [EditorBrowsable (EditorBrowsableState.Never)]
  86. public abstract IEnumerator GetEnumerator ();
  87. public abstract Type GetFieldType (int i);
  88. public abstract float GetFloat (int i);
  89. public abstract Guid GetGuid (int i);
  90. public abstract short GetInt16 (int i);
  91. public abstract int GetInt32 (int i);
  92. public abstract long GetInt64 (int i);
  93. public abstract string GetName (int i);
  94. public abstract int GetOrdinal (string name);
  95. #if NET_2_0
  96. [EditorBrowsable (EditorBrowsableState.Never)]
  97. public virtual Type GetProviderSpecificFieldType (int i)
  98. {
  99. return GetFieldType (i);
  100. }
  101. [EditorBrowsable (EditorBrowsableState.Never)]
  102. public virtual object GetProviderSpecificValue (int i)
  103. {
  104. return GetValue (i);
  105. }
  106. [EditorBrowsable (EditorBrowsableState.Never)]
  107. public virtual int GetProviderSpecificValues (object[] values)
  108. {
  109. return GetValues (values);
  110. }
  111. protected virtual DbDataReader GetDbDataReader (int ordinal)
  112. {
  113. return ((DbDataReader) this [ordinal]);
  114. }
  115. #endif
  116. public abstract DataTable GetSchemaTable ();
  117. public abstract string GetString (int i);
  118. public abstract object GetValue (int i);
  119. public abstract int GetValues (object[] values);
  120. IDataReader IDataRecord.GetData (int i)
  121. {
  122. return ((IDataReader) this).GetData (i);
  123. }
  124. public abstract bool IsDBNull (int i);
  125. public abstract bool NextResult ();
  126. public abstract bool Read ();
  127. internal static DataTable GetSchemaTableTemplate ()
  128. {
  129. Type booleanType = Type.GetType ("System.Boolean");
  130. Type stringType = Type.GetType ("System.String");
  131. Type intType = Type.GetType ("System.Int32");
  132. Type typeType = Type.GetType ("System.Type");
  133. Type shortType = Type.GetType ("System.Int16");
  134. DataTable schemaTable = new DataTable ("SchemaTable");
  135. schemaTable.Columns.Add ("ColumnName", stringType);
  136. schemaTable.Columns.Add ("ColumnOrdinal", intType);
  137. schemaTable.Columns.Add ("ColumnSize", intType);
  138. schemaTable.Columns.Add ("NumericPrecision", shortType);
  139. schemaTable.Columns.Add ("NumericScale", shortType);
  140. schemaTable.Columns.Add ("IsUnique", booleanType);
  141. schemaTable.Columns.Add ("IsKey", booleanType);
  142. schemaTable.Columns.Add ("BaseServerName", stringType);
  143. schemaTable.Columns.Add ("BaseCatalogName", stringType);
  144. schemaTable.Columns.Add ("BaseColumnName", stringType);
  145. schemaTable.Columns.Add ("BaseSchemaName", stringType);
  146. schemaTable.Columns.Add ("BaseTableName", stringType);
  147. schemaTable.Columns.Add ("DataType", typeType);
  148. schemaTable.Columns.Add ("AllowDBNull", booleanType);
  149. schemaTable.Columns.Add ("ProviderType", intType);
  150. schemaTable.Columns.Add ("IsAliased", booleanType);
  151. schemaTable.Columns.Add ("IsExpression", booleanType);
  152. schemaTable.Columns.Add ("IsIdentity", booleanType);
  153. schemaTable.Columns.Add ("IsAutoIncrement", booleanType);
  154. schemaTable.Columns.Add ("IsRowVersion", booleanType);
  155. schemaTable.Columns.Add ("IsHidden", booleanType);
  156. schemaTable.Columns.Add ("IsLong", booleanType);
  157. schemaTable.Columns.Add ("IsReadOnly", booleanType);
  158. return schemaTable;
  159. }
  160. #endregion // Methods
  161. }
  162. }
  163. #endif