Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Data / System / Data / SqlClient / TdsParameterSetter.cs / 1 / TdsParameterSetter.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.SqlClient {
using System;
using System.Data;
using System.Data.SqlTypes;
using System.Diagnostics;
using Microsoft.SqlServer.Server;
// Simple Getter/Setter for structured parameters to allow using common ValueUtilsSmi code.
// This is a stand-in to having a true SmiRequestExecutor class for TDS.
internal class TdsParameterSetter : SmiTypedGetterSetter {
#region Private fields
private TdsRecordBufferSetter _target;
#if UseSmiForTds
private TdsValueSetter _scalarTarget;
#endif
#endregion
#region ctor & control
internal TdsParameterSetter(TdsParserStateObject stateObj, SmiMetaData md) {
#if UseSmiForTds
if (SqlDbType.Structured == md.SqlDbType) {
#endif
_target = new TdsRecordBufferSetter(stateObj, md);
#if UseSmiForTds
}
else {
_scalarTarget = new TdsValueSetter(stateObj, md);
}
#endif
}
#endregion
#region TypedGetterSetter overrides
// Are calls to Get methods allowed?
internal override bool CanGet {
get {
return false;
}
}
// Are calls to Set methods allowed?
internal override bool CanSet {
get {
return true;
}
}
// valid for structured types
// This method called for both get and set.
internal override SmiTypedGetterSetter GetTypedGetterSetter(SmiEventSink sink, int ordinal) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
return _target;
}
// Set value to null
// valid for all types
public override void SetDBNull(SmiEventSink sink, int ordinal) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
#if UseSmiForTds
if (SqlDbType.Structured == md.SqlDbType) {
#endif
_target.EndElements(sink);
#if UseSmiForTds
}
else {
_scalarTarget.SetDBNull();
}
#endif
}
#if UseSmiForTds
// valid for SqlDbType.Bit
public override void SetBoolean(SmiEventSink sink, int ordinal, Boolean value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetBoolean(value);
}
// valid for SqlDbType.TinyInt
public override void SetByte(SmiEventSink sink, int ordinal, Byte value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetByte(value);
}
// Semantics for SetBytes are to modify existing value, not overwrite
// Use in combination with SetLength to ensure overwriting when necessary
// valid for SqlDbTypes: Binary, VarBinary, Image, Udt, Xml
// (VarBinary assumed for variants)
public override int SetBytes(SmiEventSink sink, int ordinal, long fieldOffset, byte[] buffer, int bufferOffset, int length) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
return _scalarTarget.SetBytes(fieldOffset, buffer, bufferOffset, length);
}
public override void SetBytesLength(SmiEventSink sink, int ordinal, long length) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetBytesLength(length);
}
// Semantics for SetChars are to modify existing value, not overwrite
// Use in combination with SetLength to ensure overwriting when necessary
// valid for character types: Char, VarChar, Text, NChar, NVarChar, NText
// (NVarChar and global clr collation assumed for variants)
public override int SetChars(SmiEventSink sink, int ordinal, long fieldOffset, char[] buffer, int bufferOffset, int length) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
return _scalarTarget.SetChars(fieldOffset, buffer, bufferOffset, length);
}
public override void SetCharsLength(SmiEventSink sink, int ordinal, long length) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetCharsLength(length);
}
// valid for character types: Char, VarChar, Text, NChar, NVarChar, NText
public override void SetString(SmiEventSink sink, int ordinal, string value, int offset, int length) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetString(value, offset, length);
}
// valid for SqlDbType.SmallInt
public override void SetInt16(SmiEventSink sink, int ordinal, Int16 value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetInt16(value);
}
// valid for SqlDbType.Int
public override void SetInt32(SmiEventSink sink, int ordinal, Int32 value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetInt32(value);
}
// valid for SqlDbType.BigInt, SqlDbType.Money, SqlDbType.SmallMoney
public override void SetInt64(SmiEventSink sink, int ordinal, Int64 value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetInt64(value);
}
// valid for SqlDbType.Real
public override void SetSingle(SmiEventSink sink, int ordinal, Single value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetSingle(value);
}
// valid for SqlDbType.Float
public override void SetDouble(SmiEventSink sink, int ordinal, Double value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetDouble(value);
}
// valid for SqlDbType.Numeric (uses SqlDecimal since Decimal cannot hold full range)
public override void SetSqlDecimal(SmiEventSink sink, int ordinal, SqlDecimal value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetSqlDecimal(value);
}
// valid for DateTime & SmallDateTime
public override void SetDateTime(SmiEventSink sink, int ordinal, DateTime value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetDateTime(value);
}
// valid for UniqueIdentifier
public override void SetGuid(SmiEventSink sink, int ordinal, Guid value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetGuid(value);
}
#endif
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.SqlClient {
using System;
using System.Data;
using System.Data.SqlTypes;
using System.Diagnostics;
using Microsoft.SqlServer.Server;
// Simple Getter/Setter for structured parameters to allow using common ValueUtilsSmi code.
// This is a stand-in to having a true SmiRequestExecutor class for TDS.
internal class TdsParameterSetter : SmiTypedGetterSetter {
#region Private fields
private TdsRecordBufferSetter _target;
#if UseSmiForTds
private TdsValueSetter _scalarTarget;
#endif
#endregion
#region ctor & control
internal TdsParameterSetter(TdsParserStateObject stateObj, SmiMetaData md) {
#if UseSmiForTds
if (SqlDbType.Structured == md.SqlDbType) {
#endif
_target = new TdsRecordBufferSetter(stateObj, md);
#if UseSmiForTds
}
else {
_scalarTarget = new TdsValueSetter(stateObj, md);
}
#endif
}
#endregion
#region TypedGetterSetter overrides
// Are calls to Get methods allowed?
internal override bool CanGet {
get {
return false;
}
}
// Are calls to Set methods allowed?
internal override bool CanSet {
get {
return true;
}
}
// valid for structured types
// This method called for both get and set.
internal override SmiTypedGetterSetter GetTypedGetterSetter(SmiEventSink sink, int ordinal) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
return _target;
}
// Set value to null
// valid for all types
public override void SetDBNull(SmiEventSink sink, int ordinal) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
#if UseSmiForTds
if (SqlDbType.Structured == md.SqlDbType) {
#endif
_target.EndElements(sink);
#if UseSmiForTds
}
else {
_scalarTarget.SetDBNull();
}
#endif
}
#if UseSmiForTds
// valid for SqlDbType.Bit
public override void SetBoolean(SmiEventSink sink, int ordinal, Boolean value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetBoolean(value);
}
// valid for SqlDbType.TinyInt
public override void SetByte(SmiEventSink sink, int ordinal, Byte value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetByte(value);
}
// Semantics for SetBytes are to modify existing value, not overwrite
// Use in combination with SetLength to ensure overwriting when necessary
// valid for SqlDbTypes: Binary, VarBinary, Image, Udt, Xml
// (VarBinary assumed for variants)
public override int SetBytes(SmiEventSink sink, int ordinal, long fieldOffset, byte[] buffer, int bufferOffset, int length) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
return _scalarTarget.SetBytes(fieldOffset, buffer, bufferOffset, length);
}
public override void SetBytesLength(SmiEventSink sink, int ordinal, long length) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetBytesLength(length);
}
// Semantics for SetChars are to modify existing value, not overwrite
// Use in combination with SetLength to ensure overwriting when necessary
// valid for character types: Char, VarChar, Text, NChar, NVarChar, NText
// (NVarChar and global clr collation assumed for variants)
public override int SetChars(SmiEventSink sink, int ordinal, long fieldOffset, char[] buffer, int bufferOffset, int length) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
return _scalarTarget.SetChars(fieldOffset, buffer, bufferOffset, length);
}
public override void SetCharsLength(SmiEventSink sink, int ordinal, long length) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetCharsLength(length);
}
// valid for character types: Char, VarChar, Text, NChar, NVarChar, NText
public override void SetString(SmiEventSink sink, int ordinal, string value, int offset, int length) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetString(value, offset, length);
}
// valid for SqlDbType.SmallInt
public override void SetInt16(SmiEventSink sink, int ordinal, Int16 value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetInt16(value);
}
// valid for SqlDbType.Int
public override void SetInt32(SmiEventSink sink, int ordinal, Int32 value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetInt32(value);
}
// valid for SqlDbType.BigInt, SqlDbType.Money, SqlDbType.SmallMoney
public override void SetInt64(SmiEventSink sink, int ordinal, Int64 value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetInt64(value);
}
// valid for SqlDbType.Real
public override void SetSingle(SmiEventSink sink, int ordinal, Single value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetSingle(value);
}
// valid for SqlDbType.Float
public override void SetDouble(SmiEventSink sink, int ordinal, Double value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetDouble(value);
}
// valid for SqlDbType.Numeric (uses SqlDecimal since Decimal cannot hold full range)
public override void SetSqlDecimal(SmiEventSink sink, int ordinal, SqlDecimal value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetSqlDecimal(value);
}
// valid for DateTime & SmallDateTime
public override void SetDateTime(SmiEventSink sink, int ordinal, DateTime value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetDateTime(value);
}
// valid for UniqueIdentifier
public override void SetGuid(SmiEventSink sink, int ordinal, Guid value) {
Debug.Assert(0==ordinal, "TdsParameterSetter only supports 0 for ordinal. Actual = " + ordinal);
_scalarTarget.SetGuid(value);
}
#endif
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CurrencyManager.cs
- LinkedResourceCollection.cs
- SystemTcpStatistics.cs
- OleDbCommandBuilder.cs
- HTTP_SERVICE_CONFIG_URLACL_KEY.cs
- ClassDataContract.cs
- ComponentManagerBroker.cs
- GroupStyle.cs
- DesignOnlyAttribute.cs
- ImportContext.cs
- SqlAggregateChecker.cs
- MsmqEncryptionAlgorithm.cs
- GeneralTransform3DGroup.cs
- ProcessModelInfo.cs
- UserControlAutomationPeer.cs
- WebFormDesignerActionService.cs
- HttpVersion.cs
- RequestQueue.cs
- DataGridSortCommandEventArgs.cs
- SingleResultAttribute.cs
- NonClientArea.cs
- ConfigurationSection.cs
- FormatterServicesNoSerializableCheck.cs
- HyperlinkAutomationPeer.cs
- CultureInfoConverter.cs
- PageOutputQuality.cs
- GenericAuthenticationEventArgs.cs
- PixelShader.cs
- PropertyToken.cs
- TextRangeProviderWrapper.cs
- BitConverter.cs
- BaseCodeDomTreeGenerator.cs
- XmlImplementation.cs
- EntityDataSourceSelectingEventArgs.cs
- CompiledXpathExpr.cs
- RegionIterator.cs
- SqlServices.cs
- DoWorkEventArgs.cs
- OracleFactory.cs
- DialogResultConverter.cs
- OrderingQueryOperator.cs
- Base64Decoder.cs
- DataColumnCollection.cs
- ConnectionPoint.cs
- ConsumerConnectionPointCollection.cs
- StringValueConverter.cs
- AssemblyCollection.cs
- DragDrop.cs
- LogRestartAreaEnumerator.cs
- KerberosRequestorSecurityToken.cs
- TrustLevel.cs
- Matrix3DConverter.cs
- SizeChangedEventArgs.cs
- DefaultProfileManager.cs
- BitmapEffectvisualstate.cs
- ProxyBuilder.cs
- __TransparentProxy.cs
- DesignerAdRotatorAdapter.cs
- WsdlInspector.cs
- BitmapSizeOptions.cs
- SqlTrackingService.cs
- DESCryptoServiceProvider.cs
- TemplateControlCodeDomTreeGenerator.cs
- WhitespaceRule.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- StretchValidation.cs
- PartialClassGenerationTaskInternal.cs
- VectorValueSerializer.cs
- ContextStaticAttribute.cs
- EntityCodeGenerator.cs
- namescope.cs
- XPathDocumentBuilder.cs
- IApplicationTrustManager.cs
- ConfigurationElementProperty.cs
- XamlFigureLengthSerializer.cs
- DescendantQuery.cs
- TiffBitmapDecoder.cs
- Byte.cs
- SspiSecurityToken.cs
- GeometryCollection.cs
- TouchDevice.cs
- compensatingcollection.cs
- SpellerStatusTable.cs
- EventLogEntryCollection.cs
- QilTargetType.cs
- PathTooLongException.cs
- SecurityDescriptor.cs
- BaseCollection.cs
- XsltSettings.cs
- UnicastIPAddressInformationCollection.cs
- TlsnegoTokenAuthenticator.cs
- Double.cs
- PeerCustomResolverElement.cs
- DigestComparer.cs
- XmlReader.cs
- TableItemPattern.cs
- ObjectManager.cs
- FullTextLine.cs
- StringDictionary.cs
- SQLByte.cs