internal void WriteParameterVarLen(MetaType type, int size, bool isNull, TdsParserStateObject stateObj, bool unknownLength = false)
{
if (type.IsLong)
{ // text/image/SQLVariant have a 4 byte length, plp datatypes have 8 byte lengths
if (isNull)
{
if (type.IsPlp)
{
WriteLong(unchecked((long)TdsEnums.SQL_PLP_NULL), stateObj);
}
else
{
WriteInt(unchecked((int)TdsEnums.VARLONGNULL), stateObj);
}
}
else if (type.NullableType == TdsEnums.SQLXMLTYPE || unknownLength)
{
WriteUnsignedLong(TdsEnums.SQL_PLP_UNKNOWNLEN, stateObj);
}
else if (type.IsPlp)
{
// Non-xml plp types
WriteLong((long)size, stateObj);
}
else
{
WriteInt(size, stateObj);
}
}
else if (type.IsVarTime)
{
if (isNull)
{
stateObj.WriteByte(TdsEnums.FIXEDNULL);
}
else
{
stateObj.WriteByte((byte)size);
}
}
else if (false == type.IsFixed)
{ // non-long but variable length column, must be a BIG* type: 2 byte length
if (isNull)
{
WriteShort(TdsEnums.VARNULL, stateObj);
}
else
{
WriteShort(size, stateObj);
}
}
else
{
if (isNull)
{
stateObj.WriteByte(TdsEnums.FIXEDNULL);
}
else
{
Debug.Assert(type.FixedLength <= 0xff, "WriteParameterVarLen: invalid one byte length!");
stateObj.WriteByte((byte)(type.FixedLength & 0xff)); // 1 byte for everything else
}
}
}