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(); }
internal SqlInternalConnectionSmi(SqlConnectionString connectionOptions, SmiContext smiContext) : base(connectionOptions) { this._smiContext = smiContext; this._smiContext.OutOfScope += new EventHandler(this.OnOutOfScope); this._smiConnection = this._smiContext.ContextConnection; this._smiEventSink = new EventSink(this); if (Bid.AdvancedOn) { Bid.Trace("<sc.SqlInternalConnectionSmi.ctor|ADV> %d#, constructed new SMI internal connection\n", base.ObjectID); } }
// // 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(); }
internal SqlDataRecord(SmiRecordBuffer recordBuffer, params SmiExtendedMetaData[] metaData) { this._columnMetaData = new SqlMetaData[metaData.Length]; this._columnSmiMetaData = new SmiExtendedMetaData[metaData.Length]; for (int i = 0; i < this._columnSmiMetaData.Length; i++) { this._columnSmiMetaData[i] = metaData[i]; this._columnMetaData[i] = MetaDataUtilsSmi.SmiExtendedMetaDataToSqlMetaData(this._columnSmiMetaData[i]); } this._eventSink = new SmiEventSink_Default(); if (InOutOfProcHelper.InProc) { this._recordContext = SmiContextFactory.Instance.GetCurrentContext(); } else { this._recordContext = null; } this._recordBuffer = recordBuffer; this._eventSink.ProcessMessagesAndThrow(); }
public SqlDataRecord(params SqlMetaData[] metaData) { if (metaData == null) { throw ADP.ArgumentNull("metadata"); } this._columnMetaData = new SqlMetaData[metaData.Length]; this._columnSmiMetaData = new SmiExtendedMetaData[metaData.Length]; ulong smiVersion = this.SmiVersion; for (int i = 0; i < this._columnSmiMetaData.Length; i++) { if (metaData[i] == null) { throw ADP.ArgumentNull("metadata[" + i + "]"); } this._columnMetaData[i] = metaData[i]; this._columnSmiMetaData[i] = MetaDataUtilsSmi.SqlMetaDataToSmiExtendedMetaData(this._columnMetaData[i]); if (!MetaDataUtilsSmi.IsValidForSmiVersion(this._columnSmiMetaData[i], smiVersion)) { throw ADP.VersionDoesNotSupportDataType(this._columnSmiMetaData[i].TypeName); } } this._eventSink = new SmiEventSink_Default(); if (InOutOfProcHelper.InProc) { this._recordContext = SmiContextFactory.Instance.GetCurrentContext(); this._recordBuffer = this._recordContext.CreateRecordBuffer(this._columnSmiMetaData, this._eventSink); this._usesStringStorageForXml = false; } else { this._recordContext = null; this._recordBuffer = new MemoryRecordBuffer(this._columnSmiMetaData); this._usesStringStorageForXml = true; } this._eventSink.ProcessMessagesAndThrow(); }
internal void ExecuteToPipe(SmiContext pipeContext) { IntPtr ptr; SqlConnection.ExecutePermission.Demand(); this._pendingCancel = false; SqlStatistics statistics = null; Bid.ScopeEnter(out ptr, "<sc.SqlCommand.ExecuteToPipe|INFO> %d#", this.ObjectID); try { statistics = SqlStatistics.StartTimer(this.Statistics); this.InternalExecuteNonQuery(null, "ExecuteNonQuery", true); } finally { SqlStatistics.StopTimer(statistics); Bid.ScopeLeave(ref ptr); } }
private SqlContext( SmiContext smiContext ) { _smiContext = smiContext; _smiContext.OutOfScope += new EventHandler(OnOutOfScope); }
private void DisposeSmiRequest() { if (this._smiRequest != null) { SmiRequestExecutor executor = this._smiRequest; this._smiRequest = null; this._smiRequestContext = null; executor.Close(this.EventSink); this.EventSink.ProcessMessagesAndThrow(); } }
internal SqlInternalConnectionSmi(SqlConnectionString connectionOptions, SmiContext smiContext) : base(connectionOptions) { Debug.Assert(null != smiContext, "null smiContext?"); _smiContext = smiContext; _smiContext.OutOfScope += new EventHandler(OnOutOfScope); _smiConnection = _smiContext.ContextConnection; Debug.Assert(null != _smiConnection, "null SmiContext.ContextConnection?"); _smiEventSink = new EventSink(this); if (Bid.AdvancedOn) { Bid.Trace("<sc.SqlInternalConnectionSmi.ctor|ADV> %d#, constructed new SMI internal connection\n", ObjectID); } }
private SqlContext(SmiContext smiContext) { _smiContext = smiContext; _smiContext.OutOfScope += new EventHandler(OnOutOfScope); }
bool _hadErrorInResultSet; // true if an exception was thrown from within various bodies; used to control cleanup during SendResultsEnd internal SqlPipe( SmiContext smiContext ) { _smiContext = smiContext; _eventSink = new SmiEventSink_Default(); }
// 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; }
// UDTs and null variants come back via return value, all else is via targetBuffer. // implements SqlClient 1.1-compatible output parameter semantics internal static object GetOutputParameterV200Smi( SmiEventSink_Default sink, // event sink for errors SmiTypedGetterSetter 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) { // new types go here case SqlDbType.Variant: // Handle variants specifically for v200, since they could contain v200 types // 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!" ); GetOutputParameterV200Smi( sink, getters, ordinal, metaData, context, targetBuffer ); break; case SqlDbType.Date: targetBuffer.SetToDate(GetDateTime_Unchecked(sink, getters, ordinal)); break; case SqlDbType.DateTime2: targetBuffer.SetToDateTime2(GetDateTime_Unchecked(sink, getters, ordinal), metaData.Scale); break; case SqlDbType.Time: targetBuffer.SetToTime(GetTimeSpan_Unchecked(sink, getters, ordinal), metaData.Scale); break; case SqlDbType.DateTimeOffset: targetBuffer.SetToDateTimeOffset(GetDateTimeOffset_Unchecked(sink, getters, ordinal), metaData.Scale); break; default: result = GetOutputParameterV3Smi(sink, getters, ordinal, metaData, context, targetBuffer); break; } } return result; }
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; }
internal static SqlBytes GetSqlBytes(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, SmiContext context) { if (CanAccessGetterDirectly(metaData, ExtendedClrTypeCode.SqlBytes)) { if (IsDBNull_Unchecked(sink, getters, ordinal)) { return SqlBytes.Null; } long num = GetBytesLength_Unchecked(sink, getters, ordinal); if ((0L <= num) && (num < 0x1f40L)) { return new SqlBytes(GetByteArray_Unchecked(sink, getters, ordinal)); } Stream source = new SmiGettersStream(sink, getters, ordinal, metaData); return new SqlBytes(CopyIntoNewSmiScratchStream(source, sink, context)); } object obj2 = GetSqlValue(sink, getters, ordinal, metaData, null); if (obj2 == null) { throw ADP.InvalidCast(); } SqlBinary binary = (SqlBinary) obj2; if (binary.IsNull) { return SqlBytes.Null; } return new SqlBytes(binary.Value); }
private SqlContext(SmiContext smiContext) { this._smiContext = smiContext; this._smiContext.OutOfScope += new EventHandler(this.OnOutOfScope); }
internal static object GetOutputParameterV3Smi(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, SmiContext context, SqlBuffer targetBuffer) { object result = null; if (IsDBNull_Unchecked(sink, getters, ordinal)) { GetNullOutputParameterSmi(metaData, targetBuffer, ref result); return result; } switch (metaData.SqlDbType) { case SqlDbType.BigInt: targetBuffer.Int64 = GetInt64_Unchecked(sink, getters, ordinal); return result; case SqlDbType.Binary: case SqlDbType.Image: case SqlDbType.Timestamp: case SqlDbType.VarBinary: targetBuffer.SqlBinary = GetSqlBinary_Unchecked(sink, getters, ordinal); return result; case SqlDbType.Bit: targetBuffer.Boolean = GetBoolean_Unchecked(sink, getters, ordinal); return result; case SqlDbType.Char: case SqlDbType.NChar: case SqlDbType.NText: case SqlDbType.NVarChar: case SqlDbType.Text: case SqlDbType.VarChar: targetBuffer.SetToString(GetString_Unchecked(sink, getters, ordinal)); return result; case SqlDbType.DateTime: case SqlDbType.SmallDateTime: { SqlDateTime time = new SqlDateTime(GetDateTime_Unchecked(sink, getters, ordinal)); targetBuffer.SetToDateTime(time.DayTicks, time.TimeTicks); return result; } case SqlDbType.Decimal: { SqlDecimal num = GetSqlDecimal_Unchecked(sink, getters, ordinal); targetBuffer.SetToDecimal(num.Precision, num.Scale, num.IsPositive, num.Data); return result; } case SqlDbType.Float: targetBuffer.Double = GetDouble_Unchecked(sink, getters, ordinal); return result; case SqlDbType.Int: targetBuffer.Int32 = GetInt32_Unchecked(sink, getters, ordinal); return result; case SqlDbType.Money: case SqlDbType.SmallMoney: targetBuffer.SetToMoney(GetInt64_Unchecked(sink, getters, ordinal)); return result; case SqlDbType.Real: targetBuffer.Single = GetSingle_Unchecked(sink, getters, ordinal); return result; case SqlDbType.UniqueIdentifier: targetBuffer.SqlGuid = new SqlGuid(GetGuid_Unchecked(sink, getters, ordinal)); return result; case SqlDbType.SmallInt: targetBuffer.Int16 = GetInt16_Unchecked(sink, getters, ordinal); return result; case SqlDbType.TinyInt: targetBuffer.Byte = GetByte_Unchecked(sink, getters, ordinal); return result; case SqlDbType.Variant: metaData = getters.GetVariantType(sink, ordinal); sink.ProcessMessagesAndThrow(); GetOutputParameterV3Smi(sink, getters, ordinal, metaData, context, targetBuffer); return result; case (SqlDbType.SmallInt | SqlDbType.Int): case (SqlDbType.Text | SqlDbType.Int): case (SqlDbType.Xml | SqlDbType.Bit): case (SqlDbType.TinyInt | SqlDbType.Int): return result; case SqlDbType.Xml: targetBuffer.SqlXml = GetSqlXml_Unchecked(sink, getters, ordinal, null); return result; case SqlDbType.Udt: return GetUdt_LengthChecked(sink, getters, ordinal, metaData); } return result; }
internal static object GetOutputParameterV200Smi(SmiEventSink_Default sink, SmiTypedGetterSetter getters, int ordinal, SmiMetaData metaData, SmiContext context, SqlBuffer targetBuffer) { object result = null; if (IsDBNull_Unchecked(sink, getters, ordinal)) { GetNullOutputParameterSmi(metaData, targetBuffer, ref result); return result; } switch (metaData.SqlDbType) { case SqlDbType.Date: targetBuffer.SetToDate(GetDateTime_Unchecked(sink, getters, ordinal)); return result; case SqlDbType.Time: targetBuffer.SetToTime(GetTimeSpan_Unchecked(sink, getters, ordinal), metaData.Scale); return result; case SqlDbType.DateTime2: targetBuffer.SetToDateTime2(GetDateTime_Unchecked(sink, getters, ordinal), metaData.Scale); return result; case SqlDbType.DateTimeOffset: targetBuffer.SetToDateTimeOffset(GetDateTimeOffset_Unchecked(sink, getters, ordinal), metaData.Scale); return result; case SqlDbType.Variant: metaData = getters.GetVariantType(sink, ordinal); sink.ProcessMessagesAndThrow(); GetOutputParameterV200Smi(sink, getters, ordinal, metaData, context, targetBuffer); return result; } return GetOutputParameterV3Smi(sink, getters, ordinal, metaData, context, targetBuffer); }
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(); }
private void SetUpSmiRequest(SqlInternalConnectionSmi innerConnection) { this.DisposeSmiRequest(); if (this.Notification != null) { throw SQL.NotificationsNotAvailableOnContextConnection(); } SmiParameterMetaData[] parameterMetaData = null; ParameterPeekAheadValue[] valueArray = null; int parameterCount = this.GetParameterCount(this.Parameters); if (0 < parameterCount) { parameterMetaData = new SmiParameterMetaData[parameterCount]; valueArray = new ParameterPeekAheadValue[parameterCount]; for (int j = 0; j < parameterCount; j++) { SqlParameter parameter2 = this.Parameters[j]; parameter2.Validate(j, System.Data.CommandType.StoredProcedure == this.CommandType); parameterMetaData[j] = parameter2.MetaDataForSmi(out valueArray[j]); if (!innerConnection.IsKatmaiOrNewer) { MetaType metaTypeFromSqlDbType = MetaType.GetMetaTypeFromSqlDbType(parameterMetaData[j].SqlDbType, parameterMetaData[j].IsMultiValued); if (!metaTypeFromSqlDbType.Is90Supported) { throw ADP.VersionDoesNotSupportDataType(metaTypeFromSqlDbType.TypeName); } } } } System.Data.CommandType commandType = this.CommandType; this._smiRequestContext = innerConnection.InternalContext; this._smiRequest = this._smiRequestContext.CreateRequestExecutor(this.CommandText, commandType, parameterMetaData, this.EventSink); this.EventSink.ProcessMessagesAndThrow(); for (int i = 0; i < parameterCount; i++) { if ((ParameterDirection.Output == parameterMetaData[i].Direction) || (ParameterDirection.ReturnValue == parameterMetaData[i].Direction)) { continue; } SqlParameter parameter = this.Parameters[i]; object coercedValue = parameter.GetCoercedValue(); ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(parameterMetaData[i].SqlDbType, parameterMetaData[i].IsMultiValued, coercedValue, null, SmiContextFactory.Instance.NegotiatedSmiVersion); if ((System.Data.CommandType.StoredProcedure == commandType) && (ExtendedClrTypeCode.Empty == typeCode)) { this._smiRequest.SetDefault(i); continue; } int size = parameter.Size; if (((size != 0) && (size != -1L)) && !parameter.SizeInferred) { switch (parameterMetaData[i].SqlDbType) { case SqlDbType.NText: if (size != 0x3fffffff) { throw SQL.ParameterSizeRestrictionFailure(i); } break; case SqlDbType.NVarChar: if (((size > 0) && (size != 0x3fffffff)) && (parameterMetaData[i].MaxLength == -1L)) { throw SQL.ParameterSizeRestrictionFailure(i); } break; case SqlDbType.Text: case SqlDbType.Image: goto Label_01E8; case SqlDbType.Timestamp: if (size < SmiMetaData.DefaultTimestamp.MaxLength) { throw SQL.ParameterSizeRestrictionFailure(i); } break; case SqlDbType.VarBinary: case SqlDbType.VarChar: goto Label_020C; case SqlDbType.Variant: goto Label_0271; case SqlDbType.Xml: if ((coercedValue != null) && (ExtendedClrTypeCode.SqlXml != typeCode)) { throw SQL.ParameterSizeRestrictionFailure(i); } break; } } goto Label_02CF; Label_01E8: if (size == 0x7fffffff) { goto Label_02CF; } throw SQL.ParameterSizeRestrictionFailure(i); Label_020C: if (((size <= 0) || (size == 0x7fffffff)) || (parameterMetaData[i].MaxLength != -1L)) { goto Label_02CF; } throw SQL.ParameterSizeRestrictionFailure(i); Label_0271: if (coercedValue != null) { MetaType metaTypeFromValue = MetaType.GetMetaTypeFromValue(coercedValue); if (((metaTypeFromValue.IsNCharType && (size < 0xfa0L)) || (metaTypeFromValue.IsBinType && (size < 0x1f40L))) || (metaTypeFromValue.IsAnsiType && (size < 0x1f40L))) { throw SQL.ParameterSizeRestrictionFailure(i); } } Label_02CF: if (innerConnection.IsKatmaiOrNewer) { ValueUtilsSmi.SetCompatibleValueV200(this.EventSink, this._smiRequest, i, parameterMetaData[i], coercedValue, typeCode, parameter.Offset, parameter.Size, valueArray[i]); } else { ValueUtilsSmi.SetCompatibleValue(this.EventSink, this._smiRequest, i, parameterMetaData[i], coercedValue, typeCode, parameter.Offset); } } }
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; }
internal static SqlChars GetSqlChars(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, SmiContext context) { if (CanAccessGetterDirectly(metaData, ExtendedClrTypeCode.SqlChars)) { if (IsDBNull_Unchecked(sink, getters, ordinal)) { return SqlChars.Null; } if ((GetCharsLength_Unchecked(sink, getters, ordinal) < 0xfa0L) || !InOutOfProcHelper.InProc) { return new SqlChars(GetCharArray_Unchecked(sink, getters, ordinal)); } Stream source = new SmiGettersStream(sink, getters, ordinal, metaData); return new SqlChars(CopyIntoNewSmiScratchStreamChars(source, sink, context)); } if (SqlDbType.Xml == metaData.SqlDbType) { SqlXml xml = GetSqlXml_Unchecked(sink, getters, ordinal, null); if (xml.IsNull) { return SqlChars.Null; } return new SqlChars(xml.Value.ToCharArray()); } object obj2 = GetSqlValue(sink, getters, ordinal, metaData, null); if (obj2 == null) { throw ADP.InvalidCast(); } SqlString str = (SqlString) obj2; if (str.IsNull) { return SqlChars.Null; } return new SqlChars(str.Value.ToCharArray()); }
bool _hadErrorInResultSet; // true if an exception was thrown from within various bodies; used to control cleanup during SendResultsEnd internal SqlPipe(SmiContext smiContext) { _smiContext = smiContext; _eventSink = new SmiEventSink_Default(); }
// 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 SqlDateTime( 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; }
private static SqlXml GetSqlXml_Unchecked(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiContext context) { if ((context == null) && InOutOfProcHelper.InProc) { context = SmiContextFactory.Instance.GetCurrentContext(); } Stream source = new SmiGettersStream(sink, getters, ordinal, SmiMetaData.DefaultXml); return new SqlXml(CopyIntoNewSmiScratchStream(source, sink, context)); }
// spool a Stream into a scratch stream from the Smi interface and return it as a SqlStreamChars internal static SqlStreamChars CopyIntoNewSmiScratchStreamChars( Stream source, SmiEventSink_Default sink, SmiContext context ) { SqlClientWrapperSmiStreamChars dest = new SqlClientWrapperSmiStreamChars( sink, context.GetScratchStream( sink ) ); int chunkSize; if ( source.CanSeek && __maxByteChunkSize > source.Length ) { chunkSize = unchecked( (int) source.Length ); // unchecked cast is safe due to check on line above } else { chunkSize = __maxByteChunkSize; } byte[] copyBuffer = new byte[chunkSize]; int bytesRead; while ( 0 != ( bytesRead = source.Read( copyBuffer, 0, chunkSize ) ) ) { dest.Write( copyBuffer, 0, bytesRead ); } dest.Flush(); // SQLBU 494334 // Need to re-wind scratch stream to beginning before returning dest.Seek(0, SeekOrigin.Begin); return dest; }
internal static object GetValue(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, SmiContext context) { object obj2 = null; if (IsDBNull_Unchecked(sink, getters, ordinal)) { return DBNull.Value; } switch (metaData.SqlDbType) { case SqlDbType.BigInt: return GetInt64_Unchecked(sink, getters, ordinal); case SqlDbType.Binary: return GetByteArray_Unchecked(sink, getters, ordinal); case SqlDbType.Bit: return GetBoolean_Unchecked(sink, getters, ordinal); case SqlDbType.Char: return GetString_Unchecked(sink, getters, ordinal); case SqlDbType.DateTime: return GetDateTime_Unchecked(sink, getters, ordinal); case SqlDbType.Decimal: return GetSqlDecimal_Unchecked(sink, getters, ordinal).Value; case SqlDbType.Float: return GetDouble_Unchecked(sink, getters, ordinal); case SqlDbType.Image: return GetByteArray_Unchecked(sink, getters, ordinal); case SqlDbType.Int: return GetInt32_Unchecked(sink, getters, ordinal); case SqlDbType.Money: return GetSqlMoney_Unchecked(sink, getters, ordinal).Value; case SqlDbType.NChar: return GetString_Unchecked(sink, getters, ordinal); case SqlDbType.NText: return GetString_Unchecked(sink, getters, ordinal); case SqlDbType.NVarChar: return GetString_Unchecked(sink, getters, ordinal); case SqlDbType.Real: return GetSingle_Unchecked(sink, getters, ordinal); case SqlDbType.UniqueIdentifier: return GetGuid_Unchecked(sink, getters, ordinal); case SqlDbType.SmallDateTime: return GetDateTime_Unchecked(sink, getters, ordinal); case SqlDbType.SmallInt: return GetInt16_Unchecked(sink, getters, ordinal); case SqlDbType.SmallMoney: return GetSqlMoney_Unchecked(sink, getters, ordinal).Value; case SqlDbType.Text: return GetString_Unchecked(sink, getters, ordinal); case SqlDbType.Timestamp: return GetByteArray_Unchecked(sink, getters, ordinal); case SqlDbType.TinyInt: return GetByte_Unchecked(sink, getters, ordinal); case SqlDbType.VarBinary: return GetByteArray_Unchecked(sink, getters, ordinal); case SqlDbType.VarChar: return GetString_Unchecked(sink, getters, ordinal); case SqlDbType.Variant: metaData = getters.GetVariantType(sink, ordinal); sink.ProcessMessagesAndThrow(); return GetValue(sink, getters, ordinal, metaData, context); case (SqlDbType.SmallInt | SqlDbType.Int): case (SqlDbType.Text | SqlDbType.Int): case (SqlDbType.Xml | SqlDbType.Bit): case (SqlDbType.TinyInt | SqlDbType.Int): return obj2; case SqlDbType.Xml: return GetSqlXml_Unchecked(sink, getters, ordinal, context).Value; case SqlDbType.Udt: return GetUdt_LengthChecked(sink, getters, ordinal, metaData); } return obj2; }
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; }
internal static object GetValue200(SmiEventSink_Default sink, SmiTypedGetterSetter getters, int ordinal, SmiMetaData metaData, SmiContext context) { if (IsDBNull_Unchecked(sink, getters, ordinal)) { return DBNull.Value; } switch (metaData.SqlDbType) { case SqlDbType.Date: case SqlDbType.DateTime2: return GetDateTime_Unchecked(sink, getters, ordinal); case SqlDbType.Time: return GetTimeSpan_Unchecked(sink, getters, ordinal); case SqlDbType.DateTimeOffset: return GetDateTimeOffset_Unchecked(sink, getters, ordinal); case SqlDbType.Variant: metaData = getters.GetVariantType(sink, ordinal); sink.ProcessMessagesAndThrow(); return GetValue200(sink, getters, ordinal, metaData, context); } return GetValue(sink, getters, ordinal, metaData, context); }
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; }
internal static Stream CopyIntoNewSmiScratchStream(Stream source, SmiEventSink_Default sink, SmiContext context) { Stream stream; int length; int num2; if (context == null) { stream = new MemoryStream(); } else { stream = new SqlClientWrapperSmiStream(sink, context.GetScratchStream(sink)); } if (source.CanSeek && (0x1f40L > source.Length)) { length = (int) source.Length; } else { length = 0x1f40; } byte[] buffer = new byte[length]; while ((num2 = source.Read(buffer, 0, length)) != 0) { stream.Write(buffer, 0, num2); } stream.Flush(); stream.Seek(0L, SeekOrigin.Begin); return stream; }
// 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; }
internal static SqlStreamChars CopyIntoNewSmiScratchStreamChars(Stream source, SmiEventSink_Default sink, SmiContext context) { int length; int num2; SqlClientWrapperSmiStreamChars chars = new SqlClientWrapperSmiStreamChars(sink, context.GetScratchStream(sink)); if (source.CanSeek && (0x1f40L > source.Length)) { length = (int) source.Length; } else { length = 0x1f40; } byte[] buffer = new byte[length]; while ((num2 = source.Read(buffer, 0, length)) != 0) { chars.Write(buffer, 0, num2); } chars.Flush(); chars.Seek(0L, SeekOrigin.Begin); return chars; }