当前位置: 首页>>代码示例>>C#>>正文


C# SqlClient.SqlMetaDataPriv类代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlMetaDataPriv的典型用法代码示例。如果您正苦于以下问题:C# SqlMetaDataPriv类的具体用法?C# SqlMetaDataPriv怎么用?C# SqlMetaDataPriv使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SqlMetaDataPriv类属于System.Data.SqlClient命名空间,在下文中一共展示了SqlMetaDataPriv类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SqlCachedBuffer

 internal SqlCachedBuffer(SqlMetaDataPriv metadata, TdsParser parser, TdsParserStateObject stateObj)
 {
     int len = 0;
     this._cachedBytes = new ArrayList();
     ulong num = parser.PlpBytesLeft(stateObj);
     do
     {
         if (num == 0L)
         {
             return;
         }
         do
         {
             len = (num > 0x800L) ? 0x800 : ((int) num);
             byte[] buff = new byte[len];
             len = stateObj.ReadPlpBytes(ref buff, 0, len);
             if (this._cachedBytes.Count == 0)
             {
                 this.AddByteOrderMark(buff);
             }
             this._cachedBytes.Add(buff);
             num -= len;
         }
         while (num > 0L);
         num = parser.PlpBytesLeft(stateObj);
     }
     while (num > 0L);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:SqlCachedBuffer.cs

示例2: TryCreate

        // Reads off from the network buffer and caches bytes. Only reads one column value in the current row.
        static internal bool TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsParserStateObject stateObj, out SqlCachedBuffer buffer)
        {
            int cb = 0;
            ulong plplength;
            byte[] byteArr;

            List<byte[]> cachedBytes = new List<byte[]>();
            buffer = null;

            // the very first length is already read.
            if (!parser.TryPlpBytesLeft(stateObj, out plplength))
            {
                return false;
            }
            // For now we  only handle Plp data from the parser directly.
            Debug.Assert(metadata.metaType.IsPlp, "SqlCachedBuffer call on a non-plp data");
            do
            {
                if (plplength == 0)
                    break;
                do
                {
                    cb = (plplength > (ulong)_maxChunkSize) ? _maxChunkSize : (int)plplength;
                    byteArr = new byte[cb];
                    if (!stateObj.TryReadPlpBytes(ref byteArr, 0, cb, out cb))
                    {
                        return false;
                    }
                    Debug.Assert(cb == byteArr.Length);
                    if (cachedBytes.Count == 0)
                    {
                        // Add the Byte order mark if needed if we read the first array
                        AddByteOrderMark(byteArr, cachedBytes);
                    }
                    cachedBytes.Add(byteArr);
                    plplength -= (ulong)cb;
                } while (plplength > 0);
                if (!parser.TryPlpBytesLeft(stateObj, out plplength))
                {
                    return false;
                }
            } while (plplength > 0);
            Debug.Assert(stateObj._longlen == 0 && stateObj._longlenleft == 0);

            buffer = new SqlCachedBuffer(cachedBytes);
            return true;
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:48,代码来源:SqlCachedBuffer.cs

示例3: ProcessUDTMetaData

 private void ProcessUDTMetaData(SqlMetaDataPriv metaData, TdsParserStateObject stateObj)
 {
     metaData.length = stateObj.ReadUInt16();
     int length = stateObj.ReadByte();
     if (length != 0)
     {
         metaData.udtDatabaseName = stateObj.ReadString(length);
     }
     length = stateObj.ReadByte();
     if (length != 0)
     {
         metaData.udtSchemaName = stateObj.ReadString(length);
     }
     length = stateObj.ReadByte();
     if (length != 0)
     {
         metaData.udtTypeName = stateObj.ReadString(length);
     }
     length = stateObj.ReadUInt16();
     if (length != 0)
     {
         metaData.udtAssemblyQualifiedName = stateObj.ReadString(length);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:24,代码来源:TdsParser.cs

示例4: WriteBulkCopyValue

        internal Task WriteBulkCopyValue(object value, SqlMetaDataPriv metadata, TdsParserStateObject stateObj, bool isSqlType, bool isDataFeed, bool isNull)
        {
            Debug.Assert(!isSqlType || value is INullable, "isSqlType is true, but value can not be type cast to an INullable");
            Debug.Assert(!isDataFeed ^ value is DataFeed, "Incorrect value for isDataFeed");

            Encoding saveEncoding = _defaultEncoding;
            SqlCollation saveCollation = _defaultCollation;
            int saveCodePage = _defaultCodePage;
            int saveLCID = _defaultLCID;
            Task resultTask = null;
            Task internalWriteTask = null;

            if (!(State == TdsParserState.OpenNotLoggedIn || State == TdsParserState.OpenLoggedIn))
            {
                throw ADP.ClosedConnectionError();
            }
            try
            {
                if (metadata.encoding != null)
                {
                    _defaultEncoding = metadata.encoding;
                }
                if (metadata.collation != null)
                {
                    _defaultCollation = metadata.collation;
                    _defaultLCID = _defaultCollation.LCID;
                }
                _defaultCodePage = metadata.codePage;

                MetaType metatype = metadata.metaType;
                int ccb = 0;
                int ccbStringBytes = 0;

                if (isNull)
                {
                    // For UDT, remember we treat as binary even though it is a PLP
                    if (metatype.IsPlp && (metatype.NullableType != TdsEnums.SQLUDT || metatype.IsLong))
                    {
                        WriteLong(unchecked((long)TdsEnums.SQL_PLP_NULL), stateObj);
                    }
                    else if (!metatype.IsFixed && !metatype.IsLong && !metatype.IsVarTime)
                    {
                        WriteShort(TdsEnums.VARNULL, stateObj);
                    }
                    else
                    {
                        stateObj.WriteByte(TdsEnums.FIXEDNULL);
                    }
                    return resultTask;
                }

                if (!isDataFeed)
                {
                    switch (metatype.NullableType)
                    {
                        case TdsEnums.SQLBIGBINARY:
                        case TdsEnums.SQLBIGVARBINARY:
                        case TdsEnums.SQLIMAGE:
                        case TdsEnums.SQLUDT:
                            ccb = (isSqlType) ? ((SqlBinary)value).Length : ((byte[])value).Length;
                            break;
                        case TdsEnums.SQLUNIQUEID:
                            ccb = GUID_SIZE;   // that's a constant for guid
                            break;
                        case TdsEnums.SQLBIGCHAR:
                        case TdsEnums.SQLBIGVARCHAR:
                        case TdsEnums.SQLTEXT:
                            if (null == _defaultEncoding)
                            {
                                ThrowUnsupportedCollationEncountered(null); // stateObject only when reading
                            }

                            string stringValue = null;
                            if (isSqlType)
                            {
                                stringValue = ((SqlString)value).Value;
                            }
                            else
                            {
                                stringValue = (string)value;
                            }

                            ccb = stringValue.Length;
                            ccbStringBytes = _defaultEncoding.GetByteCount(stringValue);
                            break;
                        case TdsEnums.SQLNCHAR:
                        case TdsEnums.SQLNVARCHAR:
                        case TdsEnums.SQLNTEXT:
                            ccb = ((isSqlType) ? ((SqlString)value).Value.Length : ((string)value).Length) * 2;
                            break;
                        case TdsEnums.SQLXMLTYPE:
                            // Value here could be string or XmlReader
                            if (value is XmlReader)
                            {
                                value = MetaType.GetStringFromXml((XmlReader)value);
                            }
                            ccb = ((isSqlType) ? ((SqlString)value).Value.Length : ((string)value).Length) * 2;
                            break;

                        default:
//.........这里部分代码省略.........
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:TdsParser.cs

示例5: TryReadSqlValue

        internal bool TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, int length, TdsParserStateObject stateObj)
        {
            bool isPlp = md.metaType.IsPlp;
            byte tdsType = md.tdsType;

            Debug.Assert(isPlp || !IsNull(md.metaType, (ulong)length), "null value should not get here!");
            if (isPlp)
            {
                // We must read the column value completely, no matter what length is passed in
                length = Int32.MaxValue;
            }
            switch (tdsType)
            {
                case TdsEnums.SQLDECIMALN:
                case TdsEnums.SQLNUMERICN:
                    if (!TryReadSqlDecimal(value, length, md.precision, md.scale, stateObj))
                    {
                        return false;
                    }
                    break;

                case TdsEnums.SQLUDT:
                    throw SQL.UnsupportedFeatureAndToken(_connHandler, SqlDbType.Udt.ToString());
                case TdsEnums.SQLBINARY:
                case TdsEnums.SQLBIGBINARY:
                case TdsEnums.SQLBIGVARBINARY:
                case TdsEnums.SQLVARBINARY:
                case TdsEnums.SQLIMAGE:
                    byte[] b = null;

                    // If varbinary(max), we only read the first chunk here, expecting the caller to read the rest
                    if (isPlp)
                    {
                        // If we are given -1 for length, then we read the entire value,
                        // otherwise only the requested amount, usually first chunk.
                        int ignored;
                        if (!stateObj.TryReadPlpBytes(ref b, 0, length, out ignored))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        //Debug.Assert(length > 0 && length < (long)(Int32.MaxValue), "Bad length for column");
                        b = new byte[length];
                        if (!stateObj.TryReadByteArray(b, 0, length))
                        {
                            return false;
                        }
                    }

                    value.SqlBinary = new SqlBinary(b, true);   // doesn't copy the byte array

                    break;

                case TdsEnums.SQLCHAR:
                case TdsEnums.SQLBIGCHAR:
                case TdsEnums.SQLVARCHAR:
                case TdsEnums.SQLBIGVARCHAR:
                case TdsEnums.SQLTEXT:
                case TdsEnums.SQLNCHAR:
                case TdsEnums.SQLNVARCHAR:
                case TdsEnums.SQLNTEXT:
                    if (!TryReadSqlStringValue(value, tdsType, length, md.encoding, isPlp, stateObj))
                    {
                        return false;
                    }
                    break;

                case TdsEnums.SQLXMLTYPE:
                    // We store SqlCachedBuffer here, so that we can return either SqlBinary, SqlString or SqlXmlReader.
                    SqlCachedBuffer sqlBuf;
                    if (!SqlCachedBuffer.TryCreate(md, this, stateObj, out sqlBuf))
                    {
                        return false;
                    }

                    value.SqlCachedBuffer = sqlBuf;
                    break;

                case TdsEnums.SQLDATE:
                case TdsEnums.SQLTIME:
                case TdsEnums.SQLDATETIME2:
                case TdsEnums.SQLDATETIMEOFFSET:
                    if (!TryReadSqlDateTime(value, tdsType, length, md.scale, stateObj))
                    {
                        return false;
                    }
                    break;

                default:
                    Debug.Assert(!isPlp, "ReadSqlValue calling ReadSqlValueInternal with plp data");
                    if (!TryReadSqlValueInternal(value, tdsType, length, stateObj))
                    {
                        return false;
                    }
                    break;
            }

            Debug.Assert((stateObj._longlen == 0) && (stateObj._longlenleft == 0), "ReadSqlValue did not read plp field completely, longlen =" + stateObj._longlen.ToString((IFormatProvider)null) + ",longlenleft=" + stateObj._longlenleft.ToString((IFormatProvider)null));
//.........这里部分代码省略.........
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:TdsParser.cs

示例6: GetNullSqlValue

        internal object GetNullSqlValue(SqlBuffer nullVal, SqlMetaDataPriv md)
        {
            switch (md.type)
            {
                case SqlDbType.Real:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Single);
                    break;

                case SqlDbType.Float:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Double);
                    break;

                case SqlDbType.Udt:
                case SqlDbType.Binary:
                case SqlDbType.VarBinary:
                case SqlDbType.Image:
                    nullVal.SqlBinary = SqlBinary.Null;
                    break;

                case SqlDbType.UniqueIdentifier:
                    nullVal.SqlGuid = SqlGuid.Null;
                    break;

                case SqlDbType.Bit:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Boolean);
                    break;

                case SqlDbType.TinyInt:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Byte);
                    break;

                case SqlDbType.SmallInt:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Int16);
                    break;

                case SqlDbType.Int:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Int32);
                    break;

                case SqlDbType.BigInt:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Int64);
                    break;

                case SqlDbType.Char:
                case SqlDbType.VarChar:
                case SqlDbType.NChar:
                case SqlDbType.NVarChar:
                case SqlDbType.Text:
                case SqlDbType.NText:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.String);
                    break;

                case SqlDbType.Decimal:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Decimal);
                    break;

                case SqlDbType.DateTime:
                case SqlDbType.SmallDateTime:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.DateTime);
                    break;

                case SqlDbType.Money:
                case SqlDbType.SmallMoney:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Money);
                    break;

                case SqlDbType.Variant:
                    // DBNull.Value will have to work here
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Empty);
                    break;

                case SqlDbType.Xml:
                    nullVal.SqlCachedBuffer = SqlCachedBuffer.Null;
                    break;

                case SqlDbType.Date:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Date);
                    break;

                case SqlDbType.Time:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Time);
                    break;

                case SqlDbType.DateTime2:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.DateTime2);
                    break;

                case SqlDbType.DateTimeOffset:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.DateTimeOffset);
                    break;

                case SqlDbType.Timestamp:
                    break;

                default:
                    Debug.Assert(false, "unknown null sqlType!" + md.type.ToString());
                    break;
            }

            return nullVal;
//.........这里部分代码省略.........
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:TdsParser.cs

示例7: TryProcessColumnHeader

        // takes care of any per data header information:
        // for long columns, reads off textptrs, reads length, check nullability
        // for other columns, reads length, checks nullability
        // returns length and nullability
        internal bool TryProcessColumnHeader(SqlMetaDataPriv col, TdsParserStateObject stateObj, int columnOrdinal, out bool isNull, out ulong length)
        {
            // query NBC row information first
            if (stateObj.IsNullCompressionBitSet(columnOrdinal))
            {
                isNull = true;
                // column information is not present in TDS if null compression bit is set, return now
                length = 0;
                return true;
            }

            return TryProcessColumnHeaderNoNBC(col, stateObj, out isNull, out length);
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:17,代码来源:TdsParser.cs

示例8: GetNullSqlValue

        internal object GetNullSqlValue(SqlBuffer nullVal, SqlMetaDataPriv md)
        {
            switch (md.type)
            {
                case SqlDbType.BigInt:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Int64);
                    return nullVal;

                case SqlDbType.Binary:
                case SqlDbType.Image:
                case SqlDbType.VarBinary:
                case SqlDbType.Udt:
                    nullVal.SqlBinary = SqlBinary.Null;
                    return nullVal;

                case SqlDbType.Bit:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Boolean);
                    return nullVal;

                case SqlDbType.Char:
                case SqlDbType.NChar:
                case SqlDbType.NText:
                case SqlDbType.NVarChar:
                case SqlDbType.Text:
                case SqlDbType.VarChar:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.String);
                    return nullVal;

                case SqlDbType.DateTime:
                case SqlDbType.SmallDateTime:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.DateTime);
                    return nullVal;

                case SqlDbType.Decimal:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Decimal);
                    return nullVal;

                case SqlDbType.Float:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Double);
                    return nullVal;

                case SqlDbType.Int:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Int32);
                    return nullVal;

                case SqlDbType.Money:
                case SqlDbType.SmallMoney:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Money);
                    return nullVal;

                case SqlDbType.Real:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Single);
                    return nullVal;

                case SqlDbType.UniqueIdentifier:
                    nullVal.SqlGuid = SqlGuid.Null;
                    return nullVal;

                case SqlDbType.SmallInt:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Int16);
                    return nullVal;

                case SqlDbType.Timestamp:
                case (SqlDbType.SmallInt | SqlDbType.Int):
                case (SqlDbType.Text | SqlDbType.Int):
                case (SqlDbType.Xml | SqlDbType.Bit):
                case (SqlDbType.TinyInt | SqlDbType.Int):
                case SqlDbType.Structured:
                    return nullVal;

                case SqlDbType.TinyInt:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Byte);
                    return nullVal;

                case SqlDbType.Variant:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Empty);
                    return nullVal;

                case SqlDbType.Xml:
                    nullVal.SqlCachedBuffer = SqlCachedBuffer.Null;
                    return nullVal;

                case SqlDbType.Date:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Date);
                    return nullVal;

                case SqlDbType.Time:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.Time);
                    return nullVal;

                case SqlDbType.DateTime2:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.DateTime2);
                    return nullVal;

                case SqlDbType.DateTimeOffset:
                    nullVal.SetToNullOfType(SqlBuffer.StorageType.DateTimeOffset);
                    return nullVal;
            }
            return nullVal;
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:100,代码来源:TdsParser.cs

示例9: CheckGetExtendedUDTInfo

 internal static void CheckGetExtendedUDTInfo(SqlMetaDataPriv metaData, bool fThrow)
 {
     if (metaData.udtType == null)
     {
         metaData.udtType = Type.GetType(metaData.udtAssemblyQualifiedName, fThrow);
         if (fThrow && (metaData.udtType == null))
         {
             throw SQL.UDTUnexpectedResult(metaData.udtAssemblyQualifiedName);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:SqlConnection.cs

示例10: WriteBulkCopyValue

        internal void WriteBulkCopyValue(object value, SqlMetaDataPriv metadata, TdsParserStateObject stateObj)
        {
            MetaType metaType = metadata.metaType;
            ulong length = 0L;
            ulong byteCount = 0L;
            if (ADP.IsNull(value))
            {
                if (metaType.IsPlp && ((metaType.NullableType != 240) || metaType.IsLong))
                {
                    this.WriteLong(-1L, stateObj);
                }
                else if ((!metaType.IsFixed && !metaType.IsLong) && !metaType.IsVarTime)
                {
                    this.WriteShort(0xffff, stateObj);
                }
                else
                {
                    this.WriteByte(0, stateObj);
                }
            }
            else
            {
                switch (metaType.NullableType)
                {
                    case 0x22:
                    case 0xa5:
                    case 0xad:
                    case 240:
                        length = (value is byte[]) ? ((ulong) ((byte[]) value).Length) : ((ulong) ((SqlBinary) value).Length);
                        break;

                    case 0x23:
                    case 0xa7:
                    case 0xaf:
                        if (this._defaultEncoding == null)
                        {
                            this.ThrowUnsupportedCollationEncountered(null);
                        }
                        if (value is string)
                        {
                            length = (ulong) ((string) value).Length;
                            byteCount = (ulong) this._defaultEncoding.GetByteCount((string) value);
                        }
                        else
                        {
                            SqlString str4 = (SqlString) value;
                            length = (ulong) str4.Value.Length;
                            SqlString str3 = (SqlString) value;
                            byteCount = (ulong) this._defaultEncoding.GetByteCount(str3.Value);
                        }
                        break;

                    case 0x24:
                        length = 0x10L;
                        break;

                    case 0x63:
                    case 0xe7:
                    case 0xef:
                        length = (ulong) (((value is string) ? ((long) ((string) value).Length) : ((long) ((SqlString) value).Value.Length)) * 2L);
                        break;

                    case 0xf1:
                        if (value is XmlReader)
                        {
                            value = MetaType.GetStringFromXml((XmlReader) value);
                        }
                        length = (ulong) (((value is string) ? ((long) ((string) value).Length) : ((long) ((SqlString) value).Value.Length)) * 2L);
                        break;

                    default:
                        length = (ulong) metadata.length;
                        break;
                }
                if (metaType.IsLong)
                {
                    switch (metaType.SqlDbType)
                    {
                        case SqlDbType.NText:
                        case SqlDbType.Image:
                        case SqlDbType.Text:
                            this.WriteByteArray(s_longDataHeader, s_longDataHeader.Length, 0, stateObj);
                            this.WriteTokenLength(metadata.tdsType, (byteCount == 0L) ? ((int) length) : ((int) byteCount), stateObj);
                            break;

                        case SqlDbType.NVarChar:
                        case SqlDbType.VarBinary:
                        case SqlDbType.VarChar:
                        case SqlDbType.Xml:
                        case SqlDbType.Udt:
                            this.WriteUnsignedLong(18446744073709551614L, stateObj);
                            break;
                    }
                }
                else
                {
                    this.WriteTokenLength(metadata.tdsType, (byteCount == 0L) ? ((int) length) : ((int) byteCount), stateObj);
                }
                if (DataStorage.IsSqlType(value.GetType()))
                {
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:TdsParser.cs

示例11: GetDataLength

 internal ulong GetDataLength(SqlMetaDataPriv colmeta, TdsParserStateObject stateObj)
 {
     if (this._isYukon && colmeta.metaType.IsPlp)
     {
         return stateObj.ReadPlpLength(true);
     }
     return (ulong) this.GetTokenLength(colmeta.tdsType, stateObj);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:TdsParser.cs

示例12: SkipValue

 internal void SkipValue(SqlMetaDataPriv md, TdsParserStateObject stateObj)
 {
     if (md.metaType.IsPlp)
     {
         this.SkipPlpValue(ulong.MaxValue, stateObj);
     }
     else
     {
         int tokenLength = this.GetTokenLength(md.tdsType, stateObj);
         if (!this.IsNull(md.metaType, (ulong) tokenLength))
         {
             this.SkipBytes(tokenLength, stateObj);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:15,代码来源:TdsParser.cs

示例13: ReadSqlValue

        internal void ReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, int length, TdsParserStateObject stateObj)
        {
            if (md.metaType.IsPlp)
            {
                length = 0x7fffffff;
            }
            switch (md.tdsType)
            {
                case 0x22:
                case 0x25:
                case 0x2d:
                case 240:
                case 0xa5:
                case 0xad:
                {
                    byte[] buff = null;
                    if (md.metaType.IsPlp)
                    {
                        stateObj.ReadPlpBytes(ref buff, 0, length);
                    }
                    else
                    {
                        buff = new byte[length];
                        stateObj.ReadByteArray(buff, 0, length);
                    }
                    value.SqlBinary = new SqlBinary(buff, true);
                    return;
                }
                case 0x23:
                case 0x27:
                case 0x2f:
                case 0x63:
                case 0xef:
                case 0xe7:
                case 0xa7:
                case 0xaf:
                    this.ReadSqlStringValue(value, md.tdsType, length, md.encoding, md.metaType.IsPlp, stateObj);
                    return;

                case 40:
                case 0x29:
                case 0x2a:
                case 0x2b:
                    this.ReadSqlDateTime(value, md.tdsType, length, md.scale, stateObj);
                    return;

                case 0x6a:
                case 0x6c:
                    this.ReadSqlDecimal(value, length, md.precision, md.scale, stateObj);
                    return;

                case 0xf1:
                {
                    SqlCachedBuffer buffer2 = new SqlCachedBuffer(md, this, stateObj);
                    value.SqlCachedBuffer = buffer2;
                    return;
                }
            }
            this.ReadSqlValueInternal(value, md.tdsType, md.metaType.TypeId, length, stateObj);
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:60,代码来源:TdsParser.cs

示例14: ReadPlpAnsiChars

 internal int ReadPlpAnsiChars(ref char[] buff, int offst, int len, SqlMetaDataPriv metadata, TdsParserStateObject stateObj)
 {
     int num3 = 0;
     int num2 = 0;
     int num = 0;
     int num4 = 0;
     if (stateObj._longlen == 0L)
     {
         return 0;
     }
     num2 = len;
     if (stateObj._longlenleft == 0L)
     {
         stateObj.ReadPlpLength(false);
         if (stateObj._longlenleft == 0L)
         {
             return 0;
         }
     }
     Encoding encoding = metadata.encoding;
     if (encoding == null)
     {
         if (this._defaultEncoding == null)
         {
             this.ThrowUnsupportedCollationEncountered(stateObj);
         }
         encoding = this._defaultEncoding;
     }
     while (num2 > 0)
     {
         num = (int) Math.Min(stateObj._longlenleft, (ulong) num2);
         if ((stateObj._bTmp == null) || (stateObj._bTmp.Length < num))
         {
             stateObj._bTmp = new byte[num];
         }
         num = stateObj.ReadPlpBytesChunk(stateObj._bTmp, 0, num);
         num3 = encoding.GetChars(stateObj._bTmp, 0, num, buff, offst);
         num2 -= num3;
         offst += num3;
         num4 += num3;
         if (stateObj._longlenleft == 0L)
         {
             stateObj.ReadPlpLength(false);
         }
         if (stateObj._longlenleft == 0L)
         {
             return num4;
         }
     }
     return num4;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:51,代码来源:TdsParser.cs

示例15: EncryptColumnValue

        /// <summary>
        /// Encrypts a column value (for SqlBulkCopy) 
        /// </summary>
        /// <returns></returns>
        internal object EncryptColumnValue (object value, SqlMetaDataPriv metadata, string column, TdsParserStateObject stateObj, bool isDataFeed, bool isSqlType) {
            Debug.Assert (_serverSupportsColumnEncryption, "Server doesn't support encryption, yet we received encryption metadata");
            Debug.Assert (ShouldEncryptValuesForBulkCopy(), "Encryption attempted when not requested");

            if (isDataFeed) { // can't encrypt a stream column
                SQL.StreamNotSupportOnEncryptedColumn(column);
            }

            int actualLengthInBytes;
            switch(metadata.baseTI.metaType.NullableType) {
                case TdsEnums.SQLBIGBINARY:
                case TdsEnums.SQLBIGVARBINARY:
                case TdsEnums.SQLIMAGE:
                    // For some datatypes, engine does truncation before storing the value. (For example, when
                    // trying to insert a varbinary(7000) into a varbinary(3000) column). Since we encrypt the
                    // column values, engine has no way to tell the size of the plaintext datatype. Therefore,
                    // we truncate the values based on target column sizes here before encrypting them. This 
                    // truncation is only needed if we exceed the max column length or if the target column is
                    // not a blob type (eg. varbinary(max)). The actual work of truncating the column happens
                    // when we normalize and serialize the data buffers. The serialization routine expects us 
                    // to report the size of data to be copied out (for serialization). If we underreport the
                    // size, truncation will happen for us!
                    actualLengthInBytes = (isSqlType) ? ((SqlBinary)value).Length : ((byte[])value).Length;
                    if (metadata.baseTI.length > 0 &&
                        actualLengthInBytes > metadata.baseTI.length) { // see comments agove
                        actualLengthInBytes = metadata.baseTI.length;
                    }
                    break;

                case TdsEnums.SQLUNIQUEID:
                    actualLengthInBytes = GUID_SIZE;   // that's a constant for guid
                    break;
                case TdsEnums.SQLBIGCHAR:
                case TdsEnums.SQLBIGVARCHAR:
                case TdsEnums.SQLTEXT:
                    if (null == _defaultEncoding)
                    {
                        ThrowUnsupportedCollationEncountered(null); // stateObject only when reading
                    }

                    string stringValue = (isSqlType) ? ((SqlString)value).Value : (string)value;
                    actualLengthInBytes = _defaultEncoding.GetByteCount(stringValue);

                    // If the string length is > max length, then use the max length (see comments above)
                    if (metadata.baseTI.length > 0 && 
                        actualLengthInBytes > metadata.baseTI.length) {
                        actualLengthInBytes = metadata.baseTI.length; // this ensure truncation!
                    }

                    break;
                case TdsEnums.SQLNCHAR:
                case TdsEnums.SQLNVARCHAR:
                case TdsEnums.SQLNTEXT:
                    actualLengthInBytes = ((isSqlType) ? ((SqlString)value).Value.Length : ((string)value).Length) * 2;

                    if (metadata.baseTI.length > 0 &&
                        actualLengthInBytes > metadata.baseTI.length) { // see comments above
                        actualLengthInBytes = metadata.baseTI.length;
                    }

                    break;

                default:
                    actualLengthInBytes = metadata.baseTI.length;
                    break;
            }

            byte[] serializedValue;
            if (isSqlType) {
                // SqlType
                serializedValue = SerializeUnencryptedSqlValue (value, 
                                            metadata.baseTI.metaType, 
                                            actualLengthInBytes,
                                            offset : 0, 
                                            normalizationVersion: metadata.cipherMD.NormalizationRuleVersion, 
                                            stateObj: stateObj);
            }
            else {
                serializedValue = SerializeUnencryptedValue (value,
                                            metadata.baseTI.metaType, 
                                            metadata.baseTI.scale,
                                            actualLengthInBytes, 
                                            offset: 0, 
                                            isDataFeed: isDataFeed, 
                                            normalizationVersion: metadata.cipherMD.NormalizationRuleVersion, 
                                            stateObj: stateObj);
            }

            Debug.Assert(serializedValue != null, "serializedValue should not be null in TdsExecuteRPC.");
            return SqlSecurityUtility.EncryptWithKey(
                    serializedValue, 
                    metadata.cipherMD, 
                    _connHandler.ConnectionOptions.DataSource);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:98,代码来源:TdsParser.cs


注:本文中的System.Data.SqlClient.SqlMetaDataPriv类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。