1 //------------------------------------------------------------------------------
2 // <copyright file="SmiTypedGetterSetter.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
10 namespace Microsoft.SqlServer.Server {
14 using System.Data.SqlTypes;
16 // Central interface for getting/setting data values from/to a set of values indexed by ordinal
17 // (record, row, array, etc)
18 // Which methods are allowed to be called depends on SmiMetaData type of data offset.
19 internal abstract class SmiTypedGetterSetter : ITypedGettersV3, ITypedSettersV3 {
21 // Are calls to Get methods allowed?
22 internal abstract bool CanGet {
26 // Are calls to Set methods allowed?
27 internal abstract bool CanSet {
34 // valid for all types
35 public virtual bool IsDBNull(SmiEventSink sink, int ordinal) {
37 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
40 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
44 // Check what type current sql_variant value is
45 // valid for SqlDbType.Variant
46 public virtual SmiMetaData GetVariantType(SmiEventSink sink, int ordinal) {
48 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
51 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
55 // valid for SqlDbType.Bit
56 public virtual Boolean GetBoolean(SmiEventSink sink, int ordinal) {
58 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
61 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
65 // valid for SqlDbType.TinyInt
66 public virtual Byte GetByte(SmiEventSink sink, int ordinal) {
68 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
71 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
75 // valid for SqlDbTypes: Binary, VarBinary, Image, Udt, Xml, Char, VarChar, Text, NChar, NVarChar, NText
76 // (Character type support needed for ExecuteXmlReader handling)
77 public virtual Int64 GetBytesLength(SmiEventSink sink, int ordinal) {
79 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
82 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
85 public virtual int GetBytes(SmiEventSink sink, int ordinal, long fieldOffset, byte[] buffer, int bufferOffset, int length) {
87 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
90 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
94 // valid for character types: Char, VarChar, Text, NChar, NVarChar, NText
95 public virtual Int64 GetCharsLength(SmiEventSink sink, int ordinal) {
97 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
100 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
103 public virtual int GetChars(SmiEventSink sink, int ordinal, long fieldOffset, char[] buffer, int bufferOffset, int length) {
105 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
108 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
111 public virtual String GetString(SmiEventSink sink, int ordinal) {
113 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
116 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
120 // valid for SqlDbType.SmallInt
121 public virtual Int16 GetInt16(SmiEventSink sink, int ordinal) {
123 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
126 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
130 // valid for SqlDbType.Int
131 public virtual Int32 GetInt32(SmiEventSink sink, int ordinal) {
133 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
136 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
140 // valid for SqlDbType.BigInt, SqlDbType.Money, SqlDbType.SmallMoney
141 public virtual Int64 GetInt64(SmiEventSink sink, int ordinal) {
143 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
146 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
150 // valid for SqlDbType.Real
151 public virtual Single GetSingle(SmiEventSink sink, int ordinal) {
153 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
156 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
160 // valid for SqlDbType.Float
161 public virtual Double GetDouble(SmiEventSink sink, int ordinal) {
163 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
166 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
170 // valid for SqlDbType.Numeric (uses SqlDecimal since Decimal cannot hold full range)
171 public virtual SqlDecimal GetSqlDecimal(SmiEventSink sink, int ordinal) {
173 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
176 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
180 // valid for DateTime, SmallDateTime, Date, and DateTime2
181 public virtual DateTime GetDateTime(SmiEventSink sink, int ordinal) {
183 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
186 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
190 // valid for UniqueIdentifier
191 public virtual Guid GetGuid(SmiEventSink sink, int ordinal) {
193 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
196 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
200 // valid for SqlDbType.Time
201 public virtual TimeSpan GetTimeSpan(SmiEventSink sink, int ordinal) {
203 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
205 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
209 // valid for DateTimeOffset
210 public virtual DateTimeOffset GetDateTimeOffset(SmiEventSink sink, int ordinal) {
212 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
214 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
218 // valid for structured types
219 // This method called for both get and set.
220 internal virtual SmiTypedGetterSetter GetTypedGetterSetter(SmiEventSink sink, int ordinal) {
221 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
224 // valid for multi-valued types only
225 internal virtual bool NextElement(SmiEventSink sink) {
227 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
230 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
238 // valid for all types
239 public virtual void SetDBNull(SmiEventSink sink, int ordinal) {
241 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
244 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
248 // valid for SqlDbType.Bit
249 public virtual void SetBoolean(SmiEventSink sink, int ordinal, Boolean value) {
251 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
254 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
258 // valid for SqlDbType.TinyInt
259 public virtual void SetByte(SmiEventSink sink, int ordinal, Byte value) {
261 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
264 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
268 // Semantics for SetBytes are to modify existing value, not overwrite
269 // Use in combination with SetLength to ensure overwriting when necessary
270 // valid for SqlDbTypes: Binary, VarBinary, Image, Udt, Xml
271 // (VarBinary assumed for variants)
272 public virtual int SetBytes(SmiEventSink sink, int ordinal, long fieldOffset, byte[] buffer, int bufferOffset, int length) {
274 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
277 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
280 public virtual void SetBytesLength(SmiEventSink sink, int ordinal, long length) {
282 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
285 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
289 // Semantics for SetChars are to modify existing value, not overwrite
290 // Use in combination with SetLength to ensure overwriting when necessary
291 // valid for character types: Char, VarChar, Text, NChar, NVarChar, NText
292 // (NVarChar and global clr collation assumed for variants)
293 public virtual int SetChars(SmiEventSink sink, int ordinal, long fieldOffset, char[] buffer, int bufferOffset, int length) {
295 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
298 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
301 public virtual void SetCharsLength(SmiEventSink sink, int ordinal, long length) {
303 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
306 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
310 // valid for character types: Char, VarChar, Text, NChar, NVarChar, NText
311 public virtual void SetString(SmiEventSink sink, int ordinal, string value, int offset, int length) {
313 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
316 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
320 // valid for SqlDbType.SmallInt
321 public virtual void SetInt16(SmiEventSink sink, int ordinal, Int16 value) {
323 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
326 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
330 // valid for SqlDbType.Int
331 public virtual void SetInt32(SmiEventSink sink, int ordinal, Int32 value) {
333 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
336 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
340 // valid for SqlDbType.BigInt, SqlDbType.Money, SqlDbType.SmallMoney
341 public virtual void SetInt64(SmiEventSink sink, int ordinal, Int64 value) {
343 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
346 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
350 // valid for SqlDbType.Real
351 public virtual void SetSingle(SmiEventSink sink, int ordinal, Single value) {
353 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
356 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
360 // valid for SqlDbType.Float
361 public virtual void SetDouble(SmiEventSink sink, int ordinal, Double value) {
363 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
366 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
370 // valid for SqlDbType.Numeric (uses SqlDecimal since Decimal cannot hold full range)
371 public virtual void SetSqlDecimal(SmiEventSink sink, int ordinal, SqlDecimal value) {
373 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
376 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
380 // valid for DateTime, SmallDateTime, Date, and DateTime2
381 public virtual void SetDateTime(SmiEventSink sink, int ordinal, DateTime value) {
383 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
386 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
390 // valid for UniqueIdentifier
391 public virtual void SetGuid(SmiEventSink sink, int ordinal, Guid value) {
393 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
396 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
400 // valid for SqlDbType.Time
401 public virtual void SetTimeSpan(SmiEventSink sink, int ordinal, TimeSpan value) {
403 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
405 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
409 // valid for DateTimeOffset
410 public virtual void SetDateTimeOffset(SmiEventSink sink, int ordinal, DateTimeOffset value) {
412 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
414 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
418 public virtual void SetVariantMetaData( SmiEventSink sink, int ordinal, SmiMetaData metaData ) {
419 // ******** OBSOLETING from SMI -- this should have been removed from ITypedSettersV3
420 // Intended to be removed prior to RTM. Sub-classes need not implement
422 // Implement body with throw because there are only a couple of ways to get to this code:
423 // 1) Client is calling this method even though the server negotiated for V3+ and dropped support for V2-.
424 // 2) Server didn't implement V2- on some interface and negotiated V2-.
425 throw System.Data.Common.ADP.InternalError( System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod );
428 // valid for multi-valued types only
429 internal virtual void NewElement(SmiEventSink sink) {
431 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
434 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
438 internal virtual void EndElements(SmiEventSink sink) {
440 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
443 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);