internal bool Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
        {
            if ((TdsParserState.Broken == this.State) || (this.State == TdsParserState.Closed))
            {
                return true;
            }
            bool flag = false;
        Label_0016:
            if (stateObj._internalTimeout)
            {
                runBehavior = RunBehavior.Attention;
            }
            if ((TdsParserState.Broken == this.State) || (this.State == TdsParserState.Closed))
            {
                goto Label_0705;
            }
            byte token = stateObj.ReadByte();
            if ((((((token != 170) && (token != 0xab)) && ((token != 0xad) && (token != 0xe3))) && (((token != 0xac) && (token != 0x79)) && ((token != 160) && (token != 0xa1)))) && ((((token != 0x81) && (token != 0x88)) && ((token != 0xa4) && (token != 0xa5))) && (((token != 0xa9) && (token != 0xd3)) && ((token != 0xd1) && (token != 0xfd))))) && ((((token != 0xfe) && (token != 0xff)) && ((token != 0x39) && (token != 0xed))) && (((token != 0xae) && (token != 0x7c)) && ((token != 120) && (token != 0xed)))))
            {
                this._state = TdsParserState.Broken;
                this._connHandler.BreakConnection();
                Bid.Trace("<sc.TdsParser.Run|ERR> Potential multi-threaded misuse of connection, unexpected TDS token found %d#\n", this.ObjectID);
                throw SQL.ParsingError();
            }
            int tokenLength = this.GetTokenLength(token, stateObj);
            switch (token)
            {
                case 0xa4:
                    if (dataStream == null)
                    {
                        this.SkipBytes(tokenLength, stateObj);
                    }
                    else
                    {
                        dataStream.TableNames = this.ProcessTableName(tokenLength, stateObj);
                    }
                    goto Label_06D5;

                case 0xa5:
                    if (dataStream == null)
                    {
                        this.SkipBytes(tokenLength, stateObj);
                    }
                    else
                    {
                        _SqlMetaDataSet metaData = this.ProcessColInfo(dataStream.MetaData, dataStream, stateObj);
                        dataStream.SetMetaData(metaData, false);
                        dataStream.BrowseModeInfoConsumed = true;
                    }
                    goto Label_06D5;

                case 0xa9:
                    this.SkipBytes(tokenLength, stateObj);
                    goto Label_06D5;

                case 170:
                case 0xab:
                {
                    if (token == 170)
                    {
                        stateObj._errorTokenReceived = true;
                    }
                    SqlError error = this.ProcessError(token, stateObj);
                    if (RunBehavior.Clean == (RunBehavior.Clean & runBehavior))
                    {
                        if (error.Class >= 20)
                        {
                            this.Errors.Add(error);
                        }
                    }
                    else
                    {
                        SqlConnection connection = null;
                        if (this._connHandler != null)
                        {
                            connection = this._connHandler.Connection;
                        }
                        if (((connection != null) && connection.FireInfoMessageEventOnUserErrors) && (error.Class <= 0x10))
                        {
                            this.FireInfoMessageEvent(connection, stateObj, error);
                        }
                        else if (error.Class < 11)
                        {
                            this.Warnings.Add(error);
                        }
                        else if (error.Class < 20)
                        {
                            this.Errors.Add(error);
                            if ((dataStream != null) && !dataStream.IsInitialized)
                            {
                                runBehavior = RunBehavior.UntilDone;
                            }
                        }
                        else
                        {
                            this.Errors.Add(error);
                            runBehavior = RunBehavior.UntilDone;
                        }
                    }
                    goto Label_06D5;
                }
                case 0xac:
                {
                    SqlReturnValue rec = this.ProcessReturnValue(tokenLength, stateObj);
                    if (cmdHandler != null)
                    {
                        cmdHandler.OnReturnValue(rec);
                    }
                    goto Label_06D5;
                }
                case 0xad:
                {
                    SqlLoginAck ack = this.ProcessLoginAck(stateObj);
                    this._connHandler.OnLoginAck(ack);
                    goto Label_06D5;
                }
                case 0x88:
                {
                    if (stateObj._cleanupAltMetaDataSetArray == null)
                    {
                        stateObj._cleanupAltMetaDataSetArray = new _SqlMetaDataSetCollection();
                    }
                    _SqlMetaDataSet altMetaDataSet = this.ProcessAltMetaData(tokenLength, stateObj);
                    stateObj._cleanupAltMetaDataSetArray.SetAltMetaData(altMetaDataSet);
                    if (dataStream != null)
                    {
                        dataStream.SetAltMetaDataSet(altMetaDataSet, 0x88 != stateObj.PeekByte());
                    }
                    goto Label_06D5;
                }
                case 0x79:
                {
                    int status = stateObj.ReadInt32();
                    if (cmdHandler != null)
                    {
                        cmdHandler.OnReturnStatus(status);
                    }
                    goto Label_06D5;
                }
                case 0x81:
                    if (tokenLength != 0xffff)
                    {
                        stateObj._cleanupMetaData = this.ProcessMetaData(tokenLength, stateObj);
                    }
                    else if (cmdHandler != null)
                    {
                        stateObj._cleanupMetaData = cmdHandler.MetaData;
                    }
                    if (dataStream != null)
                    {
                        byte num5 = stateObj.PeekByte();
                        dataStream.SetMetaData(stateObj._cleanupMetaData, (0xa4 == num5) || (0xa5 == num5));
                    }
                    else if (bulkCopyHandler != null)
                    {
                        bulkCopyHandler.SetMetaData(stateObj._cleanupMetaData);
                    }
                    goto Label_06D5;

                case 0xd1:
                    if (bulkCopyHandler == null)
                    {
                        if (RunBehavior.ReturnImmediately != (RunBehavior.ReturnImmediately & runBehavior))
                        {
                            this.SkipRow(stateObj._cleanupMetaData, stateObj);
                        }
                        break;
                    }
                    this.ProcessRow(stateObj._cleanupMetaData, bulkCopyHandler.CreateRowBuffer(), bulkCopyHandler.CreateIndexMap(), stateObj);
                    break;

                case 0xd3:
                    if (RunBehavior.ReturnImmediately != (RunBehavior.ReturnImmediately & runBehavior))
                    {
                        int id = stateObj.ReadUInt16();
                        this.SkipRow(stateObj._cleanupAltMetaDataSetArray.GetAltMetaData(id), stateObj);
                    }
                    flag = true;
                    goto Label_06D5;

                case 0xe3:
                {
                    SqlEnvChange[] changeArray = this.ProcessEnvChange(tokenLength, stateObj);
                    for (int i = 0; i < changeArray.Length; i++)
                    {
                        if ((changeArray[i] == null) || this.Connection.IgnoreEnvChange)
                        {
                            continue;
                        }
                        switch (changeArray[i].type)
                        {
                            case 8:
                            case 11:
                                this._currentTransaction = this._pendingTransaction;
                                this._pendingTransaction = null;
                                if (this._currentTransaction == null)
                                {
                                    break;
                                }
                                this._currentTransaction.TransactionId = changeArray[i].newLongValue;
                                goto Label_04B4;

                            case 9:
                            case 12:
                            case 0x11:
                                this._retainedTransactionId = 0L;
                                goto Label_04F7;

                            case 10:
                                goto Label_04F7;

                            default:
                                goto Label_0577;
                        }
                        TransactionType type = (8 == changeArray[i].type) ? TransactionType.LocalFromTSQL : TransactionType.Distributed;
                        this._currentTransaction = new SqlInternalTransaction(this._connHandler, type, null, changeArray[i].newLongValue);
                    Label_04B4:
                        if ((this._statistics != null) && !this._statisticsIsInTransaction)
                        {
                            this._statistics.SafeIncrement(ref this._statistics._transactions);
                        }
                        this._statisticsIsInTransaction = true;
                        this._retainedTransactionId = 0L;
                        continue;
                    Label_04F7:
                        if (this._currentTransaction != null)
                        {
                            if (9 == changeArray[i].type)
                            {
                                this._currentTransaction.Completed(TransactionState.Committed);
                            }
                            else if (10 == changeArray[i].type)
                            {
                                if (this._currentTransaction.IsDistributed && this._currentTransaction.IsActive)
                                {
                                    this._retainedTransactionId = changeArray[i].oldLongValue;
                                }
                                this._currentTransaction.Completed(TransactionState.Aborted);
                            }
                            else
                            {
                                this._currentTransaction.Completed(TransactionState.Unknown);
                            }
                            this._currentTransaction = null;
                        }
                        this._statisticsIsInTransaction = false;
                        continue;
                    Label_0577:
                        this._connHandler.OnEnvChange(changeArray[i]);
                    }
                    goto Label_06D5;
                }
                case 0xfd:
                case 0xfe:
                case 0xff:
                    this.ProcessDone(cmdHandler, dataStream, ref runBehavior, stateObj);
                    if ((token == 0xfe) && (cmdHandler != null))
                    {
                        cmdHandler.OnDoneProc();
                    }
                    goto Label_06D5;

                case 0xed:
                    this.ProcessSSPI(tokenLength);
                    goto Label_06D5;

                default:
                    goto Label_06D5;
            }
            if (this._statistics != null)
            {
                this._statistics.WaitForDoneAfterRow = true;
            }
            flag = true;
        Label_06D5:
            if ((stateObj._pendingData && (RunBehavior.ReturnImmediately != (RunBehavior.ReturnImmediately & runBehavior))) || ((!stateObj._pendingData && stateObj._attentionSent) && !stateObj._attentionReceived))
            {
                goto Label_0016;
            }
        Label_0705:
            if (!stateObj._pendingData && (this.CurrentTransaction != null))
            {
                this.CurrentTransaction.Activate();
            }
            if (stateObj._attentionSent && stateObj._attentionReceived)
            {
                stateObj._attentionSent = false;
                stateObj._attentionReceived = false;
                if ((RunBehavior.Clean != (RunBehavior.Clean & runBehavior)) && !stateObj._internalTimeout)
                {
                    this.Errors.Add(new SqlError(0, 0, 11, this._server, SQLMessage.OperationCancelled(), "", 0));
                }
            }
            if ((this._errors != null) || (this._warnings != null))
            {
                this.ThrowExceptionAndWarning();
            }
            return flag;
        }
 internal int GetAltRowId(TdsParserStateObject stateObj)
 {
     stateObj.ReadByte();
     return stateObj.ReadUInt16();
 }
        internal void ReadSqlValueInternal(SqlBuffer value, byte tdsType, int typeId, int length, TdsParserStateObject stateObj)
        {
            int num4;
            switch (tdsType)
            {
                case 0x7f:
                    goto Label_011A;

                case 0xa5:
                case 0xad:
                case 0x22:
                case 0x25:
                case 0x2d:
                {
                    byte[] buff = new byte[length];
                    stateObj.ReadByteArray(buff, 0, length);
                    value.SqlBinary = new SqlBinary(buff, true);
                    return;
                }
                case 0x6d:
                    if (length != 4)
                    {
                        goto Label_013B;
                    }
                    goto Label_012D;

                case 110:
                    if (length == 4)
                    {
                        goto Label_0173;
                    }
                    goto Label_014E;

                case 0x6f:
                    if (length != 4)
                    {
                        goto Label_01A2;
                    }
                    goto Label_0187;

                case 0x7a:
                    goto Label_0173;

                case 0x62:
                    this.ReadSqlVariant(value, length, stateObj);
                    return;

                case 0x68:
                case 50:
                    value.Boolean = stateObj.ReadByte() != 0;
                    return;

                case 0x23:
                case 0x2e:
                case 0x2f:
                case 0x31:
                case 0x33:
                case 0x35:
                case 0x36:
                case 0x37:
                case 0x39:
                    return;

                case 0x24:
                {
                    byte[] buffer2 = new byte[length];
                    stateObj.ReadByteArray(buffer2, 0, length);
                    value.SqlGuid = new SqlGuid(buffer2, true);
                    return;
                }
                case 0x26:
                    if (length == 1)
                    {
                        break;
                    }
                    if (length == 2)
                    {
                        goto Label_00FE;
                    }
                    if (length != 4)
                    {
                        goto Label_011A;
                    }
                    goto Label_010C;

                case 0x30:
                    break;

                case 0x34:
                    goto Label_00FE;

                case 0x38:
                    goto Label_010C;

                case 0x3a:
                    goto Label_0187;

                case 0x3b:
                    goto Label_012D;

                case 60:
                    goto Label_014E;

                case 0x3d:
                    goto Label_01A2;

                case 0x3e:
                    goto Label_013B;

                default:
                    return;
            }
            value.Byte = stateObj.ReadByte();
            return;
        Label_00FE:
            value.Int16 = stateObj.ReadInt16();
            return;
        Label_010C:
            value.Int32 = stateObj.ReadInt32();
            return;
        Label_011A:
            value.Int64 = stateObj.ReadInt64();
            return;
        Label_012D:
            value.Single = stateObj.ReadSingle();
            return;
        Label_013B:
            value.Double = stateObj.ReadDouble();
            return;
        Label_014E:
            num4 = stateObj.ReadInt32();
            uint num3 = stateObj.ReadUInt32();
            long num2 = (num4 << 0x20) + num3;
            value.SetToMoney(num2);
            return;
        Label_0173:
            value.SetToMoney((long) stateObj.ReadInt32());
            return;
        Label_0187:
            value.SetToDateTime(stateObj.ReadUInt16(), stateObj.ReadUInt16() * SqlDateTime.SQLTicksPerMinute);
            return;
        Label_01A2:
            value.SetToDateTime(stateObj.ReadInt32(), (int) stateObj.ReadUInt32());
        }
        internal void ReadSqlVariant(SqlBuffer value, int lenTotal, TdsParserStateObject stateObj)
        {
            byte tdsType = stateObj.ReadByte();
            byte num2 = stateObj.ReadByte();
            byte propBytes = MetaType.GetSqlDataType(tdsType, 0, 0).PropBytes;
            int num9 = 2 + num2;
            int length = lenTotal - num9;
            switch (tdsType)
            {
                case 0xe7:
                case 0xef:
                case 0xa7:
                case 0xaf:
                    this.ProcessCollation(stateObj);
                    stateObj.ReadUInt16();
                    if (num2 > propBytes)
                    {
                        this.SkipBytes(num2 - propBytes, stateObj);
                    }
                    this.ReadSqlStringValue(value, tdsType, length, null, false, stateObj);
                    return;

                case 0xa5:
                case 0xad:
                    stateObj.ReadUInt16();
                    if (num2 > propBytes)
                    {
                        this.SkipBytes(num2 - propBytes, stateObj);
                    }
                    break;

                case 0xa6:
                case 0xae:
                case 0x25:
                case 0x26:
                case 0x27:
                case 0x2c:
                case 0x2d:
                case 0x2e:
                case 0x2f:
                case 0x31:
                case 0x33:
                case 0x35:
                case 0x36:
                case 0x37:
                case 0x39:
                case 0x6b:
                    return;

                case 0x7a:
                case 0x7f:
                case 0x24:
                case 0x30:
                case 50:
                case 0x34:
                case 0x38:
                case 0x3a:
                case 0x3b:
                case 60:
                case 0x3d:
                case 0x3e:
                    break;

                case 40:
                    this.ReadSqlDateTime(value, tdsType, length, 0, stateObj);
                    return;

                case 0x29:
                case 0x2a:
                case 0x2b:
                {
                    byte scale = stateObj.ReadByte();
                    if (num2 > propBytes)
                    {
                        this.SkipBytes(num2 - propBytes, stateObj);
                    }
                    this.ReadSqlDateTime(value, tdsType, length, scale, stateObj);
                    return;
                }
                case 0x6a:
                case 0x6c:
                {
                    byte precision = stateObj.ReadByte();
                    byte num7 = stateObj.ReadByte();
                    if (num2 > propBytes)
                    {
                        this.SkipBytes(num2 - propBytes, stateObj);
                    }
                    this.ReadSqlDecimal(value, 0x11, precision, num7, stateObj);
                    return;
                }
                default:
                    return;
            }
            this.ReadSqlValueInternal(value, tdsType, 0, length, stateObj);
        }
        private void CommonProcessMetaData(TdsParserStateObject stateObj, _SqlMetaData col)
        {
            uint num5;
            int length = 0;
            if (this.IsYukonOrNewer)
            {
                num5 = stateObj.ReadUInt32();
            }
            else
            {
                num5 = stateObj.ReadUInt16();
            }
            byte num3 = stateObj.ReadByte();
            col.updatability = (byte) ((num3 & 11) >> 2);
            col.isNullable = 1 == (num3 & 1);
            col.isIdentity = 0x10 == (num3 & 0x10);
            stateObj.ReadByte();
            col.isColumnSet = 4 == (num3 & 4);
            byte tdsType = stateObj.ReadByte();
            if (tdsType == 0xf1)
            {
                col.length = 0xffff;
            }
            else if (this.IsVarTimeTds(tdsType))
            {
                col.length = 0;
            }
            else if (tdsType == 40)
            {
                col.length = 3;
            }
            else
            {
                col.length = this.GetTokenLength(tdsType, stateObj);
            }
            col.metaType = MetaType.GetSqlDataType(tdsType, num5, col.length);
            col.type = col.metaType.SqlDbType;
            if (this._isShiloh)
            {
                col.tdsType = col.isNullable ? col.metaType.NullableType : col.metaType.TDSType;
            }
            else
            {
                col.tdsType = tdsType;
            }
            if (this._isYukon)
            {
                if (240 == tdsType)
                {
                    this.ProcessUDTMetaData(col, stateObj);
                }
                if (col.length == 0xffff)
                {
                    col.metaType = MetaType.GetMaxMetaTypeFromMetaType(col.metaType);
                    col.length = 0x7fffffff;
                    if ((tdsType == 0xf1) && ((stateObj.ReadByte() & 1) != 0))
                    {
                        length = stateObj.ReadByte();
                        if (length != 0)
                        {
                            col.xmlSchemaCollectionDatabase = stateObj.ReadString(length);
                        }
                        length = stateObj.ReadByte();
                        if (length != 0)
                        {
                            col.xmlSchemaCollectionOwningSchema = stateObj.ReadString(length);
                        }
                        length = stateObj.ReadInt16();
                        if (length != 0)
                        {
                            col.xmlSchemaCollectionName = stateObj.ReadString(length);
                        }
                    }
                }
            }
            if (col.type == SqlDbType.Decimal)
            {
                col.precision = stateObj.ReadByte();
                col.scale = stateObj.ReadByte();
            }
            if (col.metaType.IsVarTime)
            {
                col.scale = stateObj.ReadByte();
                switch (col.metaType.SqlDbType)
                {
                    case SqlDbType.Time:
                        col.length = MetaType.GetTimeSizeFromScale(col.scale);
                        break;

                    case SqlDbType.DateTime2:
                        col.length = 3 + MetaType.GetTimeSizeFromScale(col.scale);
                        break;

                    case SqlDbType.DateTimeOffset:
                        col.length = 5 + MetaType.GetTimeSizeFromScale(col.scale);
                        break;
                }
            }
            if ((this._isShiloh && col.metaType.IsCharType) && (tdsType != 0xf1))
            {
                col.collation = this.ProcessCollation(stateObj);
                int codePage = this.GetCodePage(col.collation, stateObj);
                if (codePage == this._defaultCodePage)
                {
                    col.codePage = this._defaultCodePage;
                    col.encoding = this._defaultEncoding;
                }
                else
                {
                    col.codePage = codePage;
                    col.encoding = Encoding.GetEncoding(col.codePage);
                }
            }
            if (col.metaType.IsLong && !col.metaType.IsPlp)
            {
                if (this._isYukon)
                {
                    int num7 = 0xffff;
                    col.multiPartTableName = this.ProcessOneTable(stateObj, ref num7);
                }
                else
                {
                    length = stateObj.ReadUInt16();
                    string multipartName = stateObj.ReadString(length);
                    col.multiPartTableName = new MultiPartTableName(multipartName);
                }
            }
            length = stateObj.ReadByte();
            col.column = stateObj.ReadString(length);
            stateObj._receivedColMetaData = true;
        }
 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);
     }
 }
        private MultiPartTableName ProcessOneTable(TdsParserStateObject stateObj, ref int length)
        {
            ushort num;
            if (this._isShilohSP1)
            {
                MultiPartTableName name = new MultiPartTableName();
                byte num2 = stateObj.ReadByte();
                length--;
                switch (num2)
                {
                    case 4:
                        num = stateObj.ReadUInt16();
                        length -= 2;
                        name.ServerName = stateObj.ReadString(num);
                        num2 = (byte) (num2 - 1);
                        length -= num * 2;
                        break;

                    case 3:
                        num = stateObj.ReadUInt16();
                        length -= 2;
                        name.CatalogName = stateObj.ReadString(num);
                        length -= num * 2;
                        num2 = (byte) (num2 - 1);
                        break;

                    case 2:
                        num = stateObj.ReadUInt16();
                        length -= 2;
                        name.SchemaName = stateObj.ReadString(num);
                        length -= num * 2;
                        num2 = (byte) (num2 - 1);
                        break;

                    case 1:
                        num = stateObj.ReadUInt16();
                        length -= 2;
                        name.TableName = stateObj.ReadString(num);
                        length -= num * 2;
                        num2 = (byte) (num2 - 1);
                        break;
                }
                return name;
            }
            num = stateObj.ReadUInt16();
            length -= 2;
            string str = stateObj.ReadString(num);
            length -= num * 2;
            return new MultiPartTableName(MultipartIdentifier.ParseMultipartIdentifier(str, "[\"", "]\"", "SQL_TDSParserTableName", false));
        }
 internal SqlReturnValue ProcessReturnValue(int length, TdsParserStateObject stateObj)
 {
     int tokenLength;
     uint num8;
     SqlReturnValue metaData = new SqlReturnValue {
         length = length
     };
     if (this._isYukon)
     {
         metaData.parmIndex = stateObj.ReadUInt16();
     }
     byte num2 = stateObj.ReadByte();
     if (num2 > 0)
     {
         metaData.parameter = stateObj.ReadString(num2);
     }
     stateObj.ReadByte();
     if (this.IsYukonOrNewer)
     {
         num8 = stateObj.ReadUInt32();
     }
     else
     {
         num8 = stateObj.ReadUInt16();
     }
     stateObj.ReadUInt16();
     byte tdsType = stateObj.ReadByte();
     if (tdsType == 0xf1)
     {
         tokenLength = 0xffff;
     }
     else if (this.IsVarTimeTds(tdsType))
     {
         tokenLength = 0;
     }
     else if (tdsType == 40)
     {
         tokenLength = 3;
     }
     else
     {
         tokenLength = this.GetTokenLength(tdsType, stateObj);
     }
     metaData.metaType = MetaType.GetSqlDataType(tdsType, num8, tokenLength);
     metaData.type = metaData.metaType.SqlDbType;
     if (this._isShiloh)
     {
         metaData.tdsType = metaData.metaType.NullableType;
         metaData.isNullable = true;
         if (tokenLength == 0xffff)
         {
             metaData.metaType = MetaType.GetMaxMetaTypeFromMetaType(metaData.metaType);
         }
     }
     else
     {
         if (metaData.metaType.NullableType == tdsType)
         {
             metaData.isNullable = true;
         }
         metaData.tdsType = tdsType;
     }
     if (metaData.type == SqlDbType.Decimal)
     {
         metaData.precision = stateObj.ReadByte();
         metaData.scale = stateObj.ReadByte();
     }
     if (metaData.metaType.IsVarTime)
     {
         metaData.scale = stateObj.ReadByte();
     }
     if (tdsType == 240)
     {
         this.ProcessUDTMetaData(metaData, stateObj);
     }
     if (metaData.type == SqlDbType.Xml)
     {
         if ((stateObj.ReadByte() & 1) != 0)
         {
             num2 = stateObj.ReadByte();
             if (num2 != 0)
             {
                 metaData.xmlSchemaCollectionDatabase = stateObj.ReadString(num2);
             }
             num2 = stateObj.ReadByte();
             if (num2 != 0)
             {
                 metaData.xmlSchemaCollectionOwningSchema = stateObj.ReadString(num2);
             }
             short num7 = stateObj.ReadInt16();
             if (num7 != 0)
             {
                 metaData.xmlSchemaCollectionName = stateObj.ReadString(num7);
             }
         }
     }
     else if (this._isShiloh && metaData.metaType.IsCharType)
     {
         metaData.collation = this.ProcessCollation(stateObj);
         int codePage = this.GetCodePage(metaData.collation, stateObj);
         if (codePage == this._defaultCodePage)
         {
             metaData.codePage = this._defaultCodePage;
             metaData.encoding = this._defaultEncoding;
         }
         else
         {
             metaData.codePage = codePage;
             metaData.encoding = Encoding.GetEncoding(metaData.codePage);
         }
     }
     bool isNull = false;
     ulong num5 = this.ProcessColumnHeader(metaData, stateObj, out isNull);
     int num4 = (num5 > 0x7fffffffL) ? 0x7fffffff : ((int) num5);
     if (metaData.metaType.IsPlp)
     {
         num4 = 0x7fffffff;
     }
     if (isNull)
     {
         this.GetNullSqlValue(metaData.value, metaData);
         return metaData;
     }
     this.ReadSqlValue(metaData.value, metaData, num4, stateObj);
     return metaData;
 }
 internal SqlError ProcessError(byte token, TdsParserStateObject stateObj)
 {
     int num2;
     int infoNumber = stateObj.ReadInt32();
     byte errorState = stateObj.ReadByte();
     byte errorClass = stateObj.ReadByte();
     int length = stateObj.ReadUInt16();
     string errorMessage = stateObj.ReadString(length);
     length = stateObj.ReadByte();
     if (length != 0)
     {
         stateObj.ReadString(length);
     }
     length = stateObj.ReadByte();
     string procedure = stateObj.ReadString(length);
     if (this._isYukon)
     {
         num2 = stateObj.ReadInt32();
     }
     else
     {
         num2 = stateObj.ReadUInt16();
         if ((this._state == TdsParserState.OpenNotLoggedIn) && (stateObj.PeekByte() == 0))
         {
             num2 = (num2 << 0x10) + stateObj.ReadUInt16();
         }
     }
     return new SqlError(infoNumber, errorState, errorClass, this._server, errorMessage, procedure, num2);
 }
        private SqlEnvChange[] ProcessEnvChange(int tokenLength, TdsParserStateObject stateObj)
        {
            int num4 = 0;
            int index = 0;
            SqlEnvChange[] changeArray = new SqlEnvChange[3];
            while (tokenLength > num4)
            {
                int num3;
                ushort num5;
                if (index >= changeArray.Length)
                {
                    SqlEnvChange[] changeArray2 = new SqlEnvChange[changeArray.Length + 3];
                    for (int i = 0; i < changeArray.Length; i++)
                    {
                        changeArray2[i] = changeArray[i];
                    }
                    changeArray = changeArray2;
                }
                SqlEnvChange env = new SqlEnvChange {
                    type = stateObj.ReadByte()
                };
                changeArray[index] = env;
                index++;
                switch (env.type)
                {
                    case 1:
                    case 2:
                        this.ReadTwoStringFields(env, stateObj);
                        goto Label_03E0;

                    case 3:
                        this.ReadTwoStringFields(env, stateObj);
                        if (!(env.newValue == "iso_1"))
                        {
                            break;
                        }
                        this._defaultCodePage = 0x4e4;
                        this._defaultEncoding = Encoding.GetEncoding(this._defaultCodePage);
                        goto Label_03E0;

                    case 4:
                    {
                        this.ReadTwoStringFields(env, stateObj);
                        int size = int.Parse(env.newValue, NumberStyles.Integer, CultureInfo.InvariantCulture);
                        if (this._physicalStateObj.SetPacketSize(size))
                        {
                            this._physicalStateObj._sniPacket.Dispose();
                            uint qInfo = (uint) size;
                            SNINativeMethodWrapper.SNISetInfo(this._physicalStateObj.Handle, SNINativeMethodWrapper.QTypes.SNI_QUERY_CONN_BUFSIZE, ref qInfo);
                            this._physicalStateObj._sniPacket = new SNIPacket(this._physicalStateObj.Handle);
                        }
                        goto Label_03E0;
                    }
                    case 5:
                        this.ReadTwoStringFields(env, stateObj);
                        this._defaultLCID = int.Parse(env.newValue, NumberStyles.Integer, CultureInfo.InvariantCulture);
                        goto Label_03E0;

                    case 6:
                        this.ReadTwoStringFields(env, stateObj);
                        goto Label_03E0;

                    case 7:
                        env.newLength = stateObj.ReadByte();
                        if (env.newLength == 5)
                        {
                            env.newCollation = this.ProcessCollation(stateObj);
                            this._defaultCollation = env.newCollation;
                            int codePage = this.GetCodePage(env.newCollation, stateObj);
                            if (codePage != this._defaultCodePage)
                            {
                                this._defaultCodePage = codePage;
                                this._defaultEncoding = Encoding.GetEncoding(this._defaultCodePage);
                            }
                            this._defaultLCID = env.newCollation.LCID;
                        }
                        env.oldLength = stateObj.ReadByte();
                        if (env.oldLength == 5)
                        {
                            env.oldCollation = this.ProcessCollation(stateObj);
                        }
                        env.length = (3 + env.newLength) + env.oldLength;
                        goto Label_03E0;

                    case 8:
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 0x11:
                        env.newLength = stateObj.ReadByte();
                        if (env.newLength <= 0)
                        {
                            goto Label_02B0;
                        }
                        env.newLongValue = stateObj.ReadInt64();
                        goto Label_02B8;

                    case 13:
                        this.ReadTwoStringFields(env, stateObj);
                        goto Label_03E0;

                    case 15:
                        env.newLength = stateObj.ReadInt32();
                        env.newBinValue = new byte[env.newLength];
                        stateObj.ReadByteArray(env.newBinValue, 0, env.newLength);
                        env.oldLength = stateObj.ReadByte();
                        env.length = 5 + env.newLength;
                        goto Label_03E0;

                    case 0x10:
                    case 0x12:
                        this.ReadTwoBinaryFields(env, stateObj);
                        goto Label_03E0;

                    case 0x13:
                        this.ReadTwoStringFields(env, stateObj);
                        goto Label_03E0;

                    case 20:
                    {
                        env.newLength = stateObj.ReadUInt16();
                        byte protocol = stateObj.ReadByte();
                        ushort port = stateObj.ReadUInt16();
                        ushort length = stateObj.ReadUInt16();
                        string servername = stateObj.ReadString(length);
                        env.newRoutingInfo = new RoutingInfo(protocol, port, servername);
                        num5 = stateObj.ReadUInt16();
                        num3 = 0;
                        goto Label_03C9;
                    }
                    default:
                        goto Label_03E0;
                }
                string s = env.newValue.Substring(2);
                this._defaultCodePage = int.Parse(s, NumberStyles.Integer, CultureInfo.InvariantCulture);
                this._defaultEncoding = Encoding.GetEncoding(this._defaultCodePage);
                goto Label_03E0;
            Label_02B0:
                env.newLongValue = 0L;
            Label_02B8:
                env.oldLength = stateObj.ReadByte();
                if (env.oldLength > 0)
                {
                    env.oldLongValue = stateObj.ReadInt64();
                }
                else
                {
                    env.oldLongValue = 0L;
                }
                env.length = (3 + env.newLength) + env.oldLength;
                goto Label_03E0;
            Label_03BC:
                stateObj.ReadByte();
                num3++;
            Label_03C9:
                if (num3 < num5)
                {
                    goto Label_03BC;
                }
                env.length = (env.newLength + num5) + 5;
            Label_03E0:
                num4 += env.length;
            }
            return changeArray;
        }
 private void ProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavior run, TdsParserStateObject stateObj)
 {
     int num2;
     ushort status = stateObj.ReadUInt16();
     ushort curCmd = stateObj.ReadUInt16();
     if (this._isYukon)
     {
         num2 = (int) stateObj.ReadInt64();
     }
     else
     {
         num2 = stateObj.ReadInt32();
         if (((this._state == TdsParserState.OpenNotLoggedIn) && (stateObj._inBytesRead > stateObj._inBytesUsed)) && (stateObj.PeekByte() == 0))
         {
             num2 = stateObj.ReadInt32();
         }
     }
     if (0x20 == (status & 0x20))
     {
         stateObj._attentionReceived = true;
     }
     if ((cmd != null) && (0x10 == (status & 0x10)))
     {
         if (curCmd != 0xc1)
         {
             cmd.InternalRecordsAffected = num2;
         }
         if (stateObj._receivedColMetaData || (curCmd != 0xc1))
         {
             cmd.OnStatementCompleted(num2);
         }
     }
     stateObj._receivedColMetaData = false;
     if (((2 == (2 & status)) && (this._errors == null)) && (!stateObj._errorTokenReceived && (RunBehavior.Clean != (RunBehavior.Clean & run))))
     {
         this.Errors.Add(new SqlError(0, 0, 11, this._server, SQLMessage.SevereError(), "", 0));
         if ((reader != null) && !reader.IsInitialized)
         {
             run = RunBehavior.UntilDone;
         }
     }
     if ((0x100 == (0x100 & status)) && (RunBehavior.Clean != (RunBehavior.Clean & run)))
     {
         this.Errors.Add(new SqlError(0, 0, 20, this._server, SQLMessage.SevereError(), "", 0));
         if ((reader != null) && !reader.IsInitialized)
         {
             run = RunBehavior.UntilDone;
         }
     }
     this.ProcessSqlStatistics(curCmd, status, num2);
     if (1 != (status & 1))
     {
         stateObj._errorTokenReceived = false;
         if (stateObj._inBytesUsed >= stateObj._inBytesRead)
         {
             stateObj._pendingData = false;
         }
     }
     if (!stateObj._pendingData && stateObj._hasOpenResult)
     {
         stateObj.DecrementOpenResultCount();
     }
 }
        internal _SqlMetaDataSet ProcessAltMetaData(int cColumns, TdsParserStateObject stateObj)
        {
            _SqlMetaDataSet set = new _SqlMetaDataSet(cColumns);
            int[] numArray = new int[cColumns];
            set.id = stateObj.ReadUInt16();
            for (int i = stateObj.ReadByte(); i > 0; i--)
            {
                this.SkipBytes(2, stateObj);
            }
            for (int j = 0; j < cColumns; j++)
            {
                _SqlMetaData col = set[j];
                col.op = stateObj.ReadByte();
                col.operand = stateObj.ReadUInt16();
                this.CommonProcessMetaData(stateObj, col);
                if (ADP.IsEmpty(col.column))
                {
                    switch (col.op)
                    {
                        case 0x30:
                            col.column = "stdev";
                            break;

                        case 0x31:
                            col.column = "stdevp";
                            break;

                        case 50:
                            col.column = "var";
                            break;

                        case 0x33:
                            col.column = "varp";
                            break;

                        case 9:
                            goto Label_00FA;

                        case 0x4b:
                            col.column = "cnt";
                            break;

                        case 0x4d:
                            col.column = "sum";
                            break;

                        case 0x4f:
                            col.column = "avg";
                            break;

                        case 0x51:
                            col.column = "min";
                            break;

                        case 0x52:
                            col.column = "max";
                            break;

                        case 0x53:
                            col.column = "any";
                            break;

                        case 0x56:
                            col.column = "noop";
                            break;
                    }
                }
                goto Label_017A;
            Label_00FA:
                col.column = "cntb";
            Label_017A:
                numArray[j] = j;
            }
            set.indexMap = numArray;
            set.visibleColumns = cColumns;
            return set;
        }
        internal int GetTokenLength(byte token, TdsParserStateObject stateObj)
        {
            if (this._isYukon)
            {
                if (token == 240)
                {
                    return -1;
                }
                if (token == 0xac)
                {
                    return -1;
                }
                if (token == 0xf1)
                {
                    return stateObj.ReadUInt16();
                }
            }
            switch ((token & 0x30))
            {
                case 0x20:
                case 0:
                    if ((token & 0x80) != 0)
                    {
                        return stateObj.ReadUInt16();
                    }
                    if ((token & 12) == 0)
                    {
                        return stateObj.ReadInt32();
                    }
                    return stateObj.ReadByte();

                case 0x30:
                    return ((((int) 1) << ((token & 12) >> 2)) & 0xff);

                case 0x10:
                    return 0;
            }
            return 0;
        }