Exemple #1
0
        public ResultSetPacket Query(string queryString)
        {
            _channel.SequenceByte = 0;

            QueryCommandPacket cmd = new QueryCommandPacket();

            cmd.QueryString = queryString;
            _channel.SendPacket(cmd.ToBytes());

            var result = _channel.ReadPacket();

            ResultSetHeaderPacket rsHeader = new ResultSetHeaderPacket();

            rsHeader.FromBytes(result);

            var fields = new List <FieldPacket>();

            for (int i = 0; i < rsHeader.ColumnCount; i++)
            {
                var fp = new FieldPacket();
                fp.FromBytes(_channel.ReadPacket());
                fields.Add(fp);
            }

            ReadEofPacket();

            var rowData = new List <RowDataPacket>();

            while (true)
            {
                var body = _channel.ReadPacket();
                if (body.Buffer[0] == 254)
                {
                    break;
                }
                var rowDataPacket = new RowDataPacket();
                rowDataPacket.FromBytes(body);
                rowData.Add(rowDataPacket);
            }

            var resultSet = new ResultSetPacket();

            resultSet.FieldDescriptors.AddRange(fields);
            foreach (var r in rowData)
            {
                resultSet.FieldValues.AddRange(r.Columns);
            }
            resultSet.SourceAddress = Address;

            return(resultSet);
        }
Exemple #2
0
        public OKPacket Update(string updateString)
        {
            _channel.SequenceByte = 0;

            var cmd = new QueryCommandPacket();

            cmd.QueryString = updateString;
            _channel.SendPacket(cmd.ToBytes());

            _logger.LogDebug("Read update result.");

            var result = _channel.ReadPacket();

            var okPacket = new OKPacket();

            okPacket.FromBytes(result);

            return(okPacket);
        }