本文整理汇总了C#中System.Data.SqlClient.SqlBuffer.SetToDecimal方法的典型用法代码示例。如果您正苦于以下问题:C# SqlBuffer.SetToDecimal方法的具体用法?C# SqlBuffer.SetToDecimal怎么用?C# SqlBuffer.SetToDecimal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlBuffer
的用法示例。
在下文中一共展示了SqlBuffer.SetToDecimal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOutputParameterV3Smi
// 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;
}
示例2: TryReadSqlDecimal
private bool TryReadSqlDecimal(SqlBuffer value, int length, byte precision, byte scale, TdsParserStateObject stateObj)
{
byte byteValue;
if (!stateObj.TryReadByte(out byteValue))
{
return false;
}
bool fPositive = (1 == byteValue);
length = checked((int)length - 1);
int[] bits;
if (!TryReadDecimalBits(length, stateObj, out bits))
{
return false;
}
value.SetToDecimal(precision, scale, fPositive, bits);
return true;
}
示例3: DeserializeUnencryptedValue
//.........这里部分代码省略.........
case TdsEnums.SQLVARBINARY:
case TdsEnums.SQLIMAGE:
{
// Note: Better not come here with plp data!!
Debug.Assert(length <= TdsEnums.MAXSIZE, "Plp data decryption attempted");
// If this is a fixed length type, pad with zeros to get to the fixed length size.
if (tdsType == TdsEnums.SQLBINARY || tdsType == TdsEnums.SQLBIGBINARY) {
byte[] bytes = new byte[md.baseTI.length];
Buffer.BlockCopy(unencryptedBytes, 0, bytes, 0, unencryptedBytes.Length);
unencryptedBytes = bytes;
}
value.SqlBinary = new SqlBinary(unencryptedBytes, true); // doesn't copy the byte array
break;
}
case TdsEnums.SQLDECIMALN:
case TdsEnums.SQLNUMERICN:
// Check the sign from the first byte.
int index = 0;
byteValue = unencryptedBytes[index++];
bool fPositive = (1 == byteValue);
// Now read the 4 next integers which contain the actual value.
length = checked((int)length-1);
int[] bits = new int[4];
int decLength = length>>2;
for (int i = 0; i < decLength; i++) {
// up to 16 bytes of data following the sign byte
bits[i] = BitConverter.ToInt32(unencryptedBytes, index);
index += 4;
}
value.SetToDecimal (md.baseTI.precision, md.baseTI.scale, fPositive, bits);
break;
case TdsEnums.SQLCHAR:
case TdsEnums.SQLBIGCHAR:
case TdsEnums.SQLVARCHAR:
case TdsEnums.SQLBIGVARCHAR:
case TdsEnums.SQLTEXT:
{
System.Text.Encoding encoding = md.baseTI.encoding;
if (null == encoding) {
encoding = _defaultEncoding;
}
if (null == encoding) {
ThrowUnsupportedCollationEncountered(stateObj);
}
string strValue = encoding.GetString(unencryptedBytes, 0, length);
// If this is a fixed length type, pad with spaces to get to the fixed length size.
if (tdsType == TdsEnums.SQLCHAR || tdsType == TdsEnums.SQLBIGCHAR) {
strValue = strValue.PadRight(md.baseTI.length);
}
value.SetToString(strValue);
break;
}
case TdsEnums.SQLNCHAR:
case TdsEnums.SQLNVARCHAR:
case TdsEnums.SQLNTEXT:
示例4: GetOutputParameterV3Smi
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;
}
示例5: ReadSqlDecimal
private void ReadSqlDecimal(SqlBuffer value, int length, byte precision, byte scale, TdsParserStateObject stateObj)
{
bool positive = 1 == stateObj.ReadByte();
length--;
int[] bits = this.ReadDecimalBits(length, stateObj);
value.SetToDecimal(precision, scale, positive, bits);
}