Example #1
0
        private static long GetBytesConversion(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, long fieldOffset, byte[] buffer, int bufferOffset, int length, bool throwOnNull) {
            object obj = GetSqlValue( sink, getters, ordinal, metaData, null  );
            if (null == obj) {
                throw ADP.InvalidCast();
            }
            SqlBinary value = (SqlBinary) obj;

            if (value.IsNull) {
                if (throwOnNull) {
                    throw SQL.SqlNullValue();
                }
                else {
                    // return zero length in any case
                    return 0;
                }
            }

            if ( null == buffer ) {
                return value.Length;
            }

            length = CheckXetParameters( metaData.SqlDbType, metaData.MaxLength * sizeof(char), value.Length, 
                        fieldOffset, buffer.Length, bufferOffset, length );
            Array.Copy( value.Value, checked((int)fieldOffset), buffer, bufferOffset, length );
            return length;
        }
 internal SmiGettersStream(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData)
 {
     this._sink = sink;
     this._getters = getters;
     this._ordinal = ordinal;
     this._readPosition = 0L;
     this._metaData = metaData;
 }
        private long _length;           // Total length of the stream

        internal SqlSequentialStreamSmi(SmiEventSink_Default sink, ITypedGettersV3 getters, int columnIndex, long length)
        {
            _sink = sink;
            _getters = getters;
            _columnIndex = columnIndex;
            _length = length;
            _position = 0;
        }
        private int _peekedChar;        // Current peeked character (if any)

        internal SqlSequentialTextReaderSmi(SmiEventSink_Default sink, ITypedGettersV3 getters, int columnIndex, long length)
        {
            _sink = sink;
            _getters = getters;
            _columnIndex = columnIndex;
            _length = length;
            _position = 0;
            _peekedChar = -1;
        }
Example #5
0
        // Called zero or one time when output parameters are available (errors could prevent event from occuring)
        internal virtual void ParametersAvailable(SmiParameterMetaData[] metaData, ITypedGettersV3 paramValues)
        {
            // Adding as of V3
            // Obsoleting as of V200

            // Implement body with throw because there are only a couple of ways to get to this code:
            //  1) Client is calling this method even though the server negotiated for V200+ and dropped support for V200-.
            //  2) Server didn't implement V3- on some interface and negotiated V3-.
            Microsoft.Data.Common.ADP.InternalError(Microsoft.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod);
        }
Example #6
0
 internal static byte GetByte( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData ) {
     ThrowIfITypedGettersIsNull( sink, getters, ordinal );
     if ( CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.Byte ) ) {
         return GetByte_Unchecked( sink, getters, ordinal );
     }
     object result = GetValue( sink, getters, ordinal, metaData, null );
     if (null == result) {
         throw ADP.InvalidCast();
     }
     return (Byte)result;
 }
        internal SmiGettersStream( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData ) {
            Debug.Assert( null != sink );
            Debug.Assert( null != getters );
            Debug.Assert( 0 <= ordinal );
            Debug.Assert( null != metaData );

            _sink = sink;
            _getters = getters;
            _ordinal = ordinal;
            _readPosition = 0;
            _metaData = metaData;
        }
Example #8
0
        internal SmiGettersStream(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData)
        {
            Debug.Assert(null != sink);
            Debug.Assert(null != getters);
            Debug.Assert(0 <= ordinal);
            Debug.Assert(null != metaData);

            _sink         = sink;
            _getters      = getters;
            _ordinal      = ordinal;
            _readPosition = 0;
            _metaData     = metaData;
        }
        // calling GetTimeSpan on possibly v100 SMI
        internal static TimeSpan GetTimeSpan(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, bool gettersSupportKatmaiDateTime)
        {
            if (gettersSupportKatmaiDateTime)
            {
                return(GetTimeSpan(sink, (SmiTypedGetterSetter)getters, ordinal, metaData));
            }
            ThrowIfITypedGettersIsNull(sink, getters, ordinal);
            object obj = GetValue(sink, getters, ordinal, metaData, null);

            if (null == obj)
            {
                throw ADP.InvalidCast();
            }
            return((TimeSpan)obj);
        }
Example #10
0
 internal static SqlByte GetSqlByte( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData ) {
     if ( CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.SqlByte ) ) {
         if ( IsDBNull_Unchecked( sink, getters, ordinal ) ) {
             return SqlByte.Null;
         }
         return new SqlByte( GetByte_Unchecked( sink, getters, ordinal ) );
     }
     object result = GetSqlValue( sink, getters, ordinal, metaData, null  );
     if (null == result) {
         throw ADP.InvalidCast();
     }
     return (SqlByte) result;
 }
Example #11
0
        private static String GetString_Unchecked( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal ) {
            Debug.Assert( !IsDBNull_Unchecked( sink, getters, ordinal ) );

            // Note: depending on different getters, the result string maybed truncated, e.g. for 
            // Inproc process, the getter is InProcRecordBuffer (implemented in SqlAcess), string will be
            // truncated to 4000 (if length is more than 4000). If MemoryRecordBuffer getter is used, data 
            // is not truncated. Please refer VSDD 479655 for more detailed information regarding the string length.
            String result = getters.GetString( sink, ordinal );
            sink.ProcessMessagesAndThrow();
            return result;
        }
Example #12
0
        private static SqlXml GetSqlXml_Unchecked( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiContext context ) {
            Debug.Assert( !IsDBNull_Unchecked( sink, getters, ordinal ) );

            // allow context to be null so strongly-typed getters can use
            //  this method without having to pass along the almost-never-used context as a parameter
            //  Looking the context up like this will be slightly slower, but still correct behavior
            //  since it's only used to get a scratch stream.
            if (null == context && InOutOfProcHelper.InProc) {
                context = SmiContextFactory.Instance.GetCurrentContext();    // In the future we need to push the context checking to a higher level
            }

            // Note: must make a copy of getter stream, since it will be used beyond
            //  this method (valid lifetime of getters is limited).
            Stream s = new SmiGettersStream( sink, getters, ordinal, SmiMetaData.DefaultXml );
            Stream copy = ValueUtilsSmi.CopyIntoNewSmiScratchStream( s, sink, context );
            SqlXml result = new SqlXml( copy );
            return result;
        }
Example #13
0
 /// <summary>
 /// Forces the stream to act as if it was closed (i.e. CanRead=false and Read() throws)
 /// This does not actually close the stream, read off the rest of the data or dispose this
 /// </summary>
 internal void SetClosed()
 {
     _sink    = null;
     _getters = null;
 }
 internal override void ParametersAvailable(SmiParameterMetaData[] metaData, ITypedGettersV3 paramValues) {
     if (null == _parent) {
         throw SQL.UnexpectedSmiEvent(UnexpectedEventType.ParametersAvailable);
     }
     _parent.ParametersAvailable(metaData, paramValues);
 }
 private void RowAvailable(ITypedGettersV3 row)
 {
     this._currentColumnValuesV3 = row;
     this._currentPosition       = PositionState.OnRow;
 }
Example #16
0
        internal static TextReader GetTextReader( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData ) {
            bool isDbNull = ValueUtilsSmi.IsDBNull_Unchecked(sink, getters, ordinal);

            // If a sql_variant, get the internal type
            if ((!isDbNull) && (metaData.SqlDbType == SqlDbType.Variant)) {
                metaData = getters.GetVariantType(sink, ordinal);
            }
            // If the SqlDbType is still variant, then it must contain null, so don't throw InvalidCast
            if ((metaData.SqlDbType != SqlDbType.Variant) && (!CanAccessGetterDirectly(metaData, ExtendedClrTypeCode.TextReader))) {
                throw ADP.InvalidCast();
            }

            string data;
            if (isDbNull) {
                // "null" textreader
                data = string.Empty;
            }
            else {
                // Read all data
                data = GetString_Unchecked(sink, getters, ordinal);
            }

            // Wrap in pre-built object
            return new StringReader(data);
        }
Example #17
0
 internal virtual void ParametersAvailable(SmiParameterMetaData[] metaData, ITypedGettersV3 paramValues)
 {
     ADP.InternalError(ADP.InternalErrorCode.UnimplementedSMIMethod);
 }
Example #18
0
 internal static String GetString( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData ) {
     ThrowIfITypedGettersIsNull( sink, getters, ordinal );
     if ( CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.String ) ) {
         return GetString_Unchecked( sink, getters, ordinal );
     }
     object obj = GetValue( sink, getters, ordinal, metaData, null  );
     if (null == obj) {
         throw ADP.InvalidCast();
     }
     return (String) obj;
 }
Example #19
0
        internal static SqlString GetSqlString( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData ) {
            SqlString result;
            if ( CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.SqlString ) ) {
                if ( IsDBNull_Unchecked( sink, getters, ordinal ) ) {
                    result = SqlString.Null;
                }
                else {
                    String temp = GetString_Unchecked( sink, getters, ordinal );
                    result = new SqlString( temp );
                }
            }
            else if (SqlDbType.Xml == metaData.SqlDbType) {
                SqlXml xmlValue = GetSqlXml_Unchecked( sink, getters, ordinal, null );
                
                if (xmlValue.IsNull) {
                    result = SqlString.Null;
                }
                else {
                    result = new SqlString( xmlValue.Value );
                }
            }
            else {
                object obj = GetSqlValue( sink, getters, ordinal, metaData, null  );
                if (null == obj) {
                    throw ADP.InvalidCast();
                }
                result = (SqlString) obj;
            }

            return result;
        }
Example #20
0
        const int constTextBufferSize = 4096; // Size of the buffer (in chars) user to read input parameter of type TextReader       

    //
    //  User-visible semantics-laden Getter/Setter support methods
    //      These methods implement common semantics for getters & setters
    //      All access to underlying Smi getters/setters must validate parameters
    //      in these methods
    //  

        //  The idea for the getters is that there are two types associated with the field/column,
        //  the one the user asks for (implicitly via a strongly-typed getter) and the one the data 
        //  is stored in (SmiMetaData).
        //  When a strong getter is invoked, we try one of two ways to get the value
        //      1) go directly to the source for the requested type if possible
        //      2) instantiate the value based on the stored type (GetValue), then ask the Clr 
        //          to convert.
        internal static bool IsDBNull( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal ) {
            return IsDBNull_Unchecked( sink, getters, ordinal );
        }
Example #21
0
        internal static SqlBytes GetSqlBytes( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, SmiContext context ) {
            SqlBytes result;
            if ( CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.SqlBytes ) ) {
                if ( IsDBNull_Unchecked( sink, getters, ordinal ) ) {
                    result = SqlBytes.Null;
                }
                else {
                    long length = GetBytesLength_Unchecked( sink, getters, ordinal );
                    if ( 0 <= length && length < __maxByteChunkSize ) {
                        byte[] byteBuffer = GetByteArray_Unchecked( sink, getters, ordinal );
                        result = new SqlBytes( byteBuffer );
                    }
                    else {
                        Stream s = new SmiGettersStream( sink, getters, ordinal, metaData );
                        s = CopyIntoNewSmiScratchStream( s, sink, context );
                        result = new SqlBytes( s );
                    }
                }
            }
            else {
                object obj = GetSqlValue( sink, getters, ordinal, metaData, null  );
                if (null == obj) {
                    throw ADP.InvalidCast();
                }
                SqlBinary binaryVal = (SqlBinary) obj;
                if ( binaryVal.IsNull ) {
                    result = SqlBytes.Null;
                }
                else {
                    result = new SqlBytes( binaryVal.Value );
                }
            }

            return result;
        }
Example #22
0
 internal virtual void RowAvailable(ITypedGettersV3 rowData)
 {
     ADP.InternalError(ADP.InternalErrorCode.UnimplementedSMIMethod);
 }
        // UDTs and null variants come back via return value, all else is via targetBuffer.
        //  implements SqlClient 2.0-compatible output parameter semantics
        internal static object GetOutputParameterV3Smi(
            SmiEventSink_Default sink,  // event sink for errors
            ITypedGettersV3 getters,    // getters interface to grab value from
            int ordinal,                // parameter within getters
            SmiMetaData metaData,       // Getter's type for this ordinal
            SmiContext context,         // used to obtain scratch streams
            SqlBuffer targetBuffer      // destination
            )
        {
            object result = null;   // Workaround for UDT hack in non-Smi code paths.

            if (IsDBNull_Unchecked(sink, getters, ordinal))
            {
                GetNullOutputParameterSmi(metaData, targetBuffer, ref result);
            }
            else
            {
                switch (metaData.SqlDbType)
                {
                case SqlDbType.BigInt:
                    targetBuffer.Int64 = GetInt64_Unchecked(sink, getters, ordinal);
                    break;

                case SqlDbType.Binary:
                case SqlDbType.Image:
                case SqlDbType.Timestamp:
                case SqlDbType.VarBinary:
                    targetBuffer.SqlBinary = GetSqlBinary_Unchecked(sink, getters, ordinal);
                    break;

                case SqlDbType.Bit:
                    targetBuffer.Boolean = GetBoolean_Unchecked(sink, getters, ordinal);
                    break;

                case SqlDbType.NChar:
                case SqlDbType.NText:
                case SqlDbType.NVarChar:
                case SqlDbType.Char:
                case SqlDbType.VarChar:
                case SqlDbType.Text:
                    targetBuffer.SetToString(GetString_Unchecked(sink, getters, ordinal));
                    break;

                case SqlDbType.DateTime:
                case SqlDbType.SmallDateTime:
                {
                    SqlDateTime dt = new(GetDateTime_Unchecked(sink, getters, ordinal));
                    targetBuffer.SetToDateTime(dt.DayTicks, dt.TimeTicks);
                    break;
                }

                case SqlDbType.Decimal:
                {
                    SqlDecimal dec = GetSqlDecimal_Unchecked(sink, getters, ordinal);
                    targetBuffer.SetToDecimal(dec.Precision, dec.Scale, dec.IsPositive, dec.Data);
                    break;
                }

                case SqlDbType.Float:
                    targetBuffer.Double = GetDouble_Unchecked(sink, getters, ordinal);
                    break;

                case SqlDbType.Int:
                    targetBuffer.Int32 = GetInt32_Unchecked(sink, getters, ordinal);
                    break;

                case SqlDbType.Money:
                case SqlDbType.SmallMoney:
                    targetBuffer.SetToMoney(GetInt64_Unchecked(sink, getters, ordinal));
                    break;

                case SqlDbType.Real:
                    targetBuffer.Single = GetSingle_Unchecked(sink, getters, ordinal);
                    break;

                case SqlDbType.UniqueIdentifier:
                    targetBuffer.SqlGuid = new SqlGuid(GetGuid_Unchecked(sink, getters, ordinal));
                    break;

                case SqlDbType.SmallInt:
                    targetBuffer.Int16 = GetInt16_Unchecked(sink, getters, ordinal);
                    break;

                case SqlDbType.TinyInt:
                    targetBuffer.Byte = GetByte_Unchecked(sink, getters, ordinal);
                    break;

                case SqlDbType.Variant:
                    // For variants, recur using the current value's sqldbtype
                    metaData = getters.GetVariantType(sink, ordinal);
                    sink.ProcessMessagesAndThrow();
                    Debug.Assert(SqlDbType.Variant != metaData.SqlDbType, "Variant-within-variant not supposed to be possible!");
                    GetOutputParameterV3Smi(sink, getters, ordinal, metaData, context, targetBuffer);
                    break;

                case SqlDbType.Udt:
                    result = GetUdt_LengthChecked(sink, getters, ordinal, metaData);
                    break;

                case SqlDbType.Xml:
                    targetBuffer.SqlXml = GetSqlXml_Unchecked(sink, getters, ordinal, null);
                    break;

                default:
                    Debug.Assert(false, "Unexpected SqlDbType");
                    break;
                }
            }

            return(result);
        }
        internal static SqlSequentialTextReaderSmi GetSequentialTextReader(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData)
        {
            Debug.Assert(!ValueUtilsSmi.IsDBNull_Unchecked(sink, getters, ordinal), "Should not try to get a SqlSequentialTextReaderSmi on a null column");
            ThrowIfITypedGettersIsNull(sink, getters, ordinal);
            if (!CanAccessGetterDirectly(metaData, ExtendedClrTypeCode.TextReader))
            {
                throw ADP.InvalidCast();
            }

            // This will advance the column to ordinal
            long length = GetCharsLength_Unchecked(sink, getters, ordinal);

            return(new SqlSequentialTextReaderSmi(sink, getters, ordinal, length));
        }
Example #25
0
        internal static SqlChars GetSqlChars( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, SmiContext context ) {
            SqlChars result;
            if ( CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.SqlChars ) ) {
                if ( IsDBNull_Unchecked( sink, getters, ordinal ) ) {
                    result = SqlChars.Null;
                }
                else {
                    long length = GetCharsLength_Unchecked( sink, getters, ordinal );
                    if ( length < __maxCharChunkSize || !InOutOfProcHelper.InProc) {
                        char[] charBuffer = GetCharArray_Unchecked( sink, getters, ordinal );
                        result = new SqlChars( charBuffer );
                    }
                    else {    // InProc only
                        Stream s = new SmiGettersStream( sink, getters, ordinal, metaData );
                        SqlStreamChars sc = CopyIntoNewSmiScratchStreamChars( s, sink, context );
                        result = new SqlChars( sc );
                    }
                }
            }
            else {
                SqlString stringValue;
                if (SqlDbType.Xml == metaData.SqlDbType) {
                    SqlXml xmlValue = GetSqlXml_Unchecked( sink, getters, ordinal, null );

                    if (xmlValue.IsNull) {
                        result = SqlChars.Null;
                    }
                    else {
                        result = new SqlChars( xmlValue.Value.ToCharArray() );
                    }
                }
                else {
                    object obj = GetSqlValue( sink, getters, ordinal, metaData, null  );
                    if (null == obj) {
                        throw ADP.InvalidCast();
                    }
                    stringValue = (SqlString) obj;

                    if ( stringValue.IsNull ) {
                        result = SqlChars.Null;
                    }
                    else {
                        result = new SqlChars( stringValue.Value.ToCharArray() );
                    }
                }
            }

            return result;
        }
Example #26
0
 /// <summary>
 /// Forces the TextReader to act as if it was closed
 /// This does not actually close the stream, read off the rest of the data or dispose this
 /// </summary>
 internal void SetClosed()
 {
     _sink       = null;
     _getters    = null;
     _peekedChar = -1;
 }
Example #27
0
        internal static SqlSingle GetSqlSingle( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData ) {
            SqlSingle result;
            if ( CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.SqlSingle ) ) {
                if ( IsDBNull_Unchecked( sink, getters, ordinal ) ) {
                    result = SqlSingle.Null;
                }
                else {
                    Single temp = GetSingle_Unchecked( sink, getters, ordinal );
                    result = new SqlSingle( temp );
                }
            }
            else {
                object obj = GetSqlValue( sink, getters, ordinal, metaData, null  );
                if (null == obj) {
                    throw ADP.InvalidCast();
                }
                result = (SqlSingle) obj;
            }

            return result;
        }
Example #28
0
        private static char[] GetCharArray_Unchecked( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal ) {
            Debug.Assert( !IsDBNull_Unchecked( sink, getters, ordinal ) );

            long length = getters.GetCharsLength( sink, ordinal );
            sink.ProcessMessagesAndThrow();
            int len = checked( (int)length );

            char[] buffer = new char[len];
            getters.GetChars( sink, ordinal, 0, buffer, 0, len );
            sink.ProcessMessagesAndThrow();
            return buffer;
        }
Example #29
0
        internal static SqlXml GetSqlXml( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, SmiContext context ) {
            SqlXml result;
            if ( CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.SqlXml ) ) {
                if ( IsDBNull_Unchecked( sink, getters, ordinal ) ) {
                    result = SqlXml.Null;
                }
                else {
                    result = GetSqlXml_Unchecked( sink, getters, ordinal, context );
                }
            }
            else {
                object obj = GetSqlValue( sink, getters, ordinal, metaData, null  );
                if (null == obj) {
                    throw ADP.InvalidCast();
                }
                result = (SqlXml) obj;
            }

            return result;
        }
Example #30
0
        internal static int GetChars_Unchecked( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, long fieldOffset, char[] buffer, int bufferOffset, int length ) {
            Debug.Assert( !IsDBNull_Unchecked( sink, getters, ordinal ) );
            Debug.Assert(ordinal >= 0, string.Format("Invalid ordinal: {0}", ordinal));
            Debug.Assert(sink != null, "Null SmiEventSink");
            Debug.Assert(getters != null, "Null getters");
            Debug.Assert(fieldOffset >= 0, string.Format("Invalid field offset: {0}", fieldOffset));
            Debug.Assert(buffer != null, "Null buffer");
            Debug.Assert(bufferOffset >= 0 && length >= 0 && bufferOffset + length <= buffer.Length, string.Format("Bad offset or length. bufferOffset: {0}, length: {1}, buffer.Length{2}", bufferOffset, length, buffer.Length));

            int result = getters.GetChars( sink, ordinal, fieldOffset, buffer, bufferOffset, length );
            sink.ProcessMessagesAndThrow();
            return result;
        }
Example #31
0
        internal static SqlSequentialTextReaderSmi GetSequentialTextReader( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData ) {
            Debug.Assert(!ValueUtilsSmi.IsDBNull_Unchecked(sink, getters, ordinal), "Should not try to get a SqlSequentialTextReaderSmi on a null column");
            ThrowIfITypedGettersIsNull( sink, getters, ordinal );
            if ( !CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.TextReader ) ) {
                throw ADP.InvalidCast();
            }

            // This will advance the column to ordinal
            long length = GetCharsLength_Unchecked(sink, getters, ordinal);
            return new SqlSequentialTextReaderSmi(sink, getters, ordinal, length);
        }
Example #32
0
        private static long GetCharsLength_Unchecked( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal ) {
            Debug.Assert( !IsDBNull_Unchecked( sink, getters, ordinal ) );

            long result = getters.GetCharsLength( sink, ordinal );
            sink.ProcessMessagesAndThrow();
            return result;
        }
Example #33
0
        internal static Stream GetStream(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, bool bypassTypeCheck = false) {
            bool isDbNull = ValueUtilsSmi.IsDBNull_Unchecked(sink, getters, ordinal);

            // If a sql_variant, get the internal type
            if ( !bypassTypeCheck ) {
                if ((!isDbNull) && (metaData.SqlDbType == SqlDbType.Variant)) {
                    metaData = getters.GetVariantType(sink, ordinal);
                }
                // If the SqlDbType is still variant, then it must contain null, so don't throw InvalidCast
                if ((metaData.SqlDbType != SqlDbType.Variant) && (!CanAccessGetterDirectly(metaData, ExtendedClrTypeCode.Stream))) {
                    throw ADP.InvalidCast();
                }
            }

            byte[] data;
            if (isDbNull) {
                // "null" stream
                data = new byte[0];
            }
            else {
                // Read all data
                data = GetByteArray_Unchecked(sink, getters, ordinal);
            }

            // Wrap data in pre-built object
            return new MemoryStream(data, writable: false);
        }
Example #34
0
        private static DateTime GetDateTime_Unchecked( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal ) {
            Debug.Assert( !IsDBNull_Unchecked( sink, getters, ordinal ) );

            DateTime result = getters.GetDateTime( sink, ordinal );
            sink.ProcessMessagesAndThrow();
            return result;
        }
Example #35
0
 // calling GetTimeSpan on possibly v100 SMI
 internal static TimeSpan GetTimeSpan(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, bool gettersSupportKatmaiDateTime) {
     if (gettersSupportKatmaiDateTime) {
         return GetTimeSpan(sink, (SmiTypedGetterSetter)getters, ordinal, metaData);
     }
     ThrowIfITypedGettersIsNull(sink, getters, ordinal);
     object obj = GetValue(sink, getters, ordinal, metaData, null);
     if (null == obj) {
         throw ADP.InvalidCast();
     }
     return (TimeSpan) obj;
 }
Example #36
0
        private static SqlBinary GetSqlBinary_Unchecked( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal ) {
            Debug.Assert( !IsDBNull_Unchecked( sink, getters, ordinal ) );

            byte[] buffer = GetByteArray_Unchecked( sink, getters, ordinal );
            return new SqlBinary( buffer );
        }
Example #37
0
        //  implements SqlClient 1.1-compatible GetSqlValue() semantics for everything except output parameters
        internal static object GetSqlValue(
            SmiEventSink_Default    sink,
            ITypedGettersV3         getters,
            int                     ordinal,
            SmiMetaData             metaData,
            SmiContext              context
            ) {
            object result = null;
            if ( IsDBNull_Unchecked( sink, getters, ordinal ) ) {
                if (SqlDbType.Udt == metaData.SqlDbType) {
                    result = NullUdtInstance(metaData);
                }
                else {
                    result = __typeSpecificNullForSqlValue[(int)metaData.SqlDbType];
                }
            }
            else {
                switch( metaData.SqlDbType ) {
                    case SqlDbType.BigInt:
                        result = new SqlInt64( GetInt64_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.Binary:
                        result = GetSqlBinary_Unchecked( sink, getters, ordinal );
                        break;
                    case SqlDbType.Bit:
                        result = new SqlBoolean( GetBoolean_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.Char:
                        result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.DateTime:
                        result = new SqlDateTime( GetDateTime_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.Decimal:
                        result = GetSqlDecimal_Unchecked( sink, getters, ordinal );
                        break;
                    case SqlDbType.Float:
                        result = new SqlDouble( GetDouble_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.Image:
                        result = GetSqlBinary_Unchecked( sink, getters, ordinal );
                        break;
                    case SqlDbType.Int:
                        result = new SqlInt32( GetInt32_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.Money:
                        result = GetSqlMoney_Unchecked( sink, getters, ordinal );
                        break;
                    case SqlDbType.NChar: 
                        result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.NText: 
                        result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.NVarChar: 
                        result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.Real:
                        result = new SqlSingle( GetSingle_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.UniqueIdentifier:
                        result = new SqlGuid( GetGuid_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.SmallDateTime:
                        result = new SqlDateTime( GetDateTime_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.SmallInt:
                        result = new SqlInt16( GetInt16_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.SmallMoney:
                        result = GetSqlMoney_Unchecked( sink, getters, ordinal );
                        break;
                    case SqlDbType.Text:
                        result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.Timestamp:
                        result = GetSqlBinary_Unchecked( sink, getters, ordinal );
                        break;
                    case SqlDbType.TinyInt:
                        result = new SqlByte( GetByte_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.VarBinary:
                        result = GetSqlBinary_Unchecked( sink, getters, ordinal );
                        break;
                    case SqlDbType.VarChar:
                        result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) );
                        break;
                    case SqlDbType.Variant:
                        metaData = getters.GetVariantType( sink, ordinal );
                        sink.ProcessMessagesAndThrow();
                        Debug.Assert( SqlDbType.Variant != metaData.SqlDbType, "Variant-within-variant causes endless recursion!" );
                        result = GetSqlValue( sink, getters, ordinal, metaData, context );
                        break;
                    case SqlDbType.Xml: 
                        result = GetSqlXml_Unchecked( sink, getters, ordinal, context );
                        break;
                    case SqlDbType.Udt:
                        result = GetUdt_LengthChecked( sink, getters, ordinal, metaData );
                        break;
                }
            }

            return result;
        }
Example #38
0
        private static SqlDecimal GetSqlDecimal_Unchecked( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal ) {
            Debug.Assert( !IsDBNull_Unchecked( sink, getters, ordinal ) );

            SqlDecimal result = getters.GetSqlDecimal( sink, ordinal );
            sink.ProcessMessagesAndThrow();
            return result;
        }
 // Called when a new row arrives (ROW token)
 internal override void RowAvailable( ITypedGettersV3 rowData ) {
     if (null == _parent) {
         throw SQL.UnexpectedSmiEvent(UnexpectedEventType.RowAvailable);
     }
     _parent.RowAvailable( rowData );
 }
Example #40
0
        private static SqlMoney GetSqlMoney_Unchecked( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal ) {
            Debug.Assert( !IsDBNull_Unchecked( sink, getters, ordinal ) );

            Int64 temp = getters.GetInt64( sink, ordinal );
            sink.ProcessMessagesAndThrow();
            return new SqlMoney( temp, 1 /* ignored */ );
        }