Beispiel #1
0
 public static void WriteTypeInfoLen(this TdsPackageWriter writer, TdsMetaType.MetaDataWrite metaType, int size, bool isNull)
 {
     //write length or isNull information about the type
     if (metaType.IsPlp)
     {
         if (isNull)
         {
             writer.WriteInt64(unchecked ((long)TdsEnums.SQL_PLP_NULL));
         }
         else
         {
             writer.WriteInt64(size);
         }
     }
     else if (metaType.IsLong)
     {
         // text/image/SQLVariant have a 4 byte length, plp datatypes have 8 byte lengths
         if (isNull)
         {
             writer.WriteInt32(unchecked ((int)TdsEnums.VARLONGNULL));
         }
         else
         {
             writer.WriteInt32(size);
         }
     }
     else if (metaType.NullableType == TdsEnums.SQLDATETIME2 || metaType.NullableType == TdsEnums.SQLTIME || metaType.NullableType == TdsEnums.SQLDATETIMEOFFSET)
     {
         if (isNull)
         {
             writer.WriteByte(TdsEnums.FIXEDNULL);
         }
         else
         {
             writer.WriteByte((byte)size);
         }
     }
     else if (metaType.NullableType == TdsEnums.SQLBIGVARBINARY || metaType.NullableType == TdsEnums.SQLBIGCHAR || metaType.NullableType == TdsEnums.SQLNCHAR || metaType.NullableType == TdsEnums.SQLNVARCHAR) //skip varchar
     {
         // non-long but variable length column, must be a BIG* type: 2 byte length
         writer.WriteInt16(isNull ? TdsEnums.VARNULL : size);
     }
     else
     {
         if (isNull)
         {
             writer.WriteByte(TdsEnums.FIXEDNULL);
         }
         else
         {
             writer.WriteByte((byte)size); // 1 byte for everything else
         }
     }
 }
Beispiel #2
0
 public static void WriteParameterLen(this TdsPackageWriter writer, TdsMetaType.MetaDataWrite metaType, int size, bool isNull)
 {
     if (isNull)
     {
         return;
     }
     //write length of the parameter
     if (metaType.IsPlp)
     {
         writer.WriteInt64(size);
     }
     else if (metaType.IsLong)
     {
         // text/image/SQLVariant have a 4 byte length, plp datatypes have 8 byte lengths
         writer.WriteInt32(size);
     }
     else if (metaType.NullableType == TdsEnums.SQLDATETIME2 || metaType.NullableType == TdsEnums.SQLTIME || metaType.NullableType == TdsEnums.SQLDATETIMEOFFSET)
     {
         writer.WriteByte((byte)size);
     }
     else if (metaType.NullableType == TdsEnums.SQLBIGVARBINARY || metaType.NullableType == TdsEnums.SQLBIGCHAR || metaType.NullableType == TdsEnums.SQLNCHAR || metaType.NullableType == TdsEnums.SQLNVARCHAR) //skip varchar
     {
         writer.WriteInt16(size);
     }
     else
     {
         writer.WriteByte((byte)size); // 1 byte for everything else
     }
 }
Beispiel #3
0
        public static void WriteValue(TdsPackageWriter writer, object?value, TdsMetaType.MetaDataWrite metaData, bool isNull)
        {
            // write the value now
            if (isNull)
            {
                return;
            }
            switch (value)
            {
            case string v:
                writer.WriteUnicodeString(v);
                break;

            case decimal v:
                writer.WriteSqlDecimal(v, 17);
                break;

            case bool v:
                writer.WriteByte(v ? 1 : 0);
                break;

            case DateTime v:
                writer.WriteDateTime(v);
                break;

            case byte v:
                writer.WriteByte(v);
                break;

            case short v:
                writer.WriteInt16(v);
                break;

            case int v:
                writer.WriteInt32(v);
                break;

            case long v:
                writer.WriteInt64(v);
                break;

            case float v:
                writer.WriteFloat(v);
                break;

            case double v:
                writer.WriteDouble(v);
                break;
            }
        }
Beispiel #4
0
        public static void WriteMarsHeader(this TdsPackageWriter writer, long sqlTransactionId)
        {
            const int marsHeaderSize    = 18; // 4 + (2 + 8 + 4)= size + data
            const int totalHeaderLength = 22; // 4 + (4 + 2 + 8 + 4) size+mars

            writer.WriteInt32(totalHeaderLength);

            writer.WriteInt32(marsHeaderSize);

            writer.WriteInt16(TdsEnums.HEADERTYPE_MARS);

            writer.WriteInt64(sqlTransactionId);

            writer.WriteInt32(1);
        }
Beispiel #5
0
 public void WriteSqlInt64(long value, int index)
 {
     _writer.WriteInt64(value);
 }