Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data / Microsoft / SqlServer / Server / SmiTypedGetterSetter.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="SmiTypedGetterSetter.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
8
9
10 namespace Microsoft.SqlServer.Server {
11
12     using System;
13     using System.Data;
14     using System.Data.SqlTypes;
15
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 {
20         #region Read/Write
21         // Are calls to Get methods allowed?
22         internal abstract bool CanGet {
23             get;
24         }
25
26         // Are calls to Set methods allowed?
27         internal abstract bool CanSet {
28             get;
29         }
30         #endregion
31         
32         #region Getters
33         // Null test
34         //      valid for all types
35         public virtual bool IsDBNull(SmiEventSink sink, int ordinal) {
36             if (!CanGet) {
37                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
38             }
39             else {
40                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
41             }
42         }
43
44         // Check what type current sql_variant value is
45         //      valid for SqlDbType.Variant
46         public virtual SmiMetaData GetVariantType(SmiEventSink sink, int ordinal) {
47             if (!CanGet) {
48                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
49             }
50             else {
51                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
52             }
53         }
54
55         //  valid for SqlDbType.Bit
56         public virtual Boolean GetBoolean(SmiEventSink sink, int ordinal) {
57             if (!CanGet) {
58                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
59             }
60             else {
61                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
62             }
63         }
64
65         //  valid for SqlDbType.TinyInt
66         public virtual Byte GetByte(SmiEventSink sink, int ordinal) {
67             if (!CanGet) {
68                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
69             }
70             else {
71                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
72             }
73         }
74
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) {
78             if (!CanGet) {
79                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
80             }
81             else {
82                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
83             }
84         }
85         public virtual int GetBytes(SmiEventSink sink, int ordinal, long fieldOffset, byte[] buffer, int bufferOffset, int length) {
86             if (!CanGet) {
87                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
88             }
89             else {
90                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
91             }
92         }
93
94         // valid for character types: Char, VarChar, Text, NChar, NVarChar, NText
95         public virtual Int64 GetCharsLength(SmiEventSink sink, int ordinal) {
96             if (!CanGet) {
97                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
98             }
99             else {
100                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
101             }
102         }
103         public virtual int GetChars(SmiEventSink sink, int ordinal, long fieldOffset, char[] buffer, int bufferOffset, int length) {
104             if (!CanGet) {
105                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
106             }
107             else {
108                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
109             }
110         }
111         public virtual String GetString(SmiEventSink sink, int ordinal) {
112             if (!CanGet) {
113                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
114             }
115             else {
116                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
117             }
118         }
119
120         // valid for SqlDbType.SmallInt
121         public virtual Int16 GetInt16(SmiEventSink sink, int ordinal) {
122             if (!CanGet) {
123                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
124             }
125             else {
126                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
127             }
128         }
129
130         // valid for SqlDbType.Int
131         public virtual Int32 GetInt32(SmiEventSink sink, int ordinal) {
132             if (!CanGet) {
133                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
134             }
135             else {
136                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
137             }
138         }
139
140         // valid for SqlDbType.BigInt, SqlDbType.Money, SqlDbType.SmallMoney
141         public virtual Int64 GetInt64(SmiEventSink sink, int ordinal) {
142             if (!CanGet) {
143                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
144             }
145             else {
146                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
147             }
148         }
149
150         // valid for SqlDbType.Real
151         public virtual Single GetSingle(SmiEventSink sink, int ordinal) {
152             if (!CanGet) {
153                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
154             }
155             else {
156                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
157             }
158         }
159
160         // valid for SqlDbType.Float
161         public virtual Double GetDouble(SmiEventSink sink, int ordinal) {
162             if (!CanGet) {
163                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
164             }
165             else {
166                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
167             }
168         }
169
170         // valid for SqlDbType.Numeric (uses SqlDecimal since Decimal cannot hold full range)
171         public virtual SqlDecimal GetSqlDecimal(SmiEventSink sink, int ordinal) {
172             if (!CanGet) {
173                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
174             }
175             else {
176                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
177             }
178         }
179
180         // valid for DateTime, SmallDateTime, Date, and DateTime2
181         public virtual DateTime GetDateTime(SmiEventSink sink, int ordinal) {
182             if (!CanGet) {
183                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
184             }
185             else {
186                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
187             }
188         }
189
190         // valid for UniqueIdentifier
191         public virtual Guid GetGuid(SmiEventSink sink, int ordinal) {
192             if (!CanGet) {
193                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
194             }
195             else {
196                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
197             }
198         }
199
200         // valid for SqlDbType.Time
201         public virtual TimeSpan GetTimeSpan(SmiEventSink sink, int ordinal) {
202             if (!CanGet) {
203                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
204             } else {
205                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
206             }
207         }
208
209         // valid for DateTimeOffset
210         public virtual DateTimeOffset GetDateTimeOffset(SmiEventSink sink, int ordinal) {
211             if (!CanGet) {
212                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
213             } else {
214                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
215             }
216         }
217
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);
222         }
223
224         // valid for multi-valued types only
225         internal virtual bool NextElement(SmiEventSink sink) {
226             if (!CanGet) {
227                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
228             }
229             else {
230                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
231             }
232         }
233         #endregion
234
235         #region Setters
236
237         // Set value to null
238         //  valid for all types
239         public virtual void SetDBNull(SmiEventSink sink, int ordinal) {
240             if (!CanSet) {
241                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
242             }
243             else {
244                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
245             }
246         }
247
248         //  valid for SqlDbType.Bit
249         public virtual void SetBoolean(SmiEventSink sink, int ordinal, Boolean value) {
250             if (!CanSet) {
251                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
252             }
253             else {
254                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
255             }
256         }
257
258         //  valid for SqlDbType.TinyInt
259         public virtual void SetByte(SmiEventSink sink, int ordinal, Byte value) {
260             if (!CanSet) {
261                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
262             }
263             else {
264                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
265             }
266         }
267
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) {
273             if (!CanSet) {
274                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
275             }
276             else {
277                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
278             }
279         }
280         public virtual void SetBytesLength(SmiEventSink sink, int ordinal, long length) {
281             if (!CanSet) {
282                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
283             }
284             else {
285                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
286             }
287         }
288
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) {
294             if (!CanSet) {
295                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
296             }
297             else {
298                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
299             }
300         }
301         public virtual void SetCharsLength(SmiEventSink sink, int ordinal, long length) {
302             if (!CanSet) {
303                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
304             }
305             else {
306                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
307             }
308         }
309
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) {
312             if (!CanSet) {
313                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
314             }
315             else {
316                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
317             }
318         }
319
320         // valid for SqlDbType.SmallInt
321         public virtual void SetInt16(SmiEventSink sink, int ordinal, Int16 value) {
322             if (!CanSet) {
323                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
324             }
325             else {
326                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
327             }
328         }
329
330         // valid for SqlDbType.Int
331         public virtual void SetInt32(SmiEventSink sink, int ordinal, Int32 value) {
332             if (!CanSet) {
333                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
334             }
335             else {
336                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
337             }
338         }
339
340         // valid for SqlDbType.BigInt, SqlDbType.Money, SqlDbType.SmallMoney
341         public virtual void SetInt64(SmiEventSink sink, int ordinal, Int64 value) {
342             if (!CanSet) {
343                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
344             }
345             else {
346                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
347             }
348         }
349
350         // valid for SqlDbType.Real
351         public virtual void SetSingle(SmiEventSink sink, int ordinal, Single value) {
352             if (!CanSet) {
353                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
354             }
355             else {
356                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
357             }
358         }
359
360         // valid for SqlDbType.Float
361         public virtual void SetDouble(SmiEventSink sink, int ordinal,  Double value) {
362             if (!CanSet) {
363                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
364             }
365             else {
366                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
367             }
368         }
369
370         // valid for SqlDbType.Numeric (uses SqlDecimal since Decimal cannot hold full range)
371         public virtual void SetSqlDecimal(SmiEventSink sink, int ordinal, SqlDecimal value) {
372             if (!CanSet) {
373                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
374             }
375             else {
376                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
377             }
378         }
379
380         // valid for DateTime, SmallDateTime, Date, and DateTime2
381         public virtual void SetDateTime(SmiEventSink sink, int ordinal, DateTime value) {
382             if (!CanSet) {
383                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
384             }
385             else {
386                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
387             }
388         }
389
390         // valid for UniqueIdentifier
391         public virtual void SetGuid(SmiEventSink sink, int ordinal, Guid value) {
392             if (!CanSet) {
393                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
394             }
395             else {
396                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
397             }
398         }
399
400         // valid for SqlDbType.Time
401         public virtual void SetTimeSpan(SmiEventSink sink, int ordinal, TimeSpan value) {
402             if (!CanSet) {
403                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
404             } else {
405                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
406             }
407         }
408
409         // valid for DateTimeOffset
410         public virtual void SetDateTimeOffset(SmiEventSink sink, int ordinal, DateTimeOffset value) {
411             if (!CanSet) {
412                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
413             } else {
414                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
415             }
416         }
417
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
421
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 );
426         }
427
428         // valid for multi-valued types only
429         internal virtual void NewElement(SmiEventSink sink) {
430             if (!CanSet) {
431                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
432             }
433             else {
434                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
435             }
436         }
437
438         internal virtual void EndElements(SmiEventSink sink) {
439             if (!CanSet) {
440                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
441             }
442             else {
443                 throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
444             }
445         }
446         #endregion
447
448     }
449 }