Пример #1
0
        private TdsToken CreateEnvChange(TokenDescriptor tokenDesc, TdsResponseStream stream, Encoding encoder, FormatToken lastFormat)
        {
            int len  = stream.ReadShort();
            int read = 0;

            var changes = new List <EnvChangeToken.Change>();

            while (read < len)
            {
                var change = new EnvChangeToken.Change();
                change.Type = (EnvChangeToken.EnvType)stream.Read();
                int newValLen = stream.Read();
                change.NewValue = stream.ReadString(newValLen);
                int oldValLen = stream.Read();
                change.OldValue = stream.ReadString(oldValLen);
                read           += 3 + newValLen + oldValLen;

                changes.Add(change);
            }

            return(new EnvChangeToken(tokenDesc.TokenType)
            {
                Changes = changes
            });
        }
Пример #2
0
        public static void ReadFormat(FormatToken.Format f, TdsResponseStream stream)
        {
            var t = _types[f.Type];

            if (t.FormatFormat == FormatFormat.LenOneByte || t.FormatFormat == FormatFormat.Decimal)
            {
                f.Len = stream.Read();
            }

            if (t.FormatFormat == FormatFormat.LenFourBytes || t.FormatFormat == FormatFormat.Image)
            {
                f.Len = stream.ReadInt();
            }

            if (t.FormatFormat == FormatFormat.Image)
            {
                int nameLen = stream.ReadShort();
                f.ObjectName = stream.ReadString(nameLen);
            }

            if (t.FormatFormat == FormatFormat.Decimal)
            {
                f.Pecision = stream.Read();
                f.Scale    = stream.Read();
            }

            int localLen = stream.Read();

            f.LocaleInfo = stream.ReadString(localLen);

            // todo: blob
        }
Пример #3
0
        private TdsToken CreateTextMessage(TokenDescriptor tokenDesc, TdsResponseStream stream, Encoding encoder, FormatToken lastFormat)
        {
            int len       = stream.ReadShort();
            int msgNumber = stream.ReadInt();
            int state     = stream.Read();
            int severity  = stream.Read();

            int sqlStatusLen = stream.Read();
            var sqlStatus    = stream.ReadBytes(sqlStatusLen);

            int status    = stream.Read();
            int tranState = stream.ReadShort(); // discarded

            int msgLen = stream.ReadShort();
            var msg    = stream.ReadString(msgLen);

            int srvNameLen = stream.Read();
            var serverName = stream.ReadString(srvNameLen);

            int procNameLen = stream.Read();
            var procName    = stream.ReadString(procNameLen);

            int lineNumber = stream.ReadShort();

            return(new TextMessageToken(tokenDesc.TokenType)
            {
                MessageNumber = msgNumber,
                State = state,
                Severity = severity,
                ParamsFollows = status == 1,
                Message = msg,
                ServerName = serverName,
                ProcName = procName,
                LineNumber = lineNumber,
            });
        }
Пример #4
0
        private TdsToken CreateLoginAck(TokenDescriptor tokenDesc, TdsResponseStream stream, Encoding encoder, FormatToken lastFormat)
        {
            int len         = stream.ReadShort();
            int status      = stream.Read();
            var version     = stream.ReadBytes(4);
            int nameLen     = stream.Read();
            var name        = stream.ReadString(nameLen);
            var progVersion = stream.ReadBytes(4);

            return(new LoginAckToken(tokenDesc.TokenType)
            {
                Succeed = status == 5,
                Fail = status == 6,
                Negotiate = status == 7,
                TdsVersion = $"{version[0]}.{version[1]}.{version[2]}.{version[3]}",
                ServerProgram = name,
                ServerVersion = $"{progVersion[0]}.{progVersion[1]}.{progVersion[2]}.{progVersion[3]}",
            });
        }
Пример #5
0
        private TdsToken CreateControl(TokenDescriptor tokenDesc, TdsResponseStream stream, Encoding encoder, FormatToken lastFormat)
        {
            int len  = stream.ReadShort();
            int read = 0;

            var formats = new List <string>();

            while (read < len)
            {
                int formatLen = stream.Read();
                var format    = stream.ReadString(formatLen);
                read += 1 + formatLen;

                formats.Add(format);
            }

            return(new ControlToken(tokenDesc.TokenType)
            {
                Formats = formats
            });
        }
Пример #6
0
        private TdsToken CreateFormat(TokenDescriptor tokenDesc, TdsResponseStream stream, Encoding encoder, FormatToken lastFormat)
        {
            int len;

            if (tokenDesc.Len == TokenLength.FourByteLen)
            {
                len = stream.ReadInt();
            }
            else
            {
                len = stream.ReadShort();
            }

            int numFormats = stream.ReadShort();

            var formats = new List <FormatToken.Format>();

            for (int i = 0; i < numFormats; i++)
            {
                var f = new FormatToken.Format
                {
                    Params = tokenDesc.TokenType == TokenType.TDS_PARAMFMT || tokenDesc.TokenType == TokenType.TDS_PARAMFMT2,
                };

                int nameLen = stream.Read();
                f.Name = stream.ReadString(nameLen);

                if (tokenDesc.TokenType == TokenType.TDS_ROWFMT2)
                {
                    int catalogNameLen = stream.Read();
                    f.CatalogName = stream.ReadString(catalogNameLen);
                    int schemaNameLen = stream.Read();
                    f.SchemaName = stream.ReadString(schemaNameLen);
                    int tableNameLen = stream.Read();
                    f.TableName = stream.ReadString(tableNameLen);
                    int columnNameLen = stream.Read();
                    f.ColumnName = stream.ReadString(columnNameLen);
                }

                if (tokenDesc.Len == TokenLength.FourByteLen)
                {
                    f.Status = stream.ReadInt();
                }
                else
                {
                    f.Status = stream.Read();
                }

                f.UserType = (UserDataType)stream.ReadInt();
                f.Type     = (TdsType)stream.Read();

                TypeReader.ReadFormat(f, stream);

                formats.Add(f);
            }

            return(new FormatToken(tokenDesc.TokenType)
            {
                Formats = formats,
            });
        }