Example #1
0
 /// <summary>
 /// Constructs a new <b>MySqlDateTime</b> object by copying the current value of the given object.
 /// </summary>
 /// <param name="mdt">The <b>MySqlDateTime</b> object to copy.</param>
 public MySqlDateTime(MySqlDateTime mdt)
 {
     year = mdt.Year;
       month = mdt.Month;
       day = mdt.Day;
       hour = mdt.Hour;
       minute = mdt.Minute;
       second = mdt.Second;
       millisecond = 0;
       type = MySqlDbType.DateTime;
       isNull = false;
       TimezoneOffset = 0;
 }
Example #2
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.Millisecond > 0 ? String.Format("{0} {1:00}:{2:00}:{3:00}.{4:000}", val,
              value.Hour, value.Minute, value.Second, value.Millisecond) : String.Format("{0} {1:00}:{2:00}:{3:00} ", val,
              value.Hour, value.Minute, value.Second);
              }

              packet.WriteStringNoNull("'" + val + "'");
        }
Example #3
0
 internal static MySqlDateTime Parse(string s)
 {
     MySqlDateTime dt = new MySqlDateTime();
       return dt.ParseMySql(s);
 }
Example #4
0
 internal static MySqlDateTime Parse(string s, Common.DBVersion version)
 {
     MySqlDateTime dt = new MySqlDateTime();
       return dt.ParseMySql(s);
 }
Example #5
0
        void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object value, int length)
        {
            MySqlDateTime dtValue;

              string valueAsString = value as string;

              if (value is DateTime)
            dtValue = new MySqlDateTime(type, (DateTime)value);
              else if (valueAsString != null)
            dtValue = MySqlDateTime.Parse(valueAsString);
              else if (value is MySqlDateTime)
            dtValue = (MySqlDateTime)value;
              else
            throw new MySqlException("Unable to serialize date/time value.");

              if (!binary)
              {
            SerializeText(packet, dtValue);
            return;
              }

              if (dtValue.Millisecond > 0)
            packet.WriteByte(11);
              else
            packet.WriteByte(7);

              packet.WriteInteger(dtValue.Year, 2);
              packet.WriteByte((byte)dtValue.Month);
              packet.WriteByte((byte)dtValue.Day);
              if (type == MySqlDbType.Date)
              {
            packet.WriteByte(0);
            packet.WriteByte(0);
            packet.WriteByte(0);
              }
              else
              {
            packet.WriteByte((byte)dtValue.Hour);
            packet.WriteByte((byte)dtValue.Minute);
            packet.WriteByte((byte)dtValue.Second);
              }

              if (dtValue.Millisecond > 0)
              {
            long val = dtValue.Millisecond < 1000 ?  dtValue.Millisecond * 1000 : dtValue.Millisecond;
            for (int x = 0; x < 4; x++)
            {
              packet.WriteByte((byte)(val & 0xff));
              val >>= 8;
            }
              }
        }