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 TdsValueSetter(TdsParserStateObject stateObj, SmiMetaData md)
 {
     this._stateObj = stateObj;
     this._metaData = md;
     this._isPlp = MetaDataUtilsSmi.IsPlpFormat(md);
     this._plpUnknownSent = false;
     this._encoder = null;
 }
 internal SmiSettersStream(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData)
 {
     this._sink = sink;
     this._setters = setters;
     this._ordinal = ordinal;
     this._lengthWritten = 0L;
     this._metaData = metaData;
 }
 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;
 }
        internal MemoryRecordBuffer(SmiMetaData[] metaData) {
            Debug.Assert(null != metaData, "invalid attempt to instantiate MemoryRecordBuffer with null SmiMetaData[]");

            _buffer = new SqlRecordBuffer[metaData.Length];

            for (int i = 0; i < _buffer.Length; ++i) {
                _buffer[i] = new SqlRecordBuffer(metaData[i]);
            }
        }
 internal TdsRecordBufferSetter(TdsParserStateObject stateObj, SmiMetaData md)
 {
     this._fieldSetters = new TdsValueSetter[md.FieldMetaData.Count];
     for (int i = 0; i < md.FieldMetaData.Count; i++)
     {
         this._fieldSetters[i] = new TdsValueSetter(stateObj, md.FieldMetaData[i]);
     }
     this._stateObj = stateObj;
     this._metaData = md;
 }
Example #7
0
        private int                     _currentOffset; // for chunking, verify that caller is using correct offsets
#endif

        #endregion

        #region Exposed Construct/factory methods

        internal TdsValueSetter(TdsParserStateObject stateObj, SmiMetaData md) {
            _stateObj = stateObj;
            _metaData = md;
            _isPlp = MetaDataUtilsSmi.IsPlpFormat(md);
            _plpUnknownSent = false;
            _encoder = null;
#if DEBUG
            _currentOffset = 0;
#endif
        }
Example #8
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;
        }
        private int                     _currentField;      // validate that caller sets columns in correct order.
#endif

        #endregion
        
        #region Exposed Construct and control methods/properties

        internal TdsRecordBufferSetter(TdsParserStateObject stateObj, SmiMetaData md) {
            Debug.Assert(SqlDbType.Structured == md.SqlDbType, "Unsupported SqlDbType: " + md.SqlDbType);
            _fieldSetters = new TdsValueSetter[md.FieldMetaData.Count];
            for(int i=0; i<md.FieldMetaData.Count; i++) {
                _fieldSetters[i] = new TdsValueSetter(stateObj, md.FieldMetaData[i]);
            }
            _stateObj = stateObj;
            _metaData = md;
#if DEBUG
            _currentField = ReadyForToken;
#endif
        }
        internal SmiSettersStream( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData ) {
            Debug.Assert( null != sink );
            Debug.Assert( null != setters );
            Debug.Assert( 0 <= ordinal );
            Debug.Assert( null != metaData );

            _sink = sink;
            _setters = setters;
            _ordinal = ordinal;
            _lengthWritten = 0;
            _metaData = metaData;
        }
Example #12
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 #13
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 #14
0
 // dealing with v200 SMI
 internal static TimeSpan GetTimeSpan(SmiEventSink_Default sink, SmiTypedGetterSetter getters, int ordinal, SmiMetaData metaData) {
     ThrowIfITypedGettersIsNull(sink, getters, ordinal);
     if (CanAccessGetterDirectly(metaData, ExtendedClrTypeCode.TimeSpan)) {
         return GetTimeSpan_Unchecked(sink, getters, ordinal);
     }
     return (TimeSpan)GetValue200(sink, getters, ordinal, metaData, null);
 }
Example #15
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 #16
0
 private static void SetSqlString_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData, SqlString value, int offset, int length ) {
     if ( value.IsNull ) {
         setters.SetDBNull( sink, ordinal );
         sink.ProcessMessagesAndThrow();
     }
     else {
         if (SqlDbType.Variant == metaData.SqlDbType) {
             // Set up a NVarChar metadata with correct LCID/Collation
             metaData = new SmiMetaData(
                     SqlDbType.NVarChar, 
                     SmiMetaData.MaxUnicodeCharacters,
                     0, 
                     0, 
                     value.LCID,
                     value.SqlCompareOptions,
                     null);
             setters.SetVariantMetaData( sink, ordinal, metaData );
             sink.ProcessMessagesAndThrow();
         }
         SetString_Unchecked( sink, setters, ordinal, value.Value, offset, length );
     }
 }
Example #17
0
        private static void SetSqlMoney_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData, SqlMoney value ) {
            if ( value.IsNull ) {
                setters.SetDBNull( sink, ordinal );
            }
            else {
                if ( SqlDbType.Variant == metaData.SqlDbType ) {
                    setters.SetVariantMetaData( sink, ordinal, SmiMetaData.DefaultMoney );
                    sink.ProcessMessagesAndThrow();
                }

                setters.SetInt64( sink, ordinal, value.ToSqlInternalRepresentation() );
             }
            sink.ProcessMessagesAndThrow();
        }
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 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 #20
0
        private static void SetDataTable_Unchecked(
                SmiEventSink_Default    sink,
                SmiTypedGetterSetter    setters,
                int                     ordinal,
                SmiMetaData             metaData,
                DataTable               value
            ) {
            // Get the target gettersetter
            setters = setters.GetTypedGetterSetter(sink, ordinal);
            sink.ProcessMessagesAndThrow();

            // iterate over all records
            //  if first record was obtained earlier, use it prior to pulling more
            ExtendedClrTypeCode[] cellTypes = new ExtendedClrTypeCode[metaData.FieldMetaData.Count];
            for(int i=0; i<metaData.FieldMetaData.Count; i++) {
                cellTypes[i] = ExtendedClrTypeCode.Invalid;
            }
            foreach(DataRow row in value.Rows) {
                setters.NewElement(sink);
                sink.ProcessMessagesAndThrow();

                // Set all columns in the record
                for(int i=0; i<metaData.FieldMetaData.Count; i++) {
                    SmiMetaData fieldMetaData = metaData.FieldMetaData[i];
                    if (row.IsNull(i)) {
                        SetDBNull_Unchecked(sink, setters, i);
                    }
                    else {
                        object cellValue = row[i];

                        // Only determine cell types for first row, to save expensive 
                        if (ExtendedClrTypeCode.Invalid == cellTypes[i]) {
                            cellTypes[i] = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(
                                    fieldMetaData.SqlDbType, fieldMetaData.IsMultiValued, cellValue, fieldMetaData.Type, 
                                    // 

                                    SmiContextFactory.KatmaiVersion 
                                    );
                        }
                        SetCompatibleValueV200(sink, setters, i, fieldMetaData, cellValue, cellTypes[i], 0, NoLengthLimit, null);
                    }
                }
            }

            setters.EndElements(sink);
            sink.ProcessMessagesAndThrow();
        }
Example #21
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 #22
0
        // Set a DbDataReader to a Structured+MultiValued setter (table type)
        //  Assumes metaData correctly describes the reader's shape, and consumes only the current resultset
        private static void SetDbDataReader_Unchecked(
            SmiEventSink_Default    sink,
            SmiTypedGetterSetter    setters,
            int                     ordinal,
            SmiMetaData             metaData,
            DbDataReader            value
            ) {
            // Get the target gettersetter
            setters = setters.GetTypedGetterSetter(sink, ordinal);
            sink.ProcessMessagesAndThrow();

            // Iterate over all rows in the current set of results
            while (value.Read()) {
                setters.NewElement(sink);
                sink.ProcessMessagesAndThrow();

                FillCompatibleSettersFromReader(sink, setters, metaData.FieldMetaData, value);
            }

            setters.EndElements(sink);
            sink.ProcessMessagesAndThrow();
        }
Example #23
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 #24
0
        // dealing with v200 SMI
        internal static object GetSqlValue200(
            SmiEventSink_Default sink,
            SmiTypedGetterSetter 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.Variant: // Handle variants specifically for v200, since they could contain v200 types
                        metaData = getters.GetVariantType(sink, ordinal);
                        sink.ProcessMessagesAndThrow();
                        Debug.Assert(SqlDbType.Variant != metaData.SqlDbType, "Variant-within-variant causes endless recursion!");
                        result = GetSqlValue200(sink, getters, ordinal, metaData, context);
                        break;
                    case SqlDbType.Date:
                    case SqlDbType.DateTime2:
                        result = GetDateTime_Unchecked(sink, getters, ordinal);
                        break;
                    case SqlDbType.Time:
                        result = GetTimeSpan_Unchecked(sink, getters, ordinal);
                        break;
                    case SqlDbType.DateTimeOffset:
                        result = GetDateTimeOffset_Unchecked(sink, getters, ordinal);
                        break;
                    default:
                        result = GetSqlValue(sink, getters, ordinal, metaData, context);
                        break;
                }
            }

            return result;
        }
Example #25
0
        private static void SetIEnumerableOfSqlDataRecord_Unchecked(
            SmiEventSink_Default        sink,
            SmiTypedGetterSetter        setters,
            int                         ordinal,
            SmiMetaData                 metaData,
            IEnumerable<SqlDataRecord>  value,
            ParameterPeekAheadValue     peekAhead
            ) {
            // Get target gettersetter
            setters = setters.GetTypedGetterSetter(sink, ordinal);
            sink.ProcessMessagesAndThrow();

            IEnumerator<SqlDataRecord> enumerator = null;
            try {
                // Need to copy field metadata to an array to call FillCompatibleITypeSettersFromRecord
                SmiExtendedMetaData[] mdFields = new SmiExtendedMetaData[metaData.FieldMetaData.Count];
                metaData.FieldMetaData.CopyTo(mdFields, 0);

                SmiDefaultFieldsProperty defaults = (SmiDefaultFieldsProperty) metaData.ExtendedProperties[SmiPropertySelector.DefaultFields];

                int recordNumber = 1;   // used only for reporting position when there are errors.

                // obtain enumerator and handle any peekahead values
                if (null != peekAhead && null != peekAhead.FirstRecord) {
                    // hook up to enumerator
                    enumerator = peekAhead.Enumerator;

                    // send the first record that was obtained earlier
                    setters.NewElement(sink);
                    sink.ProcessMessagesAndThrow();
                    FillCompatibleSettersFromRecord(sink, setters, mdFields, peekAhead.FirstRecord, defaults);
                    recordNumber++;
                }
                else {
                    enumerator = value.GetEnumerator();
                }

                using (enumerator) {
                    while(enumerator.MoveNext()) {
                        setters.NewElement(sink);
                        sink.ProcessMessagesAndThrow();

                        SqlDataRecord record = enumerator.Current;

                        if (record.FieldCount != mdFields.Length) {
                            throw SQL.EnumeratedRecordFieldCountChanged(recordNumber);
                        }

                        for(int i=0; i<record.FieldCount; i++) {
                            if (!MetaDataUtilsSmi.IsCompatible(metaData.FieldMetaData[i], record.GetSqlMetaData(i))) {
                                throw SQL.EnumeratedRecordMetaDataChanged(record.GetName(i), recordNumber);
                            }
                        }

                        FillCompatibleSettersFromRecord(sink, setters, mdFields, record, defaults);
                        recordNumber++;
                    }

                    setters.EndElements(sink);
                    sink.ProcessMessagesAndThrow();
                }
            }
            finally {
                // Clean up!
                IDisposable disposable = enumerator as IDisposable;
                if (null != disposable) {
                    disposable.Dispose();
                }
            }
        }
        public virtual void SetVariantMetaData( SmiEventSink sink, int ordinal, SmiMetaData metaData ) {
            // ******** OBSOLETING from SMI -- this should have been removed from ITypedSettersV3
            //  Intended to be removed prior to RTM.  Sub-classes need not implement

            // 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 V3+ and dropped support for V2-.
            //  2) Server didn't implement V2- on some interface and negotiated V2-.
            throw System.Data.Common.ADP.InternalError( System.Data.Common.ADP.InternalErrorCode.UnimplementedSMIMethod );
        }
Example #27
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 #28
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;
        }
        private bool         _isMetaSet; // flag to indicate whether we have set the variant metadata

        internal SqlRecordBuffer(SmiMetaData metaData) {
            _isNull = true;
        }
Example #30
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;
        }