void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object val, int length) { if (!(val is TimeSpan)) { throw new MyCatException("Only TimeSpan objects can be serialized by MyCatTimeSpan"); } 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); } }
void IMyCatValue.WriteValue(MyCatPacket 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()); } }
void IMyCatValue.WriteValue(MyCatPacket 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()); } }
void IMyCatValue.WriteValue(MyCatPacket 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()); } }
void IMyCatValue.WriteValue(MyCatPacket 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()); } }
public void WriteValue(MyCatPacket 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()); } }
internal void Authenticate(bool reset) { CheckConstraints(); MyCatPacket packet = driver.Packet; // send auth response packet.WriteString(GetUsername()); // now write the password WritePassword(packet); if ((Flags & ClientFlags.CONNECT_WITH_DB) != 0 || reset) { if (!String.IsNullOrEmpty(Settings.Database)) { packet.WriteString(Settings.Database); } } if (reset) { packet.WriteInteger(8, 2); } if ((Flags & ClientFlags.PLUGIN_AUTH) != 0) { packet.WriteString(PluginName); } driver.SetConnectAttrs(); driver.SendPacket(packet); //read server response packet = ReadPacket(); byte[] b = packet.Buffer; if (b[0] == 0xfe) { if (packet.IsLastPacket) { driver.Close(true); throw new MyCatException(Resources.OldPasswordsNotSupported); } else { HandleAuthChange(packet); } } driver.ReadOk(false); AuthenticationSuccessful(); }
void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object value, int length) { MyCatDateTime dtValue; string valueAsString = value as string; if (value is DateTime) { dtValue = new MyCatDateTime(type, (DateTime)value); } else if (valueAsString != null) { dtValue = MyCatDateTime.Parse(valueAsString); } else if (value is MyCatDateTime) { dtValue = (MyCatDateTime)value; } else { throw new MyCatException("Unable to serialize date/time value."); } if (!binary) { SerializeText(packet, dtValue); return; } if (dtValue.Microsecond > 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 == MyCatDbType.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.Microsecond > 0) { long val = dtValue.Microsecond; for (int x = 0; x < 4; x++) { packet.WriteByte((byte)(val & 0xff)); val >>= 8; } } }