Ejemplo n.º 1
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());
			}
		}
Ejemplo n.º 2
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));
			}
		}
Ejemplo n.º 3
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());
			}
		}
Ejemplo n.º 4
0
 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());
     }
 }
Ejemplo n.º 5
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);
			}
		}