Example #1
0
        private void WriteParameterInfo(TdsMetaParameter param)
        {
            /*
             * Ms.net send non-nullable datatypes as nullable and allows setting null values
             * to int/float etc.. So, using Nullable form of type for all data
             */
            param.IsNullable = true;
            TdsColumnType colType = param.GetMetaType();

            param.IsNullable = false;

            tds.Comm.Append((byte)colType);              // type

            int size = 0;

            if (param.Size == 0)
            {
                size = param.GetActualSize();
            }
            else
            {
                size = param.Size;
            }

            /*
             * If column type is SqlDbType.NVarChar the size of parameter is multiplied by 2
             * FIXME: Need to check for other types
             */
            if (colType == TdsColumnType.BigNVarChar)
            {
                size <<= 1;
            }
            if (tds.IsLargeType(colType))
            {
                tds.Comm.Append((short)size);                  // Parameter size passed in SqlParameter
            }
            else if (tds.IsBlobType(colType))
            {
                tds.Comm.Append(size);                  // Parameter size passed in SqlParameter
            }
            else
            {
                tds.Comm.Append((byte)size);
            }

            // Precision and Scale are non-zero for only decimal/numeric
            if (param.TypeName == "decimal" || param.TypeName == "numeric")
            {
                tds.Comm.Append((param.Precision != 0)?param.Precision:(byte)29);
                tds.Comm.Append(param.Scale);
            }
        }
Example #2
0
        private void WriteParameterInfo(TdsMetaParameter param)
        {
            TdsColumnType colType = param.GetMetaType();

            int size = 0;

            if (param.Size == 0)
            {
                size = param.GetActualSize();
            }
            else
            {
                size = param.Size;
            }

            /*
             * If column type is SqlDbType.NVarChar the size of parameter is multiplied by 2
             * FIXME: Need to check for other types
             */
            if (colType == TdsColumnType.BigNVarChar)
            {
                size <<= 1;
            }

            // Total hack for varchar(max) and nvarchar(max)
            // They are coming back as Text and not the correct values
            // based on the size we can determine what the correct type is
            // We need the size to come out to 0xFFFF on the wire.
            if (param.IsVarNVarCharMax)
            {
                colType = TdsColumnType.BigNVarChar;
            }
            else if (param.IsVarCharMax)
            {
                colType = TdsColumnType.BigVarChar;
            }

            tds.Comm.Append((byte)colType);              // type

            param.CalculateIsVariableType();

            if (param.IsAnyVarCharMax)
            {
                tds.Comm.Append((byte)0xFF);
                tds.Comm.Append((byte)0xFF);
            }
            else if (tds.IsLargeType(colType))
            {
                tds.Comm.Append((short)size);                  // Parameter size passed in SqlParameter
            }
            else if (tds.IsBlobType(colType))
            {
                tds.Comm.Append(size);                  // Parameter size passed in SqlParameter
            }
            else if (param.IsVariableSizeType)
            {
                tds.Comm.Append((byte)size);
            }

            // Precision and Scale are non-zero for only decimal/numeric
            if (param.TypeName == "decimal" || param.TypeName == "numeric")
            {
                tds.Comm.Append((param.Precision != 0)?param.Precision:(byte)29);
                tds.Comm.Append(param.Scale);
            }

            // Documentation is basically 0 on these 5 bytes.  But in a nutshell it seems during a bulk insert
            // these are required for text types.
            if (param.IsTextType)
            {
                tds.Comm.Append((byte)0x09);
                tds.Comm.Append((byte)0x04);
                tds.Comm.Append((byte)0xd0);
                tds.Comm.Append((byte)0x00);
                tds.Comm.Append((byte)0x34);
            }
        }