Esempio n. 1
0
        void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
        {
            byte[] buffToWrite = null;

            if (val is System.Byte[])
            {
                buffToWrite = (byte[])val;
            }
            else if (val is Char[])
            {
                buffToWrite = stream.Encoding.GetBytes(val as char[]);
            }
            else
            {
                string s = val.ToString();
                if (length == 0)
                {
                    length = s.Length;
                }
                else
                {
                    s = s.Substring(0, length);
                }
                buffToWrite = stream.Encoding.GetBytes(s);
            }

            // we assume zero length means write all of the value
            if (length == 0)
            {
                length = buffToWrite.Length;
            }

            if (buffToWrite == null)
            {
                throw new MySqlException("Only byte arrays and strings can be serialized by MySqlBinary");
            }

            if (binary)
            {
                stream.WriteLength(length);
                stream.Write(buffToWrite, 0, length);
            }
            else
            {
                if (stream.Version.isAtLeast(4, 1, 0))
                {
                    stream.WriteStringNoNull("_binary ");
                }

                stream.WriteByte((byte)'\'');
                EscapeByteArray(buffToWrite, length, stream);
                stream.WriteByte((byte)'\'');
            }
        }
Esempio n. 2
0
        void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
        {
            long num = Convert.ToInt64(val);

            if (binary)
            {
                stream.Write(BitConverter.GetBytes(num));
            }
            else
            {
                stream.WriteStringNoNull(num.ToString());
            }
        }
Esempio n. 3
0
        void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
        {
            int v = Convert.ToUInt16(val);

            if (binary)
            {
                stream.Write(BitConverter.GetBytes(v));
            }
            else
            {
                stream.WriteStringNoNull(v.ToString());
            }
        }
Esempio n. 4
0
        public void WriteValue(MySqlStream stream, bool binary, object value, int length)
        {
            ulong v = Convert.ToUInt64(value);

            if (binary)
            {
                stream.Write(BitConverter.GetBytes(v));
            }
            else
            {
                stream.WriteStringNoNull(v.ToString());
            }
        }
Esempio n. 5
0
        void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object v, int length)
        {
            uint num = Convert.ToUInt32(v);

            if (binary)
            {
                stream.Write(BitConverter.GetBytes(num));
            }
            else
            {
                stream.WriteStringNoNull(num.ToString());
            }
        }
Esempio n. 6
0
        void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
        {
            double num = Convert.ToDouble(val);

            if (binary)
            {
                stream.Write(BitConverter.GetBytes(num));
            }
            else
            {
                stream.WriteStringNoNull(num.ToString("R", CultureInfo.InvariantCulture));
            }
        }
Esempio n. 7
0
        void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
        {
            sbyte v = ((IConvertible)val).ToSByte(null);

            if (binary)
            {
                stream.Write(BitConverter.GetBytes(v));
            }
            else
            {
                stream.WriteStringNoNull(v.ToString());
            }
        }
Esempio n. 8
0
        void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
        {
            Single v = Convert.ToSingle(val);

            if (binary)
            {
                stream.Write(BitConverter.GetBytes(v));
            }
            else
            {
                stream.WriteStringNoNull(v.ToString(
                                             CultureInfo.InvariantCulture));
            }
        }
Esempio n. 9
0
 void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 {
     byte[] bytes = null;
     if (val is byte[])
     {
         bytes = (byte[])val;
     }
     else if (val is char[])
     {
         bytes = stream.Encoding.GetBytes(val as char[]);
     }
     else
     {
         string s = val.ToString();
         if (length == 0)
         {
             length = s.Length;
         }
         else
         {
             s = s.Substring(0, length);
         }
         bytes = stream.Encoding.GetBytes(s);
     }
     if (length == 0)
     {
         length = bytes.Length;
     }
     if (bytes == null)
     {
         throw new MySqlException("Only byte arrays and strings can be serialized by MySqlBinary");
     }
     if (binary)
     {
         stream.WriteLength((long)length);
         stream.Write(bytes, 0, length);
     }
     else
     {
         if (stream.Version.isAtLeast(4, 1, 0))
         {
             stream.WriteStringNoNull("_binary ");
         }
         stream.WriteByte(0x27);
         this.EscapeByteArray(bytes, length, stream);
         stream.WriteByte(0x27);
     }
 }