1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
//------------------------------------------------------------------------------
// <copyright file="DbDataReader.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
//------------------------------------------------------------------------------
namespace System.Data.Common {
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Threading.Tasks;
using System.Threading;
public abstract class DbDataReader : MarshalByRefObject, IDataReader, IEnumerable { // V1.2.3300
protected DbDataReader() : base() {
}
abstract public int Depth {
get;
}
abstract public int FieldCount {
get;
}
abstract public bool HasRows {
get;
}
abstract public bool IsClosed {
get;
}
abstract public int RecordsAffected {
get;
}
virtual public int VisibleFieldCount {
// NOTE: This is virtual because not all providers may choose to support
// this property, since it was added in Whidbey
get {
return FieldCount;
}
}
abstract public object this [ int ordinal ] {
get;
}
abstract public object this [ string name ] {
get;
}
virtual public void Close()
{
}
[
EditorBrowsableAttribute(EditorBrowsableState.Never)
]
public void Dispose() {
Dispose(true);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
Close();
}
}
abstract public string GetDataTypeName(int ordinal);
[
EditorBrowsableAttribute(EditorBrowsableState.Never)
]
abstract public IEnumerator GetEnumerator();
abstract public Type GetFieldType(int ordinal);
abstract public string GetName(int ordinal);
abstract public int GetOrdinal(string name);
virtual public DataTable GetSchemaTable()
{
throw new NotSupportedException();
}
abstract public bool GetBoolean(int ordinal);
abstract public byte GetByte(int ordinal);
abstract public long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length);
abstract public char GetChar(int ordinal);
abstract public long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length);
[
EditorBrowsableAttribute(EditorBrowsableState.Never)
]
public DbDataReader GetData(int ordinal) {
return GetDbDataReader(ordinal);
}
IDataReader IDataRecord.GetData(int ordinal) {
return GetDbDataReader(ordinal);
}
virtual protected DbDataReader GetDbDataReader(int ordinal) {
// NOTE: This method is virtual because we're required to implement
// it however most providers won't support it. Only the OLE DB
// provider supports it right now, and they can override it.
throw ADP.NotSupported();
}
abstract public DateTime GetDateTime(int ordinal);
abstract public Decimal GetDecimal(int ordinal);
abstract public double GetDouble(int ordinal);
abstract public float GetFloat(int ordinal);
abstract public Guid GetGuid(int ordinal);
abstract public Int16 GetInt16(int ordinal);
abstract public Int32 GetInt32(int ordinal);
abstract public Int64 GetInt64(int ordinal);
[
EditorBrowsableAttribute(EditorBrowsableState.Never)
]
virtual public Type GetProviderSpecificFieldType(int ordinal) {
// NOTE: This is virtual because not all providers may choose to support
// this method, since it was added in Whidbey.
return GetFieldType(ordinal);
}
[
EditorBrowsableAttribute(EditorBrowsableState.Never)
]
virtual public Object GetProviderSpecificValue(int ordinal) {
// NOTE: This is virtual because not all providers may choose to support
// this method, since it was added in Whidbey
return GetValue(ordinal);
}
[
EditorBrowsableAttribute(EditorBrowsableState.Never)
]
virtual public int GetProviderSpecificValues(object[] values) {
// NOTE: This is virtual because not all providers may choose to support
// this method, since it was added in Whidbey
return GetValues(values);
}
abstract public String GetString(int ordinal);
virtual public Stream GetStream(int ordinal) {
using (MemoryStream bufferStream = new MemoryStream())
{
long bytesRead = 0;
long bytesReadTotal = 0;
byte[] buffer = new byte[4096];
do {
bytesRead = GetBytes(ordinal, bytesReadTotal, buffer, 0, buffer.Length);
bufferStream.Write(buffer, 0, (int)bytesRead);
bytesReadTotal += bytesRead;
} while (bytesRead > 0);
return new MemoryStream(bufferStream.ToArray(), false);
}
}
virtual public TextReader GetTextReader(int ordinal) {
if (IsDBNull(ordinal)) {
return new StringReader(String.Empty);
}
else {
return new StringReader(GetString(ordinal));
}
}
abstract public Object GetValue(int ordinal);
virtual public T GetFieldValue<T>(int ordinal) {
return (T)GetValue(ordinal);
}
public Task<T> GetFieldValueAsync<T>(int ordinal) {
return GetFieldValueAsync<T>(ordinal, CancellationToken.None);
}
virtual public Task<T> GetFieldValueAsync<T>(int ordinal, CancellationToken cancellationToken) {
if (cancellationToken.IsCancellationRequested) {
return ADP.CreatedTaskWithCancellation<T>();
}
else {
try {
return Task.FromResult<T>(GetFieldValue<T>(ordinal));
}
catch (Exception e) {
return ADP.CreatedTaskWithException<T>(e);
}
}
}
abstract public int GetValues(object[] values);
abstract public bool IsDBNull(int ordinal);
public Task<bool> IsDBNullAsync(int ordinal) {
return IsDBNullAsync(ordinal, CancellationToken.None);
}
virtual public Task<bool> IsDBNullAsync(int ordinal, CancellationToken cancellationToken) {
if (cancellationToken.IsCancellationRequested) {
return ADP.CreatedTaskWithCancellation<bool>();
}
else {
try {
return IsDBNull(ordinal) ? ADP.TrueTask : ADP.FalseTask;
}
catch (Exception e) {
return ADP.CreatedTaskWithException<bool>(e);
}
}
}
abstract public bool NextResult();
abstract public bool Read();
public Task<bool> ReadAsync() {
return ReadAsync(CancellationToken.None);
}
virtual public Task<bool> ReadAsync(CancellationToken cancellationToken) {
if (cancellationToken.IsCancellationRequested) {
return ADP.CreatedTaskWithCancellation<bool>();
}
else {
try {
return Read() ? ADP.TrueTask : ADP.FalseTask;
}
catch (Exception e) {
return ADP.CreatedTaskWithException<bool>(e);
}
}
}
public Task<bool> NextResultAsync() {
return NextResultAsync(CancellationToken.None);
}
virtual public Task<bool> NextResultAsync(CancellationToken cancellationToken) {
if (cancellationToken.IsCancellationRequested) {
return ADP.CreatedTaskWithCancellation<bool>();
}
else {
try {
return NextResult() ? ADP.TrueTask : ADP.FalseTask;
}
catch (Exception e) {
return ADP.CreatedTaskWithException<bool>(e);
}
}
}
}
}
|