示例#1
0
        public static void SaveNbcBitmap(this TdsPackageReader reader)
        {
            var bitmap = reader.CurrentRow.NbcBitmap;

            reader.GetBytes(bitmap, bitmap.Length);
            reader.CurrentRow.IsNbcRow = true;
        }
示例#2
0
        public static SqlServerInfo LoginAck(this TdsPackageReader reader)
        {
            var sqlServerInfo = new SqlServerInfo();

            // read past interface type and version
            reader.ReadByte();

            var b          = reader.GetBytes(TdsEnums.VERSION_SIZE);
            var tdsVersion = (uint)((((((b[0] << 8) | b[1]) << 8) | b[2]) << 8) | b[3]); // bytes are in motorola order (high byte first)
            var majorMinor = tdsVersion & 0xff00ffff;
            var increment  = (tdsVersion >> 16) & 0xff;

            // Server responds:
            // 0x07000000 -> Sphinx         // Notice server response format is different for bwd compat
            // 0x07010000 -> Shiloh RTM     // Notice server response format is different for bwd compat
            // 0x71000001 -> Shiloh SP1
            // 0x72090002 -> Yukon RTM
            // 0x730B0003 -> Katmai RTM
            // 0x74000004 -> DENALI RTM
            // information provided by S. Ashwin

            switch (majorMinor)
            {
            case (TdsEnums.YUKON_MAJOR << 24) | TdsEnums.YUKON_RTM_MINOR when increment == TdsEnums.YUKON_INCREMENT:
                sqlServerInfo.IsYukon = true;
                break;

            case (TdsEnums.KATMAI_MAJOR << 24) | TdsEnums.KATMAI_MINOR when increment == TdsEnums.KATMAI_INCREMENT:
                sqlServerInfo.IsYukon         = true;
                sqlServerInfo.IsKatmaiOrNewer = true;
                break;

            case (TdsEnums.DENALI_MAJOR << 24) | TdsEnums.DENALI_MINOR when increment == TdsEnums.DENALI_INCREMENT:
                sqlServerInfo.IsYukon         = true;
                sqlServerInfo.IsKatmaiOrNewer = true;
                sqlServerInfo.IsDenali        = true;
                break;

            default:
                throw SQL.InvalidTdsVersion();
            }
            //isYukon is always true otherwise we send an exception

            var len = reader.ReadByte();

            sqlServerInfo.Name         = reader.ReadUnicodeChars(len * 2);
            sqlServerInfo.MajorVersion = reader.ReadByte();
            sqlServerInfo.MinorVersion = reader.ReadByte();
            sqlServerInfo.BuildNum     = (short)((reader.ReadByte() << 8) + reader.ReadByte());
            return(sqlServerInfo);
        }
示例#3
0
        // read feature ID
        public static void FeatureExtAck(this TdsPackageReader reader)
        {
            while (true)
            {
                var featureId = reader.ReadByte();

                if (featureId == TdsEnums.FEATUREEXT_TERMINATOR)
                {
                    break;
                }
                var dataLen = reader.ReadUInt32();
                var data    = reader.GetBytes(checked ((int)dataLen));
                if (dataLen > 0)
                {
                    OnFeatureExtAck(featureId, data);
                }
            }
        }
        public static void ParseSessionState(this TdsPackageReader reader, int length)
        {
            var sdata = reader.CurrentSession.CurrentSessionData;

            if (length < 5)
            {
                throw SQL.ParsingError();
            }
            var seqNum = reader.ReadUInt32();

            if (seqNum == uint.MaxValue)
            {
                reader.CurrentSession.DoNotPoolThisConnection = true;
            }
            var status = reader.ReadByte();

            if (status > 1)
            {
                throw SQL.ParsingError();
            }
            var recoverable = status != 0;

            length -= 5;

            while (length > 0)
            {
                var stateId      = reader.ReadByte();
                var stateLenByte = reader.ReadByte();
                var stateLen     = stateLenByte < 0xFF
                    ? stateLenByte
                    : reader.ReadInt32();

                byte[] buffer = null;
                lock (sdata.Delta)
                {
                    if (sdata.Delta[stateId] == null)
                    {
                        buffer = new byte[stateLen];
                        sdata.Delta[stateId] = new SessionStateRecord {
                            Version = seqNum, DataLength = stateLen, Data = buffer, Recoverable = recoverable
                        };
                        sdata.DeltaDirty = true;
                        if (!recoverable)
                        {
                            checked
                            {
                                sdata.UnrecoverableStatesCount++;
                            }
                        }
                    }
                    else
                    {
                        if (sdata.Delta[stateId].Version <= seqNum)
                        {
                            var sv = sdata.Delta[stateId];
                            sv.Version    = seqNum;
                            sv.DataLength = stateLen;
                            if (sv.Recoverable != recoverable)
                            {
                                if (recoverable)
                                {
                                    Debug.Assert(sdata.UnrecoverableStatesCount > 0, "Unrecoverable states count >0");
                                    sdata.UnrecoverableStatesCount--;
                                }
                                else
                                {
                                    checked
                                    {
                                        sdata.UnrecoverableStatesCount++;
                                    }
                                }

                                sv.Recoverable = recoverable;
                            }

                            buffer = sv.Data;
                            if (buffer.Length < stateLen)
                            {
                                buffer  = new byte[stateLen];
                                sv.Data = buffer;
                            }
                        }
                    }
                }

                if (buffer != null)
                {
                    reader.ReadByteArray(buffer, 0, stateLen);
                }
                else
                {
                    reader.GetBytes(stateLen);
                }

                length -= stateLenByte < 0xFF
                    ? 2 + stateLen
                    : 6 + stateLen;
            }
        }