Esempio n. 1
0
        //
        //  SqlDataRecord public API
        //

        public SqlDataRecord(params SqlMetaData[] metaData)
        {
            // Initial consistency check
            if (null == metaData)
            {
                throw ADP.ArgumentNull(nameof(metaData));
            }

            _columnMetaData    = new SqlMetaData[metaData.Length];
            _columnSmiMetaData = new SmiExtendedMetaData[metaData.Length];
            for (int i = 0; i < _columnSmiMetaData.Length; i++)
            {
                if (null == metaData[i])
                {
                    throw ADP.ArgumentNull($"{nameof(metaData)}[{i}]");
                }
                _columnMetaData[i]    = metaData[i];
                _columnSmiMetaData[i] = MetaDataUtilsSmi.SqlMetaDataToSmiExtendedMetaData(_columnMetaData[i]);
            }

            _eventSink = new SmiEventSink_Default();

            _recordBuffer            = new MemoryRecordBuffer(_columnSmiMetaData);
            _usesStringStorageForXml = true;
            _eventSink.ProcessMessagesAndThrow();
        }
        internal SqlDataRecord(SmiRecordBuffer recordBuffer, params SmiExtendedMetaData[] metaData)
        {
            Debug.Assert(null != recordBuffer, "invalid attempt to instantiate SqlDataRecord with null SmiRecordBuffer");
            Debug.Assert(null != metaData, "invalid attempt to instantiate SqlDataRecord with null SmiExtendedMetaData[]");

            _columnMetaData    = new SqlMetaData[metaData.Length];
            _columnSmiMetaData = new SmiExtendedMetaData[metaData.Length];
            for (int i = 0; i < _columnSmiMetaData.Length; i++)
            {
                _columnSmiMetaData[i] = metaData[i];
                _columnMetaData[i]    = MetaDataUtilsSmi.SmiExtendedMetaDataToSqlMetaData(_columnSmiMetaData[i]);
            }

            _eventSink = new SmiEventSink_Default( );

            if (InOutOfProcHelper.InProc)
            {
                _recordContext = SmiContextFactory.Instance.GetCurrentContext();
            }
            else
            {
                _recordContext = null;
            }
            _recordBuffer = recordBuffer;
            _eventSink.ProcessMessagesAndThrow();
        }
Esempio n. 3
0
        internal SqlDataRecord(SmiRecordBuffer recordBuffer, params SmiExtendedMetaData[] metaData)
        {
            Debug.Assert(null != recordBuffer, "invalid attempt to instantiate SqlDataRecord with null SmiRecordBuffer");
            Debug.Assert(null != metaData, "invalid attempt to instantiate SqlDataRecord with null SmiExtendedMetaData[]");

            _columnMetaData    = new SqlMetaData[metaData.Length];
            _columnSmiMetaData = new SmiExtendedMetaData[metaData.Length];
            for (int i = 0; i < _columnSmiMetaData.Length; i++)
            {
                _columnSmiMetaData[i] = metaData[i];
                _columnMetaData[i]    = MetaDataUtilsSmi.SmiExtendedMetaDataToSqlMetaData(_columnSmiMetaData[i]);
            }

            _eventSink = new SmiEventSink_Default();

            _recordBuffer = recordBuffer;
            _eventSink.ProcessMessagesAndThrow();
        }
Esempio n. 4
0
        internal SmiContext GetCurrentContext()
        {
            if (null == _smiLink)
            {
                throw SQL.ContextUnavailableOutOfProc();    // Must not be a valid version of Sql Server, or not be SqlCLR
            }

            object result = _smiLink.GetCurrentContext(_eventSinkForGetCurrentContext);

            _eventSinkForGetCurrentContext.ProcessMessagesAndThrow();

            if (null == result)
            {
                throw SQL.ContextUnavailableWhileInProc();
            }

            Debug.Assert(typeof(SmiContext).IsInstanceOfType(result), "didn't get SmiContext from GetCurrentContext?");
            return((SmiContext)result);
        }
        //
        //  SqlDataRecord public API
        //

        public SqlDataRecord(params SqlMetaData[] metaData)
        {
            // Initial consistency check
            if (null == metaData)
            {
                throw ADP.ArgumentNull("metadata");
            }

            _columnMetaData    = new SqlMetaData[metaData.Length];
            _columnSmiMetaData = new SmiExtendedMetaData[metaData.Length];
            ulong smiVersion = SmiVersion;

            for (int i = 0; i < _columnSmiMetaData.Length; i++)
            {
                if (null == metaData[i])
                {
                    throw ADP.ArgumentNull("metadata[" + i + "]");
                }
                _columnMetaData[i]    = metaData[i];
                _columnSmiMetaData[i] = MetaDataUtilsSmi.SqlMetaDataToSmiExtendedMetaData(_columnMetaData[i]);
                if (!MetaDataUtilsSmi.IsValidForSmiVersion(_columnSmiMetaData[i], smiVersion))
                {
                    throw ADP.VersionDoesNotSupportDataType(_columnSmiMetaData[i].TypeName);
                }
            }

            _eventSink = new SmiEventSink_Default( );

            if (InOutOfProcHelper.InProc)
            {
                _recordContext           = SmiContextFactory.Instance.GetCurrentContext();
                _recordBuffer            = _recordContext.CreateRecordBuffer(_columnSmiMetaData, _eventSink);
                _usesStringStorageForXml = false;
            }
            else
            {
                _recordContext           = null;
                _recordBuffer            = new MemoryRecordBuffer(_columnSmiMetaData);
                _usesStringStorageForXml = true;
            }
            _eventSink.ProcessMessagesAndThrow();
        }
Esempio n. 6
0
 private static void SetSqlXml_Unchecked(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlXml value) {
     if (value.IsNull) {
         setters.SetDBNull(sink, ordinal);
         sink.ProcessMessagesAndThrow();
     }
     else {
         SetXmlReader_Unchecked(sink, setters, ordinal, value.CreateReader());
     }
 }
Esempio n. 7
0
 private static void SetSqlSingle_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlSingle value ) {
     if ( value.IsNull ) {
         setters.SetDBNull( sink, ordinal );
     }
     else {
         setters.SetSingle( sink, ordinal, value.Value ); 
     }
     sink.ProcessMessagesAndThrow();
 }
Esempio n. 8
0
        private static void SetSqlChars_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlChars value, int offset, int length ) {
            if ( value.IsNull ) {
                setters.SetDBNull( sink, ordinal );
                sink.ProcessMessagesAndThrow();
            }
            else {
                int chunkSize;
                if ( length > __maxCharChunkSize || length < 0 ) {
                    chunkSize = __maxCharChunkSize;
                }
                else {
                    chunkSize = checked( (int)length );
                }

                char[] buffer = new char[ chunkSize ];
                long charsRead;
                long charsWritten = 1;  // prime value to get into write loop
                long currentOffset = offset;
                long lengthWritten = 0;

                while ( (length < 0  || lengthWritten < length) &&
                        0 != ( charsRead = value.Read( currentOffset, buffer, 0, chunkSize ) ) &&
                        0 != charsWritten ) {
                    charsWritten = setters.SetChars( sink, ordinal, currentOffset, buffer, 0, checked( (int) charsRead ) );
                    sink.ProcessMessagesAndThrow();
                    checked{ currentOffset += charsWritten; }
                    checked{ lengthWritten += charsWritten;}
                }

                // Make sure to trim any left-over data
                setters.SetCharsLength( sink, ordinal, currentOffset );
                sink.ProcessMessagesAndThrow();
            }
        }
Esempio n. 9
0
 private static void SetSingle_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, Single value ) {
     setters.SetSingle( sink, ordinal, value ); 
     sink.ProcessMessagesAndThrow();
 }
Esempio n. 10
0
 private static void SetDate_Unchecked(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData, DateTime value)
 {
     Debug.Assert(SqlDbType.Variant == metaData.SqlDbType, "Invalid type. This should be called only when the type is variant.");
     setters.SetVariantMetaData(sink, ordinal, SmiMetaData.DefaultDate);
     setters.SetDateTime(sink, ordinal, value);
     sink.ProcessMessagesAndThrow();
 }
Esempio n. 11
0
 private static void SetDBNull_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal ) {
     setters.SetDBNull( sink, ordinal );
     sink.ProcessMessagesAndThrow();
 }
Esempio n. 12
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;
        }
Esempio n. 13
0
 //
 //  Private implementation of common mappings from a given type to corresponding Smi Getter/Setter
 //      These classes do type validation, parameter limit validation, nor coercions
 //
     private static bool IsDBNull_Unchecked( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal ) {
         bool result = getters.IsDBNull( sink, ordinal );
         sink.ProcessMessagesAndThrow();
         return result;
     }
 public override void Flush()
 {
     _stream.Flush(_sink);
     _sink.ProcessMessagesAndThrow();
 }
Esempio n. 15
0
 private static void SetString_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, String value, int offset, int length ) {
     setters.SetString( sink, ordinal, value, offset, length ); 
     sink.ProcessMessagesAndThrow();
 }
Esempio n. 16
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();
        }
Esempio n. 17
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;
        }
Esempio n. 18
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;
        }
Esempio n. 19
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;
        }
Esempio n. 20
0
 private static void SetDecimal_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, Decimal value ) {
     setters.SetSqlDecimal( sink, ordinal, new SqlDecimal( value ) ); 
     sink.ProcessMessagesAndThrow();
 }
Esempio n. 21
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;
        }
Esempio n. 22
0
 private static void SetDateTimeOffset_Unchecked(SmiEventSink_Default sink, SmiTypedGetterSetter setters, int ordinal, DateTimeOffset value) {
     setters.SetDateTimeOffset(sink, ordinal, value);
     sink.ProcessMessagesAndThrow();
 }
Esempio n. 23
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;
        }
Esempio n. 24
0
 private static void SetSqlBinary_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlBinary value, int offset, int length ) {
     if ( value.IsNull ) {
         setters.SetDBNull( sink, ordinal );
     }
     else {
         SetByteArray_Unchecked( sink, setters, ordinal, value.Value, offset, length );
     }
     sink.ProcessMessagesAndThrow();
 }
Esempio n. 25
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 */ );
        }
Esempio n. 26
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();
        }
Esempio n. 27
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;
        }
Esempio n. 28
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 );
     }
 }
Esempio n. 29
0
        private static TimeSpan GetTimeSpan_Unchecked(SmiEventSink_Default sink, SmiTypedGetterSetter getters, int ordinal) {
            Debug.Assert(!IsDBNull_Unchecked(sink, getters, ordinal));

            TimeSpan result = getters.GetTimeSpan(sink, ordinal);
            sink.ProcessMessagesAndThrow();
            return result;
        }
Esempio n. 30
0
        private static void SetXmlReader_Unchecked(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, XmlReader xmlReader) {
            // set up writer
            XmlWriterSettings WriterSettings = new XmlWriterSettings();
            WriterSettings.CloseOutput = false;		// don't close the memory stream
            WriterSettings.ConformanceLevel = ConformanceLevel.Fragment;
            WriterSettings.Encoding = System.Text.Encoding.Unicode;
            WriterSettings.OmitXmlDeclaration = true;

            System.IO.Stream target = new SmiSettersStream(sink, setters, ordinal, SmiMetaData.DefaultXml);

            XmlWriter xmlWriter = XmlWriter.Create(target, WriterSettings);

            // now spool the data into the writer (WriteNode will call Read())
            xmlReader.Read();
            while (!xmlReader.EOF) {
                xmlWriter.WriteNode(xmlReader, true);
            }
            xmlWriter.Flush();
            sink.ProcessMessagesAndThrow();
        }
Esempio n. 31
0
        private static void SetTextReader_Unchecked(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metadata, TextDataFeed feed) {
            long len = metadata.MaxLength;
            char[] buff = new char[constTextBufferSize];
            int nWritten = 0;
            do {
                int nRead = 0;
                int readSize = constTextBufferSize;
                if (len > 0 && nWritten + readSize > len) {
                    readSize = (int)(len - nWritten);
                }

                Debug.Assert(readSize >= 0);

                nRead = feed._source.Read(buff, 0, readSize);

                if (nRead == 0) {
                    break;
                }

                setters.SetChars(sink, ordinal, nWritten, buff, 0, nRead);
                sink.ProcessMessagesAndThrow();

                nWritten += nRead;
            } while (len <= 0 || nWritten < len);

            setters.SetCharsLength(sink, ordinal, nWritten);
            sink.ProcessMessagesAndThrow();
        }
Esempio n. 32
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();
        }
Esempio n. 33
0
 private static void SetCharArray_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, char[] buffer, int bufferOffset, int length ) {
     if ( length > 0 ) {
         setters.SetChars( sink, ordinal, 0, buffer, bufferOffset, length );
         sink.ProcessMessagesAndThrow();
     }
     setters.SetCharsLength( sink, ordinal, length );
     sink.ProcessMessagesAndThrow();
 }
Esempio n. 34
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();
                }
            }
        }
Esempio n. 35
0
 private static int SetChars_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, long fieldOffset, char[] buffer, int bufferOffset, int length ) {
     int result = setters.SetChars( sink, ordinal, fieldOffset, buffer, bufferOffset, length );
     sink.ProcessMessagesAndThrow();
     return result;
 }
Esempio n. 36
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;
        }
Esempio n. 37
0
        // Equivalent to TSQL PRINT statement -- sends an info-only message.
        public void Send(string message)
        {
            ADP.CheckArgumentNull(message, "message");

            if (SmiMetaData.MaxUnicodeCharacters < message.Length)
            {
                throw SQL.SqlPipeMessageTooLong(message.Length);
            }

            SetPipeBusy( );
            try {
                EnsureNormalSendValid("Send");

                _smiContext.SendMessageToPipe(message, _eventSink);

                // Handle any errors that are reported.
                _eventSink.ProcessMessagesAndThrow();
            }
            catch {
                _eventSink.CleanMessages();
                throw;
            }
            finally {
                ClearPipeBusy( );
                Debug.Assert(_eventSink.HasMessages == false, "There should be no messages left in _eventsink at the end of the Send message!");
            }
        }