コード例 #1
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());
 }
コード例 #2
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());
 }
コード例 #3
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, is24Bit ? 3 : 4);
   else
     packet.WriteStringNoNull(v.ToString());
 }
コード例 #4
0
 void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
 {
   int v = (val is UInt16) ? (UInt16)val : Convert.ToUInt16(val);
   if (binary)
     packet.WriteInteger((long)v, 2);
   else
     packet.WriteStringNoNull(v.ToString());
 }
コード例 #5
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));
 }
コード例 #6
0
 void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
 {
   byte v = (val is byte) ? (byte)val : Convert.ToByte(val);
   if (binary)
     packet.WriteByte(v);
   else
     packet.WriteStringNoNull(v.ToString());
 }
コード例 #7
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());
 }
コード例 #8
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) + "'");
        }
コード例 #9
0
    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 = value.Microsecond > 0 ? String.Format("{0} {1:00}:{2:00}:{3:00}.{4:000000}", val,
          value.Hour, value.Minute, value.Second, value.Microsecond) : String.Format("{0} {1:00}:{2:00}:{3:00} ", val,
          value.Hour, value.Minute, value.Second);
      }

      packet.WriteStringNoNull("'" + val + "'");
    }
コード例 #10
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)
      {
        if (ts.Milliseconds > 0)
          packet.WriteByte(12);
        else
          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);
        if (ts.Milliseconds > 0)
        {
          long mval = ts.Milliseconds*1000;
          packet.WriteInteger(mval, 4);          
        }
      }
      else
      {
        String s = String.Format("'{0}{1} {2:00}:{3:00}:{4:00}.{5:0000000}'",
            negative ? "-" : "", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Ticks % 10000000);
			
        packet.WriteStringNoNull(s);
      }
    }
コード例 #11
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;
         }
         if (ValueObject.MySqlDbType == MySqlDbType.Geometry)
         {
             MySqlGeometry v = (MySqlGeometry)ValueObject;
             if (v.IsNull && Value != null)
             {
                 MySqlGeometry.TryParse(Value.ToString(), out v);
             }
             ValueObject = v;
         }
         ValueObject.WriteValue(packet, binary, paramValue, Size);
     }
 }
コード例 #12
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)'\'');
      }
    }
コード例 #13
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);
 }
コード例 #14
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(Resources.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")) + "'");
      }
    }
コード例 #15
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)'\'');
      }
    }
コード例 #16
0
    void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
    {
      byte[] buffToWrite = null;
     
      try
      {
        buffToWrite = ((MySqlGeometry)val)._valBinary;        
      }
      catch 
      {
        buffToWrite = val as Byte[];
      }

      if (buffToWrite == null)
      {
        MySqlGeometry v = new MySqlGeometry(0, 0);
        MySqlGeometry.TryParse(val.ToString(), out v);
        buffToWrite = v._valBinary;
      }

      byte[] result = new byte[GEOMETRY_LENGTH];
     
      for (int i = 0; i < buffToWrite.Length; i++)
      {
       if (buffToWrite.Length < GEOMETRY_LENGTH)
         result[i + 4] = buffToWrite[i];
       else
        result[i] = buffToWrite[i];
      }
      
        packet.WriteStringNoNull("_binary ");
        packet.WriteByte((byte)'\'');
        EscapeByteArray(result, GEOMETRY_LENGTH, packet);
        packet.WriteByte((byte)'\'');      
    }