예제 #1
0
		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);
			}
		}
예제 #2
0
		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());
			}
		}
예제 #3
0
		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());
			}
		}
예제 #4
0
		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);
			}
		}
예제 #5
0
		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));
			}
		}
예제 #6
0
		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());
			}
		}
예제 #7
0
		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)));
		}
예제 #8
0
		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)));
		}
예제 #9
0
		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));
		}
예제 #10
0
		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)));
		}
예제 #11
0
		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));
		}
예제 #12
0
		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));
		}
예제 #13
0
		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);
		}
예제 #14
0
		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) + "'");
			}
		}
예제 #15
0
		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;
		}
예제 #16
0
		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);
			}
		}
예제 #17
0
		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;
		}
예제 #18
0
		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);
				}
			}
		}
예제 #19
0
		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;
			}
		}
예제 #20
0
		public void SkipValue(MySqlStream stream) {
			long num = stream.ReadFieldLength();
			stream.SkipBytes((int)num);
		}
예제 #21
0
		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);
			}
		}
예제 #22
0
		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);
		}
예제 #23
0
		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);
		}
예제 #24
0
		void IMySqlValue.SkipValue(MySqlStream stream) {
			long num = stream.ReadByte();
			stream.SkipBytes((int)num);
		}
예제 #25
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);
				}
			}
		}
예제 #26
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 + "'");
		}
예제 #27
0
		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;
				}
			}
		}
예제 #28
0
		void IMySqlValue.SkipValue(MySqlStream stream) {
			stream.ReadByte();
		}
예제 #29
0
		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;
		}
예제 #30
0
		void IMySqlValue.SkipValue(MySqlStream stream) {
			stream.SkipBytes(2);
		}
예제 #31
0
        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);
                }
            }
        }