Esempio n. 1
0
 public DrdaResultSet(
     DrdaStreamReader reader)
 {
     Locator    = reader.ReadUInt32();
     CursorName = reader.ReadVcmVcs();
     Rows       = reader.ReadUInt32();
 }
        public static Decimal ReadDecimal(
            this DrdaStreamReader reader,
            Int32 precision,
            Int32 scale)
        {
            var value = 0M;

            var bytes = precision / 2;

            for (var index = 0; index < bytes; ++index)
            {
                var nybbles = reader.ReadUInt8();

                var hiNybble  = (nybbles >> 4) & 0xF;
                var lowNybble = nybbles & 0xF;

                value = value * 10 + hiNybble;
                value = value * 10 + lowNybble;
            }

            var lastNybbles = reader.ReadUInt8();

            if (precision % 2 == 1)
            {
                var hiNybble = (lastNybbles >> 4) & 0xF;
                value = value * 10 + hiNybble;
            }

            if ((lastNybbles & 0x0F) == 0x0D)
            {
                value = Decimal.Negate(value);
            }

            return(value * Scales[scale]);
        }
Esempio n. 3
0
        public CommAreaGroupDescriptor(
            DrdaStreamReader reader)
        {
            if (reader.ReadUInt8() == 0xFF)
            {
                return;
            }

            SqlCode  = reader.ReadUInt32();
            SqlState = reader.ReadString(5);
            var sqlErrProc = reader.ReadString(8);

            if (reader.ReadUInt8() != 0xFF)
            {
                RowsFetched = reader.ReadUInt64();
                RowsUpdated = reader.ReadUInt32();

                var sqlErrs = reader.ReadBytes(12); // 3 * sizeof(UInt32)
                var sqlWarn = reader.ReadBytes(11); // 11 * sizeof(Byte)

                var rdbName = reader.ReadUInt16();

                SqlMessage = reader.ReadVcmVcs();
            }

            if (reader.ReadUInt8() != 0xFF)
            {
                // WORKWORK
            }
        }
Esempio n. 4
0
 public UInt16Parameter(
     DrdaStreamReader reader,
     CodePoint codePoint)
     : this(
         codePoint,
         reader.ReadUInt16())
 {
 }
        public static String ReadVarString(
            this DrdaStreamReader reader)
        {
            var size  = reader.ReadUInt16();
            var bytes = reader.ReadBytes(size);

            return(Encoding.UTF8.GetString(bytes));
        }
Esempio n. 6
0
 public ReaderCommand(
     DrdaStreamReader reader,
     UInt32 totalByteLength,
     CodePoint codePoint)
 {
     _totalByteLength = totalByteLength - BaseSize;
     CodePoint        = codePoint;
     Reader           = reader;
 }
        private static String ReadVarString(
            this DrdaStreamReader reader,
            Byte hiByte)
        {
            var size  = (hiByte << 8) | reader.ReadUInt8();
            var bytes = reader.ReadBytes((UInt32)size);

            return(Encoding.UTF8.GetString(bytes));
        }
Esempio n. 8
0
 public CompositeCommand(
     DrdaStreamReader reader,
     UInt32 sizeWithoutHeader,
     CodePoint codePoint)
     : this(
         codePoint,
         ReadParameters(reader, sizeWithoutHeader).ToArray())
 {
 }
Esempio n. 9
0
 public BytesParameter(
     DrdaStreamReader reader,
     UInt32 byteArraySize,
     CodePoint codePoint)
     : this(
         codePoint,
         reader.ReadBytes(
             byteArraySize - BaseSize))
 {
 }
Esempio n. 10
0
 private static IEnumerable <IDrdaMessage> ReadParameters(
     DrdaStreamReader reader,
     UInt32 size)
 {
     while (size > BaseSize)
     {
         var parameter = CodePointMapper.Deserialize(reader);
         size -= parameter.GetSize();
         yield return(parameter);
     }
 }
Esempio n. 11
0
        public ResponseMessage(
            DrdaStreamReader reader)
        {
            Size = reader.ReadUInt16();

            reader.ReadUInt8(); // DDMID
            Format = (MessageFormat)reader.ReadUInt8();

            RequestCorrelationId = reader.ReadUInt16();

            Command = (ICommand)CodePointMapper.Deserialize(reader);
        }
Esempio n. 12
0
        public void Process(
            QueryContext context)
        {
            using var stream = new MemoryStream(_messageBytes, false);

            var reader = new DrdaStreamReader(stream);

            while (stream.Position < stream.Length &&
                   ProcessSingleRow(reader, context))
            {
                TraceInformation("-------- Next row fetched...");
            }
            TraceWarning($"P: {stream.Position} / L: {stream.Length}");
        }
Esempio n. 13
0
        internal void Process(
            QueryContext context)
        {
            using var stream = new MemoryStream(_messageBytes, false);

            var reader = new DrdaStreamReader(stream);

            while (stream.Position < stream.Length)
            {
                var length = reader.ReadUInt8();
                var type   = reader.ReadUInt8();
                var id     = reader.ReadUInt8();

                // TODO: olegra - store full parsing tree here later

                if (id != 0xD0)
                {
                    reader.ReadBytes((UInt32)length - 3);
                    continue;
                }

                var triples = new Triple[length / 3 - 1];
                for (var index = 0; index < triples.Length; ++index)
                {
                    switch (type)
                    {
                    case 117:     // GDA
                    case 118:     // NGDA
                        triples[index] = new Triple(
                            reader.ReadUInt8(),
                            reader.ReadUInt16());
                        break;

                    case 113:     // RLO
                        // TODO: olegra - skip for now
                        reader.ReadUInt8();
                        reader.ReadUInt16();
                        break;
                    }
                }

                for (var index = 0; index < triples.Length; ++index)
                {
                    context.Columns[index].TripletType     = triples[index].Type;
                    context.Columns[index].TripletDataSize = triples[index].Size;
                }
            }
        }
        public static String ReadVcmVcs(
            this DrdaStreamReader reader)
        {
            var value = reader.ReadVarString();

            if (String.IsNullOrEmpty(value))
            {
                value = reader.ReadVarString();
            }
            else
            {
                reader.ReadUInt16();
            }

            return(value);
        }
        public static String ReadString(
            this DrdaStreamReader reader,
            Int32 maxLength)
        {
            var buffer = new StringBuilder(maxLength);

            do
            {
                var character = (Char)reader.ReadUInt8();
                if (character == 0x00)
                {
                    break;
                }

                buffer.Append(character);
            } while (--maxLength != 0);

            return(buffer.ToString());
        }
Esempio n. 16
0
        private Boolean ProcessSingleRow(
            DrdaStreamReader reader,
            QueryContext context)
        {
            var groupDescriptor = new CommAreaGroupDescriptor(reader);

            reader.ReadUInt8(); // Parent nullable triplet

            if (groupDescriptor.SqlCode == 100 &&
                String.Equals(groupDescriptor.SqlState, "02000"))
            {
                context.HasMoreData = false;
                return(false);
            }

            context.Rows.Enqueue(context.Columns
                                 .Select(reader.ReadColumnValue).ToList());

            return(true);
        }
Esempio n. 17
0
        public DrdaColumn(
            DrdaStreamReader reader)
        {
            Precision = reader.ReadUInt16();
            Scale     = reader.ReadUInt16();
            Length    = reader.ReadUInt64();
            Db2Type   = (Db2Type)reader.ReadUInt16();

            CcsId    = reader.ReadUInt16();
            ArrayExt = reader.ReadUInt8();
            Unnamed  = reader.ReadUInt16();

            Name    = reader.ReadVcmVcs();
            Label   = reader.ReadVcmVcs();
            Comment = reader.ReadVcmVcs();

            var hiByte = reader.ReadUInt8();

            if (hiByte != 0xFF)
            {
                TypeName  = reader.ReadVcmVcs(hiByte);
                ClassName = reader.ReadVcmVcs();
            }

            // ReSharper disable once RedundantAssignment
            reader.ReadUInt8();

            KeyMem        = reader.ReadUInt16();
            Updateable    = reader.ReadUInt16();
            Generated     = reader.ReadUInt16();
            ParameterMode = reader.ReadUInt16();

            RdbName  = reader.ReadVarString();
            CoreName = reader.ReadVcmVcs();
            BaseName = reader.ReadVcmVcs();
            Scheme   = reader.ReadVcmVcs();
            DxName   = reader.ReadVcmVcs();
        }
Esempio n. 18
0
        public static IDrdaMessage Deserialize(
            DrdaStreamReader reader)
        {
            var size      = (UInt32)reader.ReadUInt16();
            var codePoint = (CodePoint)reader.ReadUInt16();

            if (size == 0x8004)
            {
                // TODO: olegra - check how we can obtain real message length here
            }
            else if ((size & 0x8000) == 0x8000)
            {
                size = reader.ReadUInt32() + sizeof(UInt16) + sizeof(UInt16);
            }

            // TODO: olegra - find the better way for handling code points here

            switch (codePoint)
            {
            case PBSD:
            case EXSATRM:
            case ACCSECRM:
            case SECCHKRM:
            case ACCRDBRM:
            case CMDCHKRM:
            case SQLERRRM:
            case RDBUPDRM:
            case SYNTAXRM:
            case RSLSETRM:
            case OPNQRYRM:
            case ENDUOWRM:
                return(new CompositeCommand(reader, size, codePoint));

            // In fact they are composite but we don't need them right now
            case MGRLVLLS:
            case TYPDEFOVR:
            case PKGSNLST:
                return(new BytesParameter(reader, size, codePoint));    //-V3139

            case QRYDSC:
            case QRYDTA:
            case EXTDTA:
            case SQLCARD:
            case SQLDARD:
            case SQLCINRD:
            case SQLRSLRD:
                return(new ReaderCommand(reader, size, codePoint));

            case UOWDSP:
            case PBSD_ISO:
            case SYNERRCD:
            case SECCHKCD:
            case SQLCSRHLD:
            case QRYATTUPD:
                return(new UInt8Parameter(reader, codePoint));

            case SECMEC:
            case SRVCOD:
            case QRYPRCTYP:
                return(new UInt16Parameter(reader, codePoint));

            case QRYINSID:
                return(new UInt64Parameter(reader, codePoint));

            case PRDID:
            case RDBNAM:
            case EXTNAM:
            case SRVNAM:
            case SRVCLSNM:
            case SRVRLSLV:
            case TYPDEFNAM:
            case PBSD_SCHEMA:
                // TODO: olegra - create string parameter type?
                return(new BytesParameter(reader, size, codePoint));

            default:
                TraceWarning("Unknown code point value: 0x{0:X}", codePoint);
                return(new BytesParameter(reader, size, codePoint));
            }
        }
 public static Object ReadColumnValue(
     this DrdaStreamReader reader,
     DrdaColumn column) =>
 column.ReadColumnValue(reader);