IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
        {
            MyCatGuid g = new MyCatGuid();

            g.isNull   = true;
            g.OldGuids = OldGuids;
            if (!nullVal)
            {
                if (OldGuids)
                {
                    return(ReadOldGuid(packet, length));
                }
                string s = String.Empty;
                if (length == -1)
                {
                    s = packet.ReadLenString();
                }
                else
                {
                    s = packet.ReadString(length);
                }
                g.mValue = new Guid(s);
                g.isNull = false;
            }
            return(g);
        }
Exemple #2
0
    IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
    {
      if (nullVal)
        return new MyCatDecimal(true);

      string s = String.Empty;
      if (length == -1)
        s = packet.ReadLenString();
      else
        s = packet.ReadString(length);
      return new MyCatDecimal(s);
    }
        IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MyCatTimeSpan(true));
            }

            if (length >= 0)
            {
                string value = packet.ReadString(length);
                ParseMyCat(value);
                return(this);
            }

            long bufLength = packet.ReadByte();
            int  negate    = 0;

            if (bufLength > 0)
            {
                negate = packet.ReadByte();
            }

            isNull = false;
            if (bufLength == 0)
            {
                isNull = true;
            }
            else if (bufLength == 5)
            {
                mValue = new TimeSpan(packet.ReadInteger(4), 0, 0, 0);
            }
            else if (bufLength == 8)
            {
                mValue = new TimeSpan(packet.ReadInteger(4),
                                      packet.ReadByte(), packet.ReadByte(), packet.ReadByte());
            }
            else
            {
                mValue = new TimeSpan(packet.ReadInteger(4),
                                      packet.ReadByte(), packet.ReadByte(), packet.ReadByte(),
                                      packet.ReadInteger(4) / 1000000);
            }

            if (negate == 1)
            {
                mValue = mValue.Negate();
            }
            return(this);
        }
Exemple #4
0
        private void HandleAuthChange(MyCatPacket packet)
        {
            byte b = packet.ReadByte();

            Debug.Assert(b == 0xfe);

            string method = packet.ReadString();

            byte[] authData = new byte[packet.Length - packet.Position];
            Array.Copy(packet.Buffer, packet.Position, authData, 0, authData.Length);

            MyCatAuthenticationPlugin plugin = MyCatAuthenticationPlugin.GetPlugin(method, driver, authData);

            plugin.AuthenticationChange();
        }
Exemple #5
0
        IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MyCatSingle(true));
            }

            if (length == -1)
            {
                byte[] b = new byte[4];
                packet.Read(b, 0, 4);
                return(new MyCatSingle(BitConverter.ToSingle(b, 0)));
            }
            return(new MyCatSingle(Single.Parse(packet.ReadString(length),
                                                CultureInfo.InvariantCulture)));
        }
Exemple #6
0
        IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MyCatInt64(true));
            }

            if (length == -1)
            {
                return(new MyCatInt64((long)packet.ReadULong(8)));
            }
            else
            {
                return(new MyCatInt64(Int64.Parse(packet.ReadString(length))));
            }
        }
        IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MyCatUInt16(true));
            }

            if (length == -1)
            {
                return(new MyCatUInt16((ushort)packet.ReadInteger(2)));
            }
            else
            {
                return(new MyCatUInt16(UInt16.Parse(packet.ReadString(length))));
            }
        }
Exemple #8
0
        IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MyCatUByte(true));
            }

            if (length == -1)
            {
                return(new MyCatUByte((byte)packet.ReadByte()));
            }
            else
            {
                return(new MyCatUByte(Byte.Parse(packet.ReadString(length))));
            }
        }
Exemple #9
0
        IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MyCatUInt32((this as IMyCatValue).MyCatDbType, true));
            }

            if (length == -1)
            {
                return(new MyCatUInt32((this as IMyCatValue).MyCatDbType,
                                       (uint)packet.ReadInteger(4)));
            }
            else
            {
                return(new MyCatUInt32((this as IMyCatValue).MyCatDbType,
                                       UInt32.Parse(packet.ReadString(length), NumberStyles.Any, CultureInfo.InvariantCulture)));
            }
        }
Exemple #10
0
        IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MyCatByte(true));
            }

            if (length == -1)
            {
                return(new MyCatByte((sbyte)packet.ReadByte()));
            }
            else
            {
                string    s = packet.ReadString(length);
                MyCatByte b = new MyCatByte(SByte.Parse(s, NumberStyles.Any, CultureInfo.InvariantCulture));
                b.TreatAsBoolean = TreatAsBoolean;
                return(b);
            }
        }
Exemple #11
0
        public IMyCatValue ReadValue(MyCatPacket packet, long length, bool isNull)
        {
            if (isNull)
            {
                return(new MyCatJson(true));
            }

            string s = String.Empty;

            if (length == -1)
            {
                s = packet.ReadLenString();
            }
            else
            {
                s = packet.ReadString(length);
            }
            MyCatJson str = new MyCatJson(s);

            return(str);
        }
Exemple #12
0
        IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MyCatString(type, true));
            }

            string s = String.Empty;

            if (length == -1)
            {
                s = packet.ReadLenString();
            }
            else
            {
                s = packet.ReadString(length);
            }
            MyCatString str = new MyCatString(type, s);

            return(str);
        }
        IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MyCatDateTime(type, true));
            }

            if (length >= 0)
            {
                string value = packet.ReadString(length);
                return(ParseMyCat(value));
            }

            long bufLength = packet.ReadByte();
            int  year = 0, month = 0, day = 0;
            int  hour = 0, minute = 0, second = 0, microsecond = 0;

            if (bufLength >= 4)
            {
                year  = packet.ReadInteger(2);
                month = packet.ReadByte();
                day   = packet.ReadByte();
            }

            if (bufLength > 4)
            {
                hour   = packet.ReadByte();
                minute = packet.ReadByte();
                second = packet.ReadByte();
            }

            if (bufLength > 7)
            {
                microsecond = packet.Read3ByteInt();
                packet.ReadByte();
            }

            return(new MyCatDateTime(type, year, month, day, hour, minute, second, microsecond));
        }
        public IMyCatValue ReadValue(MyCatPacket packet, long length, bool isNull)
        {
            this.isNull = isNull;
            if (isNull)
            {
                return(this);
            }

            if (length == -1)
            {
                length = packet.ReadFieldLength();
            }

            if (ReadAsString)
            {
                mValue = UInt64.Parse(packet.ReadString(length));
            }
            else
            {
                mValue = (UInt64)packet.ReadBitValue((int)length);
            }
            return(this);
        }
Exemple #15
0
        IMyCatValue IMyCatValue.ReadValue(MyCatPacket packet, long length,
                                          bool nullVal)
        {
            if (nullVal)
            {
                return(new MyCatDouble(true));
            }

            if (length == -1)
            {
                byte[] b = new byte[8];
                packet.Read(b, 0, 8);
                return(new MyCatDouble(BitConverter.ToDouble(b, 0)));
            }
            string s = packet.ReadString(length);
            double d;

            try
            {
                d = Double.Parse(s, CultureInfo.InvariantCulture);
            }
            catch (OverflowException)
            {
                // MySQL server < 5.5 can return values not compatible with
                // Double.Parse(), i.e out of range for double.

                if (s.StartsWith("-", StringComparison.Ordinal))
                {
                    d = double.MinValue;
                }
                else
                {
                    d = double.MaxValue;
                }
            }
            return(new MyCatDouble(d));
        }