public override void Execute() { if (!this.IsPrepared) { base.Execute(); } else { MySqlStream stream = new MySqlStream(base.Driver.Encoding); BitArray array = new BitArray(base.Parameters.Count); if (this.paramList != null) { for (int i = 0; i < this.paramList.Length; i++) { MySqlParameter parameter = base.Parameters[this.paramList[i].ColumnName]; if ((parameter.Value == DBNull.Value) || (parameter.Value == null)) { array[i] = true; } } } byte[] buffer = new byte[(base.Parameters.Count + 7) / 8]; if (buffer.Length > 0) { array.CopyTo(buffer, 0); } stream.WriteInteger((long) this.statementId, 4); stream.WriteByte(0); stream.WriteInteger(1L, 4); stream.Write(buffer); stream.WriteByte(1); if (this.paramList != null) { foreach (MySqlField field in this.paramList) { MySqlParameter parameter2 = base.Parameters[field.ColumnName]; stream.WriteInteger((long) parameter2.GetPSType(), 2); } foreach (MySqlField field2 in this.paramList) { int index = base.Parameters.IndexOf(field2.ColumnName); if (index == -1) { throw new MySqlException("Parameter '" + field2.ColumnName + "' is not defined."); } MySqlParameter parameter3 = base.Parameters[index]; if ((parameter3.Value != DBNull.Value) && (parameter3.Value != null)) { stream.Encoding = field2.Encoding; parameter3.Serialize(stream, true); } } } this.executionCount++; base.Driver.ExecuteStatement(stream.InternalBuffer.ToArray()); } }
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()); } }
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length) { float num = Convert.ToSingle(val); if (binary) { stream.Write(BitConverter.GetBytes(num)); } else { stream.WriteStringNoNull(num.ToString("R", CultureInfo.InvariantCulture)); } }
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object v, int length) { uint num = Convert.ToUInt32(v); 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 = 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) + "'"); } }
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); } }
void IMySqlValue.SkipValue(MySqlStream stream) { int len = stream.ReadByte(); stream.SkipBytes(len); }
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; } }
private void SendFileToServer(string filename) { byte[] buffer = new byte[0x2004]; FileStream stream = null; long num = 0L; try { int num2; stream = new FileStream(filename, FileMode.Open); for (num = stream.Length; num > 0L; num -= num2) { num2 = stream.Read(buffer, 4, (num > 0x2000L) ? ((int) 0x2000L) : ((int) num)); this.stream.SendEntirePacketDirectly(buffer, num2); } this.stream.SendEntirePacketDirectly(buffer, 0); } catch (Exception exception) { throw new MySqlException("Error during LOAD DATA LOCAL INFILE", exception); } finally { stream.Close(); } }
public override void Open() { base.Open(); try { if (base.Settings.ConnectionProtocol == MySqlConnectionProtocol.SharedMemory) { SharedMemoryStream stream = new SharedMemoryStream(base.Settings.SharedMemoryName); stream.Open(base.Settings.ConnectionTimeout); this.baseStream = stream; } else { string pipeName = base.Settings.PipeName; if (base.Settings.ConnectionProtocol != MySqlConnectionProtocol.NamedPipe) { pipeName = null; } this.baseStream = new StreamCreator(base.Settings.Server, base.Settings.Port, pipeName).GetStream(base.Settings.ConnectionTimeout); } if (this.baseStream == null) { throw new Exception(); } } catch (Exception exception) { throw new MySqlException(Resources.UnableToConnectToHost, 0x412, exception); } if (this.baseStream == null) { throw new MySqlException("Unable to connect to any of the specified MySQL hosts"); } int num = 0xfd02ff; this.stream = new MySqlStream(this.baseStream, base.encoding, false); this.stream.OpenPacket(); this.protocol = this.stream.ReadByte(); string versionString = this.stream.ReadString(); base.version = DBVersion.Parse(versionString); base.threadId = this.stream.ReadInteger(4); this.encryptionSeed = this.stream.ReadString(); if (this.version.isAtLeast(4, 0, 8)) { num = 0xffffff; } base.serverCaps = 0; if (this.stream.HasMoreData) { base.serverCaps = (ClientFlags) this.stream.ReadInteger(2); } if (this.version.isAtLeast(4, 1, 1)) { base.serverCharSetIndex = this.stream.ReadInteger(1); base.serverStatus = (ServerStatusFlags) this.stream.ReadInteger(2); this.stream.SkipBytes(13); string str3 = this.stream.ReadString(); this.encryptionSeed = this.encryptionSeed + str3; } this.SetConnectionFlags(); this.stream.StartOutput(0L, false); this.stream.WriteInteger((long) this.connectionFlags, this.version.isAtLeast(4, 1, 0) ? 4 : 2); if (base.connectionString.UseSSL && ((base.serverCaps & ClientFlags.SSL) != 0)) { this.stream.Flush(); this.StartSSL(); this.stream.StartOutput(0L, false); this.stream.WriteInteger((long) this.connectionFlags, this.version.isAtLeast(4, 1, 0) ? 4 : 2); } this.stream.WriteInteger((long) num, this.version.isAtLeast(4, 1, 0) ? 4 : 3); if (this.version.isAtLeast(4, 1, 1)) { this.stream.WriteByte(8); this.stream.Write(new byte[0x17]); } this.Authenticate(); if ((this.connectionFlags & ClientFlags.COMPRESS) != 0) { this.stream = new MySqlStream(this.baseStream, base.encoding, true); } this.stream.Version = base.version; this.stream.MaxBlockSize = num; base.isOpen = true; }
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); }
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.SkipBytes(4); }
void IMySqlValue.SkipValue(MySqlStream stream) { stream.ReadByte(); }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlUInt32(((IMySqlValue) this).MySqlDbType, true); } if (length == -1L) { return new MySqlUInt32(((IMySqlValue) this).MySqlDbType, (uint) stream.ReadInteger(4)); } return new MySqlUInt32(((IMySqlValue) this).MySqlDbType, uint.Parse(stream.ReadString(length), NumberStyles.Any, CultureInfo.InvariantCulture)); }
private bool SerializeParameter(MySqlParameterCollection parameters, MySqlStream stream, string parmName) { MySqlParameter parameterFlexible = parameters.GetParameterFlexible(parmName, false); if (parameterFlexible == null) { if (!parmName.StartsWith("@") || !this.ShouldIgnoreMissingParameter(parmName)) { throw new MySqlException(string.Format(Resources.ParameterMustBeDefined, parmName)); } return false; } parameterFlexible.Serialize(stream, false); return true; }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlSingle(true); } if (length == -1L) { byte[] buffer = new byte[4]; stream.Read(buffer, 0, 4); return new MySqlSingle(BitConverter.ToSingle(buffer, 0)); } return new MySqlSingle(float.Parse(stream.ReadString(length), CultureInfo.InvariantCulture)); }
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); } } }
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) { 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) { long num = stream.ReadFieldLength(); stream.SkipBytes((int) num); }
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; }
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); }
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))); }
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); } }
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal) { if (nullVal) { return new MySqlByte(true); } if (length == -1L) { return new MySqlByte((sbyte) stream.ReadByte()); } string s = stream.ReadString(length); MySqlByte num = new MySqlByte(sbyte.Parse(s, NumberStyles.Any, CultureInfo.InvariantCulture)); num.TreatAsBoolean = this.TreatAsBoolean; return num; }
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 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 = Convert.ToDecimal(val).ToString(CultureInfo.InvariantCulture); if (binary) { stream.WriteLenString(s); } else { stream.WriteStringNoNull(s); } }
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)); }
public override void Open() { base.Open(); try { if (base.Settings.ConnectionProtocol == MySqlConnectionProtocol.SharedMemory) { SharedMemoryStream stream = new SharedMemoryStream(base.Settings.SharedMemoryName); stream.Open(base.Settings.ConnectionTimeout); this.baseStream = stream; } else { string pipeName = base.Settings.PipeName; if (base.Settings.ConnectionProtocol != MySqlConnectionProtocol.NamedPipe) { pipeName = null; } this.baseStream = new StreamCreator(base.Settings.Server, base.Settings.Port, pipeName).GetStream(base.Settings.ConnectionTimeout); } if (this.baseStream == null) { throw new Exception(); } } catch (Exception exception) { throw new MySqlException(Resources.UnableToConnectToHost, 0x412, exception); } if (this.baseStream == null) { throw new MySqlException("Unable to connect to any of the specified MySQL hosts"); } int num = 0xfd02ff; this.stream = new MySqlStream(this.baseStream, base.encoding, false); this.stream.OpenPacket(); this.protocol = this.stream.ReadByte(); string versionString = this.stream.ReadString(); base.version = DBVersion.Parse(versionString); base.threadId = this.stream.ReadInteger(4); this.encryptionSeed = this.stream.ReadString(); if (this.version.isAtLeast(4, 0, 8)) { num = 0xffffff; } base.serverCaps = 0; if (this.stream.HasMoreData) { base.serverCaps = (ClientFlags)this.stream.ReadInteger(2); } if (this.version.isAtLeast(4, 1, 1)) { base.serverCharSetIndex = this.stream.ReadInteger(1); base.serverStatus = (ServerStatusFlags)this.stream.ReadInteger(2); this.stream.SkipBytes(13); string str3 = this.stream.ReadString(); this.encryptionSeed = this.encryptionSeed + str3; } this.SetConnectionFlags(); this.stream.StartOutput(0L, false); this.stream.WriteInteger((long)this.connectionFlags, this.version.isAtLeast(4, 1, 0) ? 4 : 2); if (base.connectionString.UseSSL && ((base.serverCaps & ClientFlags.SSL) != 0)) { this.stream.Flush(); this.StartSSL(); this.stream.StartOutput(0L, false); this.stream.WriteInteger((long)this.connectionFlags, this.version.isAtLeast(4, 1, 0) ? 4 : 2); } this.stream.WriteInteger((long)num, this.version.isAtLeast(4, 1, 0) ? 4 : 3); if (this.version.isAtLeast(4, 1, 1)) { this.stream.WriteByte(8); this.stream.Write(new byte[0x17]); } this.Authenticate(); if ((this.connectionFlags & ClientFlags.COMPRESS) != 0) { this.stream = new MySqlStream(this.baseStream, base.encoding, true); } this.stream.Version = base.version; this.stream.MaxBlockSize = num; base.isOpen = true; }