Beispiel #1
0
 public MySqlDateTime(MySqlDateTime mdt)
 {
     this.year = mdt.Year;
     this.month = mdt.Month;
     this.day = mdt.Day;
     this.hour = mdt.Hour;
     this.minute = mdt.Minute;
     this.second = mdt.Second;
     this.millisecond = 0;
     this.type = MySqlDbType.DateTime;
     this.isNull = false;
 }
Beispiel #2
0
 internal static MySqlDateTime Parse(string s, DBVersion version)
 {
     MySqlDateTime time = new MySqlDateTime();
     return time.ParseMySql(s, version.isAtLeast(4, 1, 0));
 }
Beispiel #3
0
 internal static MySqlDateTime Parse(string s)
 {
     MySqlDateTime time = new MySqlDateTime();
     return time.ParseMySql(s, true);
 }
Beispiel #4
0
 void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object value, int length)
 {
     MySqlDateTime time;
     if (value is DateTime)
     {
         time = new MySqlDateTime(this.type, (DateTime) value);
     }
     else if (value is string)
     {
         time = new MySqlDateTime(this.type, DateTime.Parse((string) value, CultureInfo.CurrentCulture));
     }
     else
     {
         if (!(value is MySqlDateTime))
         {
             throw new MySqlException("Unable to serialize date/time value.");
         }
         time = (MySqlDateTime) value;
     }
     if (!binary)
     {
         this.SerializeText(stream, time);
     }
     else
     {
         if (this.type == MySqlDbType.Timestamp)
         {
             stream.WriteByte(11);
         }
         else
         {
             stream.WriteByte(7);
         }
         stream.WriteInteger((long) time.Year, 2);
         stream.WriteByte((byte) time.Month);
         stream.WriteByte((byte) time.Day);
         if (this.type == MySqlDbType.Date)
         {
             stream.WriteByte(0);
             stream.WriteByte(0);
             stream.WriteByte(0);
         }
         else
         {
             stream.WriteByte((byte) time.Hour);
             stream.WriteByte((byte) time.Minute);
             stream.WriteByte((byte) time.Second);
         }
         if (this.type == MySqlDbType.Timestamp)
         {
             stream.WriteInteger((long) time.Millisecond, 4);
         }
     }
 }
Beispiel #5
0
 private void SerializeText(MySqlStream stream, MySqlDateTime value)
 {
     string str = string.Empty;
     if ((this.type == MySqlDbType.Timestamp) && !stream.Version.isAtLeast(4, 1, 0))
     {
         str = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}", new object[] { value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second });
     }
     else
     {
         str = string.Format("{0:0000}-{1:00}-{2:00}", value.Year, value.Month, value.Day);
         if (this.type != MySqlDbType.Date)
         {
             str = string.Format("{0}  {1:00}:{2:00}:{3:00}", new object[] { str, value.Hour, value.Minute, value.Second });
         }
     }
     stream.WriteStringNoNull("'" + str + "'");
 }