void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length) { byte[] bytes = null; if (val is byte[]) { bytes = (byte[])val; } else if (val is char[]) { bytes = stream.Encoding.GetBytes(val as char[]); } else { string s = val.ToString(); if (length == 0) { length = s.Length; } else { s = s.Substring(0, length); } bytes = stream.Encoding.GetBytes(s); } if (length == 0) { length = bytes.Length; } if (bytes == null) { throw new MySqlException("Only byte arrays and strings can be serialized by MySqlBinary"); } if (binary) { stream.WriteLength((long)length); stream.Write(bytes, 0, length); } else { if (stream.Version.isAtLeast(4, 1, 0)) { stream.WriteStringNoNull("_binary "); } stream.WriteByte(0x27); this.EscapeByteArray(bytes, length, stream); stream.WriteByte(0x27); } }
public void WriteValue(MySqlStream stream, bool binary, object value, int length) { ulong num = Convert.ToUInt64(value); if (binary) { stream.Write(BitConverter.GetBytes(num)); } else { stream.WriteStringNoNull(num.ToString()); } }
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length) { int num = Convert.ToInt32(val); if (binary) { stream.Write(BitConverter.GetBytes(num)); } else { stream.WriteStringNoNull(num.ToString()); } }
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length) { string s = Convert.ToDecimal(val).ToString(CultureInfo.InvariantCulture); if (binary) { stream.WriteLenString(s); } else { stream.WriteStringNoNull(s); } }
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length) { double num = Convert.ToDouble(val); if (binary) { stream.Write(BitConverter.GetBytes(num)); } else { stream.WriteStringNoNull(num.ToString("R", CultureInfo.InvariantCulture)); } }
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length) { byte num = ((IConvertible)val).ToByte(null); if (binary) { stream.WriteByte(num); } else { stream.WriteStringNoNull(num.ToString()); } }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlInt16(true); } if (length == -1L) { return new MySqlInt16((short)stream.ReadInteger(2)); } return new MySqlInt16(short.Parse(stream.ReadString(length))); }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlUByte(true); } if (length == -1L) { return new MySqlUByte((byte)stream.ReadByte()); } return new MySqlUByte(byte.Parse(stream.ReadString(length))); }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlInt32(((IMySqlValue)this).MySqlDbType, true); } if (length == -1L) { return new MySqlInt32(((IMySqlValue)this).MySqlDbType, stream.ReadInteger(4)); } return new MySqlInt32(((IMySqlValue)this).MySqlDbType, int.Parse(stream.ReadString(length), CultureInfo.InvariantCulture)); }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlUInt64(true); } if (length == -1L) { return new MySqlUInt64(stream.ReadLong(8)); } return new MySqlUInt64(ulong.Parse(stream.ReadString(length))); }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlDecimal(true); } if (length == -1L) { return new MySqlDecimal(decimal.Parse(stream.ReadLenString(), CultureInfo.InvariantCulture)); } return new MySqlDecimal(decimal.Parse(stream.ReadString(length), CultureInfo.InvariantCulture)); }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlDouble(true); } if (length == -1L) { byte[] buffer = new byte[8]; stream.Read(buffer, 0, 8); return new MySqlDouble(BitConverter.ToDouble(buffer, 0)); } return new MySqlDouble(double.Parse(stream.ReadString(length), CultureInfo.InvariantCulture)); }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlString(this.type, true); } string val = string.Empty; if (length == -1L) { val = stream.ReadLenString(); } else { val = stream.ReadString(length); } return new MySqlString(this.type, val); }
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length) { string s = val.ToString(); if (length > 0) { length = Math.Min(length, s.Length); s = s.Substring(0, length); } if (binary) { stream.WriteLenString(s); } else { stream.WriteStringNoNull("'" + MySqlHelper.EscapeString(s) + "'"); } }
public IMySqlValue ReadValue(MySqlStream stream, long length, bool isNull) { this.isNull = isNull; if (!isNull) { if (this.buffer == null) { this.buffer = new byte[8]; } if (length == -1L) { length = stream.ReadFieldLength(); } Array.Clear(this.buffer, 0, this.buffer.Length); for (long i = length - 1L; i >= 0L; i -= 1L) { this.buffer[(int)((IntPtr)i)] = (byte)stream.ReadByte(); } this.mValue = BitConverter.ToUInt64(this.buffer, 0); } return this; }
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length) { if (!(val is TimeSpan)) { throw new MySqlException("Only TimeSpan objects can be serialized by MySqlTimeSpan"); } TimeSpan span = (TimeSpan)val; bool flag = span.TotalMilliseconds < 0.0; span = span.Duration(); if (binary) { stream.WriteByte(8); stream.WriteByte(flag ? ((byte)1) : ((byte)0)); stream.WriteInteger((long)span.Days, 4); stream.WriteByte((byte)span.Hours); stream.WriteByte((byte)span.Minutes); stream.WriteByte((byte)span.Seconds); } else { string v = string.Format("'{0}{1} {2:00}:{3:00}:{4:00}.{5}'", new object[] { flag ? "-" : "", span.Days, span.Hours, span.Minutes, span.Seconds, span.Milliseconds }); stream.WriteStringNoNull(v); } }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlTimeSpan(true); } if (length >= 0L) { string s = stream.ReadString(length); this.ParseMySql(s, stream.Version.isAtLeast(4, 1, 0)); return this; } long num = stream.ReadByte(); int num2 = 0; if (num > 0L) { num2 = stream.ReadByte(); } this.isNull = false; switch (num) { case 0L: this.isNull = true; break; case 5L: this.mValue = new TimeSpan(stream.ReadInteger(4), 0, 0, 0); break; case 8L: this.mValue = new TimeSpan(stream.ReadInteger(4), stream.ReadByte(), stream.ReadByte(), stream.ReadByte()); break; default: this.mValue = new TimeSpan(stream.ReadInteger(4), stream.ReadByte(), stream.ReadByte(), stream.ReadByte(), stream.ReadInteger(4) / 0xf4240); break; } if (num2 == 1) { this.mValue = this.mValue.Negate(); } return this; }
private void InternalBindParameters(string sql, MySqlParameterCollection parameters, MySqlStream stream) { ArrayList list = this.TokenizeSql(sql); if (stream == null) { stream = new MySqlStream(this.Driver.Encoding); stream.Version = this.Driver.Version; } string str = (string)list[list.Count - 1]; if (str != ";") { list.Add(";"); } foreach (string str2 in list) { if (str2.Trim().Length == 0) { continue; } if (str2 == ";") { this.buffers.Add(stream); stream = new MySqlStream(this.Driver.Encoding); continue; } if (((str2.Length < 2) || (((str2[0] != '@') || (str2[1] == '@')) && (str2[0] != '?'))) || !this.SerializeParameter(parameters, stream, str2)) { stream.WriteStringNoNull(str2); } } }
private void StartSSL() { RemoteCertificateValidationCallback userCertificateValidationCallback = new RemoteCertificateValidationCallback(NativeDriver.NoServerCheckValidation); SslStream baseStream = new SslStream(this.baseStream, true, userCertificateValidationCallback, null); try { X509CertificateCollection clientCertificates = new X509CertificateCollection(); baseStream.AuthenticateAsClient(string.Empty, clientCertificates, SslProtocols.Default, false); this.baseStream = baseStream; this.stream = new MySqlStream(baseStream, base.encoding, false); this.stream.SequenceByte = 2; } catch (Exception) { throw; } }
public void SkipValue(MySqlStream stream) { long num = stream.ReadFieldLength(); stream.SkipBytes((int)num); }
internal void Serialize(MySqlStream stream, bool binary) { IMySqlValue iMySqlValue = MySqlField.GetIMySqlValue(this.mySqlDbType); if (!binary && ((this.paramValue == null) || (this.paramValue == DBNull.Value))) { stream.WriteStringNoNull("NULL"); } else { iMySqlValue.WriteValue(stream, binary, this.paramValue, this.size); } }
protected override void Dispose(bool disposing) { if (disposing) { try { if (base.isOpen) { this.ExecuteCommand(DBCmd.QUIT, null, 0); } if (this.stream != null) { this.stream.Close(); } this.stream = null; } catch (Exception) { } } base.Dispose(disposing); }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlDateTime(this.type, true); } if (length >= 0L) { string s = stream.ReadString(length); return this.ParseMySql(s, stream.Version.isAtLeast(4, 1, 0)); } long num = stream.ReadByte(); int year = 0; int month = 0; int day = 0; int hour = 0; int minute = 0; int second = 0; if (num >= 4L) { year = stream.ReadInteger(2); month = stream.ReadByte(); day = stream.ReadByte(); } if (num > 4L) { hour = stream.ReadByte(); minute = stream.ReadByte(); second = stream.ReadByte(); } if (num > 7L) { stream.ReadInteger(4); } return new MySqlDateTime(this.type, year, month, day, hour, minute, second); }
void IMySqlValue.SkipValue(MySqlStream stream) { long num = stream.ReadByte(); stream.SkipBytes((int)num); }
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); } } }
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 + "'"); }
private void EscapeByteArray(byte[] bytes, int length, MySqlStream stream) { for (int i = 0; i < length; i++) { byte num2 = bytes[i]; switch (num2) { case 0: stream.WriteByte(0x5c); stream.WriteByte(0x30); break; case 0x5c: case 0x27: case 0x22: stream.WriteByte(0x5c); stream.WriteByte(num2); break; default: stream.WriteByte(num2); break; } } }
void IMySqlValue.SkipValue(MySqlStream stream) { stream.ReadByte(); }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { MySqlBinary binary; if (nullVal) { binary = new MySqlBinary(this.type, true); } else { if (length == -1L) { length = stream.ReadFieldLength(); } byte[] buffer = new byte[length]; stream.Read(buffer, 0, (int)length); binary = new MySqlBinary(this.type, buffer); } binary.IsGuid = this.IsGuid; return binary; }
void IMySqlValue.SkipValue(MySqlStream stream) { stream.SkipBytes(2); }
private void InternalBindParameters(string sql, MySqlParameterCollection parameters, MySqlStream stream) { ArrayList list = this.TokenizeSql(sql); if (stream == null) { stream = new MySqlStream(this.Driver.Encoding); stream.Version = this.Driver.Version; } string str = (string)list[list.Count - 1]; if (str != ";") { list.Add(";"); } foreach (string str2 in list) { if (str2.Trim().Length == 0) { continue; } if (str2 == ";") { this.buffers.Add(stream); stream = new MySqlStream(this.Driver.Encoding); continue; } if (((str2.Length < 2) || (((str2[0] != '@') || (str2[1] == '@')) && (str2[0] != '?'))) || !this.SerializeParameter(parameters, stream, str2)) { stream.WriteStringNoNull(str2); } } }