internal void Serialize(MySqlPacket packet, bool binary, MySqlConnectionStringBuilder settings)
 {
     if (!binary && (paramValue == null || paramValue == DBNull.Value))
     {
         packet.WriteStringNoNull("NULL");
     }
     else
     {
         if (ValueObject.MySqlDbType == MySqlDbType.Guid)
         {
             MySqlGuid g = (MySqlGuid)ValueObject;
             g.OldGuids  = settings.OldGuids;
             valueObject = g;
         }
         ValueObject.WriteValue(packet, binary, paramValue, size);
     }
 }
        private void SerializeText(MySqlPacket packet, MySqlDateTime value)
        {
            string val = String.Empty;

            val = String.Format("{0:0000}-{1:00}-{2:00}",
                value.Year, value.Month, value.Day);
            if (type != MySqlDbType.Date)
                val = String.Format("{0} {1:00}:{2:00}:{3:00}", val,
                    value.Hour, value.Minute, value.Second);
            packet.WriteStringNoNull("'" + val + "'");
        }
예제 #3
0
 void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
 {
     sbyte v = (val is sbyte) ? (sbyte)val : Convert.ToSByte(val);
     if (binary)
         packet.WriteByte((byte)v);
     else
         packet.WriteStringNoNull(v.ToString());
 }
예제 #4
0
 void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
 {
     long v = (val is Int64) ? (Int64)val : Convert.ToInt64(val);
     if (binary)
         packet.WriteInteger(v, 8);
     else
         packet.WriteStringNoNull(v.ToString());
 }
예제 #5
0
 public void WriteValue(MySqlPacket packet, bool binary, object value, int length)
 {
     ulong v = (value is UInt64) ? (UInt64)value : Convert.ToUInt64(value);
     if (binary)
         packet.WriteInteger((long)v, 8);
     else
         packet.WriteStringNoNull(v.ToString());
 }
예제 #6
0
        private void WriteOldGuid(MySqlPacket packet, Guid guid, bool binary)
        {
            byte[] bytes = guid.ToByteArray();

            if (binary)
            {
                packet.WriteLength(bytes.Length);
                packet.Write(bytes);
            }
            else
            {
                packet.WriteStringNoNull("_binary ");
                packet.WriteByte((byte)'\'');
                EscapeByteArray(bytes, bytes.Length, packet);
                packet.WriteByte((byte)'\'');
            }
        }
예제 #7
0
        void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
        {
            Guid guid = Guid.Empty;
            string valAsString = val as string;
            byte[] valAsByte = val as byte[];

            if (val is Guid)
                guid = (Guid)val;
            else
            {
                try
                {
                    if (valAsString != null)
                        guid = new Guid(valAsString);
                    else if (valAsByte != null)
                        guid = new Guid(valAsByte);
                }
                catch (Exception ex)
                {
                    throw new MySqlException(ResourceStrings.DataNotInSupportedFormat, ex);
                }
            }

            if (OldGuids)
                WriteOldGuid(packet, guid, binary);
            else
            {
                guid.ToString("D");

                if (binary)
                    packet.WriteLenString(guid.ToString("D"));
                else
                    packet.WriteStringNoNull("'" + MySqlHelper.EscapeString(guid.ToString("D")) + "'");
            }
        }
예제 #8
0
 void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
 {
     int v = (val is Int32) ? (int)val : Convert.ToInt32(val);
     if (binary)
         packet.WriteInteger((long)v, 2);
     else
         packet.WriteStringNoNull(v.ToString());
 }
예제 #9
0
 void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
 {
     double v = (val is double) ? (double)val : Convert.ToDouble(val);
     if (binary)
         packet.Write(BitConverter.GetBytes(v));
     else
         packet.WriteStringNoNull(v.ToString("R", CultureInfo.InvariantCulture));
 }
예제 #10
0
        void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
        {
            string v = val.ToString();
            if (length > 0)
            {
                length = Math.Min(length, v.Length);
                v = v.Substring(0, length);
            }

            if (binary)
                packet.WriteLenString(v);
            else
                packet.WriteStringNoNull("'" + MySqlHelper.EscapeString(v) + "'");
        }
예제 #11
0
 void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
 {
     decimal v = (val is decimal) ? (decimal)val : Convert.ToDecimal(val);
     string valStr = v.ToString(CultureInfo.InvariantCulture);
     if (binary)
         packet.WriteLenString(valStr);
     else
         packet.WriteStringNoNull(valStr);
 }
예제 #12
0
 void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object v, int length)
 {
     uint val = (v is uint) ? (uint)v : Convert.ToUInt32(v);
     if (binary)
         packet.WriteInteger((long)val, is24Bit ? 3 : 4);
     else
         packet.WriteStringNoNull(val.ToString());
 }
예제 #13
0
        void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
        {
            if (!(val is TimeSpan))
                throw new MySqlException("Only TimeSpan objects can be serialized by MySqlTimeSpan");

            TimeSpan ts = (TimeSpan)val;
            bool negative = ts.TotalMilliseconds < 0;
            ts = ts.Duration();

            if (binary)
            {
                packet.WriteByte(8);
                packet.WriteByte((byte)(negative ? 1 : 0));
                packet.WriteInteger(ts.Days, 4);
                packet.WriteByte((byte)ts.Hours);
                packet.WriteByte((byte)ts.Minutes);
                packet.WriteByte((byte)ts.Seconds);
            }
            else
            {
                String s = String.Format("'{0}{1} {2:00}:{3:00}:{4:00}.{5}'",
                    negative ? "-" : "", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);

                packet.WriteStringNoNull(s);
            }
        }
예제 #14
0
 internal void Serialize(MySqlPacket packet, bool binary, MySqlConnectionStringBuilder settings)
 {
     if (!binary && (paramValue == null || paramValue == DBNull.Value))
         packet.WriteStringNoNull("NULL");
     else
     {
         if (ValueObject.MySqlDbType == MySqlDbType.Guid)
         {
             MySqlGuid g = (MySqlGuid)ValueObject;
             g.OldGuids = settings.OldGuids;
             valueObject = g;
         }
         ValueObject.WriteValue(packet, binary, paramValue, size);
     }
 }
예제 #15
0
        void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
        {
            byte[] buffToWrite = (val as byte[]);
            if (buffToWrite == null)
            {
                char[] valAsChar = (val as Char[]);
                if (valAsChar != null)
                    buffToWrite = packet.Encoding.GetBytes(valAsChar);
                else
                {
                    string s = val.ToString();
                    if (length == 0)
                        length = s.Length;
                    else
                        s = s.Substring(0, length);
                    buffToWrite = packet.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)
            {
                packet.WriteLength(length);
                packet.Write(buffToWrite, 0, length);
            }
            else
            {
                packet.WriteStringNoNull("_binary ");
                packet.WriteByte((byte)'\'');
                EscapeByteArray(buffToWrite, length, packet);
                packet.WriteByte((byte)'\'');
            }
        }